<?php

/**
 * Reports Main View
 */

?>

<div class="wrap">
    <h1><?php esc_html_e( 'Reports', 'giveasap' ); ?></h1>

    <h2 class="nav-tab-wrapper">
        <?php
            $sub_reports = array();
            $current_section = '';

            if ( $reports ) {
	            $current_section = isset( $_GET['section'] ) ? $_GET['section'] : 'subscribers';
                foreach ( $reports as $report_section_slug => $report_section ) {
                    $active_tab = '';
                    if ( $report_section_slug === $current_section ) {
                        $sub_reports = $report_section['reports'];
	                    $active_tab = 'nav-tab-active';
                    }
                    ?>
                    <a class="nav-tab <?php echo esc_attr( $active_tab ); ?>" href="<?php echo admin_url( 'edit.php?post_type=giveasap&page=sg_reports&section=' . $report_section_slug ); ?>"><?php echo $report_section['title']; ?></a>
                    <?php
                }
            }
        ?>
    </h2>
    <?php
        if ( $sub_reports ) {
            $active_report = isset( $_GET['report'] ) && isset( $sub_reports[ $_GET['report'] ] ) ? $_GET['report'] : false;
            if ( false == $active_report ) {
                $report_slugs = array_keys( $sub_reports );
                $active_report = $report_slugs[ 0 ];
            }
            echo '<ul class="subsubsub">';
            foreach ( $sub_reports as $sub_report_slug => $report_title ) {
                echo '<li>';
                echo '<a ' . ( $sub_report_slug === $active_report ? 'class="current"' : '' ) . ' href="' . admin_url( 'edit.php?post_type=giveasap&page=sg_reports&section=' . $current_section . '&report=' . $sub_report_slug ) . '">' . $report_title . '</a>';
                echo '</li>';
            }
            do_action( 'sg_reports_' . $current_section . '_sub_reports' );
            echo '</ul>';
        }
        do_action( 'sg_reports_' . $current_section . '_after_sub_reports' );
    ?>

	<?php $options = $report->get_report_options(); ?>
    <div class="sg-report-view <?php if ( $options ) { echo 'with-options'; } ?>">
        <?php echo $options; ?>

        <div class="sg-report-container">
            <?php echo $report->get_view(); ?>
        </div>
    </div>
    <?php
        if ( $options ) {
            ?>
            <br/>
            <label><?php esc_html_e( 'Options', 'giveasap' ); ?></label>
            <div class="sg-report-options-switch on">
                <div class="data-on">
                    <span class="selected"><?php esc_html_e( 'ON', 'giveasap' ); ?></span>
                    <span><?php esc_html_e( 'OFF', 'giveasap' ); ?></span>
                </div>
                <div class="data-off">
                    <span><?php esc_html_e( 'ON', 'giveasap' ); ?></span>
                    <span class="selected"><?php esc_html_e( 'OFF', 'giveasap' ); ?></span>
                </div>
            </div>
            <?php
        }
    ?>
</div>
<script type="text/javascript">

    var sgReports = {
        legend: <?php echo $report->show_legend(); ?>,
        type: '<?php echo $report->get_type(); ?>',
        labels: [  <?php echo $report->get_labels(); ?>],
        datasets: <?php echo wp_json_encode( $report->get_data_sets() ); ?>
    };

</script>