package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
#line 50 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"

  use List::Util ();
  use Lingua::EN::Inflect ();
  use CXGN::Page::FormattingHelpers qw | columnar_table_html |;
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
HTML::Mason::Exception::Params->throw
    ( error =>
      "Odd number of parameters passed to component expecting name/value pairs"
    ) if @_ % 2;
my %ARGS = @_;
my ( $data, $headings, $frequency_tables );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }

    foreach my $arg ( qw( data ) )
    {
        HTML::Mason::Exception::Params->throw
            ( error => "no value sent for required parameter '$arg'" )
                unless exists $pos{$arg};
    }
#line 46 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"
    $data = $_[ $pos{'data'} ];
#line 47 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"
     $headings = exists $pos{'headings'} ? $_[ $pos{'headings'} ] :  undef;
#line 48 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"
     $frequency_tables = exists $pos{'frequency_tables'} ? $_[ $pos{'frequency_tables'} ] :  [];
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 55 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"

if( @$frequency_tables && @$data > 4) {
    my %heading_idx = do { my $i = 0; map {lc $_ => $i++} @$frequency_tables };
    for my $colname (@$frequency_tables) {
        my $idx = $heading_idx{ lc $colname };
        my $name = $headings->[$idx];
        my @data_slice = map $_->[$idx], @$data;
        my %stats;
        $stats{$_}++ for @data_slice;
        my @stat_disp = map {
            [ $stats{$_}, $_ ]
        } sort keys %stats;

        if( @stat_disp > 1 ) {
            push @stat_disp, [ List::Util::sum( map $_->[0], @stat_disp ), '<b>Total</b>' ];
        }

        print '<div style="width: 30%; float: left; margin: 2px;">'.columnar_table_html( data => \@stat_disp, __caption => Lingua::EN::Inflect::PL_N( $name ), __align => 'rl' ).'</div>';
    }
}
#line 76 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"
$m->print(  columnar_table_html( %ARGS )  );
#line 76 "/home/production/cxgn/sgn/mason/page/columnar_table.mas"
$m->print( '

' );
;return;
},
'declared_args' => {
  '$data' => { default => undef },
  '$frequency_tables' => { default => ' []' },
  '$headings' => { default => ' undef' }
},
'load_time' => 1763108195,

)
;