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

$rightText .= $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|notes_cb",
  value    => 'edit',
  image    => %{ $fa->get_notes } ? 'note_fill' : "note",
  useGlobalImage => 1,
);

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

);
</%perl>

  <table border="0" width="578" cellpadding="0" cellspacing="0">
  <tr>
    <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
    <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Template Type') %>:&nbsp;</span></td>
    <td width="470">&nbsp;<% $fa->get_tplate_type_string %></td>
  </tr>
  <tr>
    <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
    <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
% if ($fa->get_tplate_type == Bric::Biz::Asset::Formatting::ELEMENT_TEMPLATE) {
    <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Element') %>:&nbsp;</span></td>
    <td width="470">&nbsp;<% $fa->get_element_name %></td>
% } else {
    <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Name') %>:&nbsp;</span></td>
    <td width="470">&nbsp;<% $fa->get_name %></td>
% }
  </tr>
  <tr>
    <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
    <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
    <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Output Channel') %>:&nbsp;</span></td>
    <td width="470">&nbsp;<% $fa->get_output_channel_name %></td>
  </tr>
  <tr>
    <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
    <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
    <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('URI') %>:&nbsp;</span></td>
    <td width="470">&nbsp;<% $fa->get_uri %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Site') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% Bric::Biz::Site->lookup({id => $fa->get_site_id})->
  get_name() %></td>
  </tr>
  <tr>
    <td class="medHeader" colspan=3><img src="/media/images/spacer.gif" height="1" width="1" /></td>
  </tr>
  </table>

<& '/widgets/profile/displayFormElement.mc',
   objref => $fa,
   key => 'priority',
&>

<& '/widgets/select_object/select_object.mc',
    object => 'category',
    constrain => { site_id => $fa->get_site_id },
    field => 'uri',
    sort_field => 'uri',
    name => 'category_id',
    disp => 'Category',
    selected => $fa->get_category_id
&>

<& '/widgets/profile/displayFormElement.mc',
   objref => $fa,
   key => 'description',
&>

<& '/widgets/profile/displayFormElement.mc',
	objref => $fa,
	key => 'expire_date',
&>

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


<& /widgets/wrappers/sharky/table_top.mc,
   caption => 'Template Code',
   number  => 2
&>
% if ($at) {
  <table border=0 cellpadding=0 cellspacing=0 width=578>
    <tr>
      <td width=1 height=20 class=medHeader><img src="/media/images/spacer.gif" width=1 height=20 /></td>
      <td width=<% FIELD_INDENT %> align="right" class=medHeader><span class=label><% $lang->maketext('Key Name') %>:&nbsp;</span></td>
      <td width=5 height=20><img src="/media/images/spacer.gif" width=5 height=20 /></td>
      <td width=<% 577 - FIELD_INDENT %>>
	<% $at->get_key_name  . $show_element_flags->($at) %>
      </td>
    </tr>
    <tr><td colspan=4><img src="/media/images/spacer.gif" width=578 height=1 /></td></tr>
% if (@{$at->get_data}) {
    <tr>
      <td width=1 height=20 class=medHeader><img src="/media/images/spacer.gif" width=1 height=20 /></td>
      <td align="right" class=medHeader><span class=label><% $lang->maketext('Data Elements') %>:&nbsp;</span></td>
      <td width=5 height=20><img src="/media/images/spacer.gif" width=5 height=20 /></td>
      <td>
% my $comma = '';
% foreach my $d ($at->get_data) {
% $m->print($comma, $d->get_key_name, $show_data_flags->($d));
%     $comma ||= ', ';
% }
      </td>
    </tr>
    <tr><td colspan=4><img src="/media/images/spacer.gif" width=578 height=1 /></td></tr>
% }
% if (@{$at->get_containers}) {
    <tr>
      <td width=1 height=20 class=medHeader><img src="/media/images/spacer.gif" width=1 height=20 /></td>
      <td align="right" class=medHeader><span class=label><% $lang->maketext('Container Elements') %>:&nbsp;</span></td>
      <td width=5 height=20><img src="/media/images/spacer.gif" width=5 height=20 /></td>
      <td>
% my $comma = '';
% foreach my $c ($at->get_containers) {
% $m->print($comma, $c->get_key_name, $show_subelement_flags->($at, $c));
%     $comma ||= ', ';
% }
      </td>
    </tr>
% }
  <tr><td colspan=4 class=medHeader><img src="/media/images/spacer.gif" width=578 height=1 /></td></tr>
  </table>
% }


<table border=0 cellpadding=2 cellspacing=0 width=550>
<tr>
  <td width=46 rowspan=2 valign="top">

  </td>
  <td width=500>
  <textarea name="<% "$widget|code" %>" rows="20" cols="<% $agent->ie ? 60 : 72 %>" width="200" wrap="off" class="codeArea"><% escape_html($fa->get_data) %></textarea>
</td>
</tr>
</table>
<& /widgets/wrappers/sharky/table_bottom.mc &>

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


<%args>
$widget
</%args>

<%init>

my $fa = get_state_data($widget, 'fa');
my $at = $fa->get_element;

# Use the same reset key for this widget in all the widgets we call.
my $rk    = get_state_data($widget, 'reset_key');

# Get the workflow ID.
my $wf_id = get_state_data($widget, 'work_id') || $fa->get_workflow_id();

# Lookup the workflow and get its allowed desks.
my $wf    = Bric::Biz::Workflow->lookup({id => $wf_id});
my $desks = $wf->allowed_desks();

# Get the current desk, or if this hasn't been put on a desk yet, the start desk
my $cd    = $fa->get_current_desk() || $wf->get_start_desk();

# Set up a formatting variable
my $agent = detect_agent();
my $infoIndent = $agent->nav4 ? FIELD_INDENT - 5 : FIELD_INDENT + 8;

</%init>

<%once>
my $show_element_flags = sub {
    my ($at) = @_;
    my @flags;

    push @flags, 'paginated' if $at->get_paginated;
    push @flags, 'top level' if $at->get_top_level;
    push @flags, 'fixed url' if $at->get_fixed_url;
    push @flags, 'media'     if $at->is_media;
    push @flags, 'related media' if $at->is_related_media;
    push @flags, 'related story' if $at->is_related_story;

    if (scalar @flags) {
        return '&nbsp;<span class="orangeLink">('.join(', ', @flags).')</span>';
    } else {
        return;
    }
};

my $show_data_flags = sub {
    my ($d) = @_;
    my @flags;

    push @flags, 'required' if $d->get_required;
    push @flags, 'repeatable' if $d->get_quantifier;
  
    if (scalar @flags) {
        return '&nbsp;<span class="orangeLink">('.join(', ', @flags).')</span>';
    } else {
        return;
    }
};

my $show_subelement_flags = sub {
    my ($at, $c) = @_;
    my @flags;

    push @flags, 'repeatable' if $at->is_repeatable($c);

    if (scalar @flags) {
        return '&nbsp;<span class="orangeLink">('.join(', ', @flags).')</span>';
    } else {
        return;
    }
};

</%once>
