/**
  * [happiness_report] shortcode
  *
  * @since  1.0
  */
 public function happiness_report_shortcode($atts, $content = null)
 {
     $atts = shortcode_atts(array('rating' => '', 'graph' => ''), $atts, 'happiness_report');
     $content = hrfhs_show_rating($atts);
     if (isset($atts['graph']) && 'yes' === $atts['graph']) {
         $hrfhs = happiness_reports_for_help_scout()->functions;
         $graph_options = $hrfhs->graph_options();
         // load scripts
         wp_enqueue_script('hrfhs-frontend');
     }
     return do_shortcode($content);
 }
/**
 *  Load the frontend styles
 *
 *  @since 1.0.0
 *  @return void
 */
function hrfhs_styles()
{
    global $post;
    $hrfhs = happiness_reports_for_help_scout()->functions;
    $graph_options = $hrfhs->graph_options();
    if (!is_object($post)) {
        return;
    }
    if (has_shortcode($post->post_content, 'happiness_report') || apply_filters('hrfhs_force_frontend_scripts', false)) {
        ?>

        <style>
            .pie { position: relative; box-sizing: border-box; }
            .pie canvas { padding: 0; }
            .pie > div { position: absolute; left: 50%; top: 50%; transform: translate( -50%, -50% ) }
            .pie .label { font-size: 1.2em; font-weight: 700; text-transform: uppercase; text-align: center; }
            .pie .great { color: <?php 
        echo $graph_options['color_great'];
        ?>
; }
            .pie .okay { color: <?php 
        echo $graph_options['color_okay'];
        ?>
; }
            .pie .not-good { color: <?php 
        echo $graph_options['color_not_good'];
        ?>
; }
            .pie .value { font-size: 3em; text-align: center; margin-left: 1rem; line-height: 1.2; }
			.pie .percent { font-size: 20px; vertical-align: super; }
            .pie:last-child { margin-right: 0; }
			.graph-single .pie { margin-bottom: 1.5em; }
			@media only screen and ( max-width: 640px ) { .graphs-all .pie { margin-bottom: 1.5em; } }
			@media only screen and ( min-width: 641px ) { .graphs-all { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; -webkit-justify-content: space-between; justify-content: space-between; } .graphs-all .pie { width: 30%; } .graph-single { max-width: 300px; } }
        </style>

	<?php 
    }
}
/**
 * Show the ratings in graphs
 *
 * @since 1.0.0
 */
function hrfhs_ratings_graphs($rating = '')
{
    $hrfhs = happiness_reports_for_help_scout()->functions;
    $options = $hrfhs->options();
    $graph_options = $hrfhs->graph_options();
    $show_labels = $graph_options['show_labels'];
    $show_scores = $graph_options['show_scores'];
    if (!$rating) {
        $rating = 'all';
    }
    $css_class = 'all' == $rating ? ' graphs-all' : ' graph-single';
    ob_start();
    ?>

    <div class="graph-happiness-reports<?php 
    echo $css_class;
    ?>
">

        <?php 
    if ('great' == $rating || 'all' == $rating) {
        ?>
        <div class="pie">
            <div class="great">
                <?php 
        if ($show_labels) {
            ?>
                <div class="label"><?php 
            echo $options['label_great'];
            ?>
</div>
                <?php 
        }
        ?>
                <?php 
        if ($show_scores) {
            ?>
                <div class="value"><span><?php 
            echo happiness_reports_for_help_scout()->functions->score('great');
            ?>
</span><span class="percent">%</span></div>
                <?php 
        }
        ?>
            </div>
            <canvas class="chart-great" width="500" height="500" />
        </div>
        <?php 
    }
    ?>

        <?php 
    if ('okay' == $rating || 'all' == $rating) {
        ?>
        <div class="pie">
            <div class="okay">
                <?php 
        if ($show_labels) {
            ?>
                <div class="label"><?php 
            echo $options['label_okay'];
            ?>
</div>
                <?php 
        }
        ?>
                <?php 
        if ($show_scores) {
            ?>
                <div class="value"><span><?php 
            echo happiness_reports_for_help_scout()->functions->score('okay');
            ?>
</span><span class="percent">%</span></div>
                <?php 
        }
        ?>
            </div>
            <canvas class="chart-okay" width="500" height="500" />
        </div>
        <?php 
    }
    ?>

        <?php 
    if ('notGood' == $rating || 'all' == $rating) {
        ?>
        <div class="pie">
            <div class="not-good">
                <?php 
        if ($show_labels) {
            ?>
                <div class="label"><?php 
            echo $options['label_not_good'];
            ?>
</div>
                <?php 
        }
        ?>
                <?php 
        if ($show_scores) {
            ?>
                <div class="value"><span><?php 
            echo happiness_reports_for_help_scout()->functions->score('notGood');
            ?>
</span><span class="percent">%</span></div>
                <?php 
        }
        ?>
            </div>
            <canvas class="chart-not-good" width="500" height="500" />
        </div>
        <?php 
    }
    ?>

    </div>

    <?php 
    $content = ob_get_clean();
    return $content;
}
    /**
     * Mailboxes callback
     *
     * @since  1.0.0
     */
    public function callback_mailboxes($args)
    {
        $options = get_option('help_scout_happiness_reports');
        $mailboxes = happiness_reports_for_help_scout()->functions->get_mailboxes();
        // get API key
        $api_key = $options['help_scout_api_key'];
        if (!$api_key) {
            _e('Please enter you API key above and click "Save Changes" to view your mailboxes', 'happiness-reports-for-help-scout');
        }
        if (empty($mailboxes)) {
            return;
        }
        foreach ($mailboxes as $key => $mailbox) {
            $checked = isset($options['help_scout_mailboxes'][$key]) ? $options['help_scout_mailboxes'][$key] : '';
            ?>

		<label for="<?php 
            echo $mailbox->id;
            ?>
" class="description">
			<input type="checkbox" class="" id="<?php 
            echo $mailbox->id;
            ?>
" name="help_scout_happiness_reports[<?php 
            echo $args['name'];
            ?>
][<?php 
            echo $key;
            ?>
]" value="<?php 
            echo $mailbox->id;
            ?>
"  <?php 
            checked($checked, $mailbox->id);
            ?>
 />
			<?php 
            echo $mailbox->name;
            ?>
		</label>
		<br />

	<?php 
        }
        ?>
		<?php 
    }