<& '/widgets/profile/hidden.mc',
    name    => "$widget|update_cb",
    value   => 1,
&>
<%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",
  image    => $media->has_notes ? 'note_fill' : "note",
  useGlobalImage => 1,
  value    => 'edit',
  alt      => 'Notes',
);

$m->comp("/widgets/wrappers/sharky/table_top.mc",
         caption => "Information",
         number  => $num++,
         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('Current Version') %>:</dt>
<dd><% $media->get_current_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('URI') %>:</dt>
% if (my $uri = $media->get_primary_uri) {
%     if (@ocs == 1) {
<dd><% $m->comp('/widgets/profile/preview_link.mc',
                                    type  => 'media',
                                    value => $media->get_primary_uri,
                                    doc   => $media,
                                    style => 'blackUnderlinedLink') %></dd>
%     } else {
<dd><% $uri %></dd>
<dt><% $lang->maketext('Preview in') %>:</dt>
<dd><% $oc_select %>&nbsp;<a href="#" onClick="window.open('/workflow/profile/preview/media/<% $id %>/' + window.document.theForm.ocSelect.options[window.document.theForm.ocSelect.selectedIndex].value, 'preview_<% SERVER_WINDOW_NAME %>');return false;"><img src="/media/images/<% $lang_key %>/preview_lgreen.gif" alt="Preview" border="0" width="74" height="20"></a></dd>
%     }
% }
% if (@$sites > 1) {
<dt><% $lang->maketext('Site') %>:</dt>
<dd><% Bric::Biz::Site->lookup({id => $media->get_site_id})->get_name() %></dd>
% }
</dl>

<div class="editmeta">
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'title',
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'description',
&>
<& '/widgets/select_object/select_object.mc',
  object   => 'source',
  name     => "$widget|source__id",
  field    => 'source_name',
  selected => $media->get_source__id,
  indent   => 0,
  useTable => 1,
  disp     => "Source"
&>

% unless (ENABLE_CATEGORY_BROWSER) {
<& '/widgets/select_object/select_object.mc',
  object        => 'category',
  constrain => { site_id => $media->get_site_id },
  name          => "$widget|category__id",
  field         => "uri",
  sort_field    => "uri",
  selected      => $media->get_category__id,
  indent        => 0,
  req           => 1,
  useTable      => 1,
  exclude       => sub { ! chk_authz($_[0], READ, 1) },
  disp          => "Category"
&>
% }  # unless ENABLE_CATEGORY_BROWSER

<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'priority',
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'cover_date',
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'expire_date',
&>
</div>
<%perl>;
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

$m->comp('file_section.mc',
         media     => $media,
         widget    => $widget,
         num       => $num++,
         read_only => $media->get_alias_id,
         indent    => $infoIndent
        );

$num = $m->comp( '/widgets/container_prof/container_prof.mc',
        element        => $element,
        element_type   => 'media',
        action      => $media->get_alias_id ? 'view' : 'edit',
        num         => $num,
        title       => 'Content',
        start_count => 6
);

if (ENABLE_OC_ASSET_ASSOCIATION) {
    $m->comp('/widgets/profile/asset_ocs.mc',
             asset  => $media,
             widget => $widget,
             ocs    => \@ocs,
             num    => $num++,
             at_ocs => \@aocs
         );
}

$m->comp("/widgets/wrappers/sharky/table_top.mc",
         caption => "Associations",
         number => $num++);
</%perl>
% my $rowColor = "even";
<table class="associations">
% if (ENABLE_CATEGORY_BROWSER) {
% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<th><% $lang->maketext('Category') %>:</th>
<td><% $media->get_category->get_uri %></td>
<td class="edit"><& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'category_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &></td>
</tr>
% }   # if ENABLE_CATEGORY_BROWSER

% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<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>
<td class="edit"><& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'keywords_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &></td>
</tr>

% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<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>
<td class="edit">
% unless ($media->get_alias_id) {
<& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'contributors_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &>
% }
</td>
</tr>
</table>
<%perl>
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

$m->comp("/widgets/profile/buttonBar.mc",
         widget      => $widget,
         desks       => $desks,
         cd          => $cd,
         obj         => $media,
);

</%perl>

<%args>
$widget
</%args>

<%init>

my $media = get_state_data($widget, 'media');
my $element = $media->get_element();

set_state_data('container_prof', 'element', $element);

my $wf_id = get_state_data($widget, 'work_id');
$wf_id = $media->get_workflow_id() unless $wf_id;
my $wf = Bric::Biz::Workflow->lookup( { id => $wf_id });
my $desks = $wf->allowed_desks();
my $cd = $media->get_current_desk();
$cd = $wf->get_start_desk() unless $cd;
my $id = $media->get_id;
my $sites = $c->get('__SITES__') || Bric::Biz::Site->list({ active => 1 });

# Set up a formatting variable
my $infoIndent = FIELD_INDENT + 8;
my $num = 1;

# get output channel info
my $asset_type = $media->get_element_type;
my @aocs = $asset_type->get_output_channels;
my @ocs = $media->get_output_channels;
my $primocid = $media->get_primary_oc_id;

my $oc_select = '<select name="ocSelect">';
foreach my $oc (@ocs) {
    my $ocid = $oc->get_id;
    my $selected = $ocid == $primocid ? ' selected' : '';
    $oc_select .= qq{<option value="$ocid"$selected>} . $oc->get_name . '</option>';
}
$oc_select .= '</select>';
</%init>

