<%perl>
my $note_img = $story->has_notes ? 'note_fill' : 'note';
my $toText = qq{
<a href="/workflow/profile/story/view_notes.html?id=} . $id .
 qq{"><img src="/media/images/$note_img.gif" border="0" alt="View Notes" /></a>
    <a href="/workflow/trail/story/}. $id . qq{"><img src="/media/images/} .
  $lang_key  . qq{/view_trail_teal.gif" border="0" alt="View Trail" /></a>
};

$m->comp("/widgets/wrappers/sharky/table_top.mc",
          caption => "Information",
          number  => ++$number,
          id      => 'storyinfo',
          toText => $toText
);
</%perl>
<dl class="viewmeta">
  <dt><%$lang->maketext('UUID')%>:</dt>
  <dd title="ID: <% $story->get_id %>"><% $story->get_uuid %></dd>
  <dt><%$lang->maketext('Story Type')%>:</dt>
  <dd><% $story->get_element_name %></dd>
  <dt><% $lang->maketext('Title') %>:</dt>
  <dd><% $story->get_name %></dd>
  <dt><% $lang->maketext('Slug') %>:</dt>
  <dd><% $story->get_slug || '&nbsp;' %></dd>
  <dt><% $lang->maketext('URI') %>:</dt>
% if (@ocs == 1) {
  <dd><% $m->comp(
      '/widgets/profile/preview_link.mc',
      doc => $story,
  )%></dd>
% } else {
% my $oc_opts = [
%     map { [ $_->get_id => $_->get_name ] }
%         $story->get_output_channels
% ];
  <dd><% $story->get_primary_uri %></dd>
  <dt><% $lang->maketext('Preview in') %>:</dt>
  <dd><&
          '/widgets/profile/select.mc',
          options => $oc_opts,
          name    => 'ocSelect',
          useTable => 0,
          value   => $story->get_primary_oc_id,
      &>
      <% $m->comp('/widgets/profile/preview_link.mc',
      type  => 'story',
      value => $story->get_primary_uri,
      doc   => $story,
      oc_js => 'window.document.theForm.ocSelect.options[window.document.theForm.ocSelect.selectedIndex].value',
       style => 'blackUnderlinedLink',
) %></dd>
% }
  <dt><% $lang->maketext('Source') %>:</dt>
  <dd><% Bric::Biz::Org::Source->lookup({ id => $story->get_source__id })->get_source_name %></dd>
% unless (ENABLE_CATEGORY_BROWSER) {
  <dt><% $lang->maketext('Categories') %>:</dt>
  <dd><%perl>
$m->print(join '<br />&nbsp;', sort { $a cmp $b }
          map { $_->get_uri } $story->get_categories);
</%perl></dd>
% }   # unless ENABLE_CATEGORY_BROWSER
  <dt><% $lang->maketext('Cover Date') %>:</dt>
  <dd><% $story->get_cover_date %></dd>
  <dt><% $lang->maketext('Current Version') %>:</dt>
  <dd><% $story->get_current_version %></dd>
  <dt><% $lang->maketext('Published Version') %>:</dt>
  <dd><% $story->get_published_version || '&nbsp;' %></dd>
  <dt><% $lang->maketext('First Published') %>:</dt>
  <dd><% $story->get_first_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Last Published') %>:</dt>
  <dd><% $story->get_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Expire Date') %>:</dt>
  <dd><% $story->get_expire_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Output Channels') %>:</dt>
  <dd><% join ', ', (map { $_->get_name } $story->get_output_channels) %></dd>
</dl>

<& '/widgets/wrappers/sharky/table_bottom.mc' &>

<%perl>;
if ($param->{diff}) {
    my $version  = $story->get_version;
    my $from     = $param->{from};
    my $to       = $param->{to};
    my $from_ver = $param->{from_version};
    my $to_ver   = $param->{to_version};

    $m->comp(
        '/widgets/wrappers/sharky/table_top.mc',
        number  => ++$number,
        caption => $lang->maketext(
            'Diff between versions [_1] and [_2]',
            $from_ver, $to_ver
        ),
    );

    $m->print(
        '<div id="worddiff">' . join( "<br />\n", split /\r?\n|\r/,
            Text::WordDiff::word_diff(
            \$from->get_element->serialize_to_pod,
            \$to->get_element->serialize_to_pod, {
                STYLE => 'HTML',
                FILENAME_A => $from->get_uri  . " v.$from_ver",
                FILENAME_B => $to->get_uri . " v.$to_ver",
                MTIME_A    => $param->{from_time},
                MTIME_B    => $param->{to_time},
            }
        )) . '</div>'
    );

    $m->comp('/widgets/wrappers/sharky/table_bottom.mc');

}

else {
</%perl>
<& '/widgets/container_prof/container_prof.mc',
    element        => $element,
    element_type   => 'story',
    action      => 'view',
    start_count => ++$number,
    num         => 2
&>

<& '/widgets/wrappers/sharky/table_top.mc',
    caption => "Associations",
    number  => ++$number
&>
<table class="associations">
<tr class="odd">
  <th><% $lang->maketext('Categories') %>:</th>
  <td><%perl>
my @cats;
foreach my $cat ($story->get_categories) {
    push @cats, $cat->get_name;
}

$m->out(scalar(@cats) ? join(", ", @cats) : $lang->maketext("No categories defined."));
</%perl></td>
</tr>
<tr class="even">
  <th><% $lang->maketext('Keywords') %>:</th>
  <td><%perl>
my @keywords;
foreach my $kw ($story->get_keywords) {
    push @keywords, $kw->get_name;
}

$m->out(scalar(@keywords) ? join(", ", @keywords) : $lang->maketext("No keywords defined."));
</%perl></td>
</tr>
<tr class="odd">
  <th><% $lang->maketext('Contributors') %>:</th>
  <td><%perl>
my @contribs;
foreach my $cntr ($story->get_contributors) {
    push @contribs,  $cntr->get_name;
}
$m->out(scalar(@contribs) ? join(", ", @contribs) : $lang->maketext("No contributors defined."));

</%perl></td>
</tr>
</table>
<& '/widgets/wrappers/sharky/table_bottom.mc' &>
% }

% if ($curr_ver > 1) {
<& '/widgets/wrappers/sharky/table_top.mc',
    caption => 'Select Diff Version',
    number  => ++$number,
&>
<& '/widgets/profile/select.mc',
    name    => 'from_version',
    disp    => 'From Version',
    options => $versions,
    value   => $param->{from_version} || $story->get_version,
&>
<& '/widgets/profile/select.mc',
    name    => 'to_version',
    disp    => 'To Version',
    options => $versions,
    value   => $param->{to_version},
&>
<& '/widgets/profile/button.mc',
    name     => 'diff',
    button   => 'view_diff',
    useTable => 1,
    value    => 1,
&>
<& '/widgets/wrappers/sharky/table_bottom.mc' &>
% }
<& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Return"),
    widget    => $widget,
    cb        => 'return_cb',
    button    => 'return_dgreen',
    useTable  => 0 &>
<%args>
$widget
$param
</%args>
<%init>
my $story    = get_state_data($widget, 'story');
my $id       = $story->get_id;
my $element     = $story->get_element;
my @ocs      = $story->get_output_channels;
my $curr_ver = $story->get_current_version;
my $versions = [ map { [ $_ => $_] } reverse 1 .. $curr_ver ];
my $number   = 0;
</%init>
