<%perl>
my $rightText = $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|trail_cb",
  image    => "view_trail_teal",
  alt      => 'Trail',
) . '&nbsp;';

$rightText .= $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|notes_cb",
  value    => 'view',
  image    => $media->has_notes ? 'note_fill' : "note",
  alt      => 'Notes',
  useGlobalImage => 1,
);

$m->comp("/widgets/wrappers/sharky/table_top.mc",
  	 caption => "Information",
	 number  => ++$number,
         id  => 'mediainfo',
   rightText => $rightText

);
</%perl>
<dl class="viewmeta">
  <dt><%$lang->maketext('UUID')%>:</dt>
  <dd title="ID: <% $media->get_id %>"><% $media->get_uuid %></dd>
  <dt><% $lang->maketext('Media Type')%>:</dt>
  <dd><% $media->get_element_name %></dd>
  <dt><% $lang->maketext('Title') %>:</dt>
  <dd><% $media->get_title %></dd>
  <dt><%$lang->maketext('URI') %>:</dt>
% if ($media->get_file_name) {
  <dd><% $m->comp(
      '/widgets/profile/preview_link.mc',
      type  => 'media',
      doc   => $media,
   )%></dd>
% } else {
  <dd>&nbsp;</dd>
% }
  <dt><% $lang->maketext('Source') %>:</dt>
  <dd><% Bric::Biz::Org::Source->lookup({ id => $media->get_source__id })->get_source_name %></dd>
  <dt><% $lang->maketext('Current Version') %>:</dt>
  <dd><% $media->get_version() %></dd>
  <dt><% $lang->maketext('Published Version') %>:</dt>
  <dd><% $media->get_published_version || '&nbsp;' %></dd>
  <dt><% $lang->maketext('First Published') %>:</dt>
  <dd><% $media->get_first_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Last Published') %>:</dt>
  <dd><% $media->get_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Priority') %>:</dt>
  <dd><% $media->get_priority() %></dd>
  <dt><% $lang->maketext('Output Channels') %>:</dt>
  <dd><% join ', ', (map { $_->get_name } $media->get_output_channels) %></dd>
</dl>

<& '/widgets/wrappers/sharky/table_bottom.mc' &>
<& 'file_section.mc', media     => $media,
                      widget    => $widget,
                      num       => ++$number,
                      read_only => 1,
                      indent    => FIELD_INDENT + 8,
&>
<%perl>;
if ($param->{diff}) {
    my $version  = $media->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   => 'media',
  action      => 'view',
  num         => ++$number,
  title       => 'Content',
  start_count => 6
&>

<& '/widgets/wrappers/sharky/table_top.mc',
   caption => "Associations",
   number => 4
&>

<table class="associations">
<tr class="odd">
  <th><% $lang->maketext('Category') %>:</th>
  <td><%perl>
my $cat = $media->get_category;
$m->out($cat->get_name);
</%perl></td>
</tr>
<tr class="even">
  <th><% $lang->maketext('Keywords') %>:</th>
  <td><%perl>
my @keywords;
foreach my $kw ($media->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 ($media->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} || $media->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 $media    = get_state_data($widget, 'media');
my $id       = $media->get_id;
my $element     = $media->get_element;
my @ocs      = $media->get_output_channels;
my $curr_ver = $media->get_current_version;
my $versions = [ map { [ $_ => $_] } reverse 1 .. $curr_ver ];
my $number   = 0;
#set_state_data('container_prof', 'element', $element);
</%init>
