<?php
declare(strict_types=1);

use Fisharebest\Webtrees\I18N;

$id = 'google-chart-' . bin2hex(random_bytes(8));
?>

<?php if (count($data) === 1): ?>
    <?= I18N::translate('This information is not available.') ?>
<?php else: ?>

    <?= view('statistics/other/chart-setup') ?>

    <div id="<?= $id ?>" title="<?= $chart_title ?? '' ?>"></div>

    <script>

    var callbackColumnChart = function () {
        google.charts.setOnLoadCallback(function () {
            drawColumnChart(
                '<?= $id ?>',
                <?= json_encode($data) ?>,
                <?= json_encode($chart_options) ?>
            );
        });

        $(window).resize(function () {
            drawColumnChart(
                '<?= $id ?>',
                <?= json_encode($data) ?>,
                <?= json_encode($chart_options) ?>
            );
        });
    };

    if (
        document.readyState === "complete" ||
        (document.readyState !== "loading" && !document.documentElement.doScroll)
    ) {
        callbackColumnChart();
    } else {
        document.addEventListener("DOMContentLoaded", callbackColumnChart);
    }

    </script>
<?php endif; ?>
