#!/usr/bin/perl
# -*- Mode: perl -*-
# file: polymorphism

use lib '/usr/local/gramene/lib/perl/';
use strict;
use vars qw($DB);
use Ace 1.51;
use Ace::Browser::AceSubs qw(:DEFAULT Toggle);
use GrameneSubs;
use CGI 2.42 qw/:standard :html3 escape *table *blockquote/;

use constant CLASS   => 'Polymorphism';
#use constant EXAMPLE => 'BCD98/EcoRI';

# open the database
$DB = OpenDatabase() || AceError("Couldn't open database.");

my ($obj_name, $obj);
$obj_name = param('name');
$obj = get_obj($obj_name) if $obj_name;

PrintTop($obj,CLASS,$obj ? CLASS . ": $obj" : CLASS . " Search");
PrintWarning($obj_name,CLASS) if $obj_name && !$obj;
print_report($obj) if $obj;
PrintBottom();

sub get_obj {
  my $name = shift;
  my ($obj) = $DB->fetch(-class =>CLASS,
			 -name  => $name);
  return $obj;
}

sub print_report {
  my $obj = shift;

  print start_table({-border=>1});
  if ($obj->Marker) {
    print TR(
	   th({-class=>'datatitle'},'Marker'),
	   td({-class=>'databody'},ObjectLink($obj->Marker))
	   );
  }
  if ($obj->Enzyme) {
    print TR(
	   th({-class=>'datatitle'},'Enzyme'),
 	   td({-class=>'databody'},$obj->Enzyme)
	   );
  }
  if ($obj->Image) {
    print TR(
	   th({-class=>'datatitle'},'Image'),
 	   td({-class=>'databody'},ObjectLink($obj->Image))
	   );
  }
  if ($obj->Pattern) {
    print TR(
	   th({-class=>'datatitle'},'Pattern'),
 	   td({-class=>'databody'},$obj->Pattern)
	   );
  }
  if ($obj->Reference) {
    print TR(
	   th({-class=>'datatitle'},'Reference'),
 	   td({-class=>'databody'},ObjectLink($obj->Reference))
	   );
    DataRow('Remarks',$obj->Remarks);
  }
  print end_table;

  if ($obj->Label) {
    my $label = $obj->Label;
    my @headers = split /\s+/,$label;
    unshift @headers,'';
    my $heading = TR(th({-class=>'datatitle'},\@headers));
    my $table   = $obj->Size(0)->asHTML;
    $table=~ s/<TR/$heading\n<TR/i;
    print $table;
#    my $string = join("\n",$obj->Label,$obj->Size(0)->asTable);
#    my $pad = '&nbsp;'x8;
#    $string =~ s/\t/$pad/g;
#    print pre(font({-font=>'monospaced'},$string));
  }

  my $info = $obj->Help->Info;
  if ( $info ) {
    print br,br;
    if ( Toggle('help','Help on polymorphism') ) {
      print pre($info->right);
    }
  }
}


