<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php // phpcs:ignoreFile ?>
<div class="date-select">
    <?php $rand = wp_rand(1, 9999999999) ?>
    <div class="predefined-time-ranges-buttons button-group flex items-center text-sm">
        <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-1 day")); ?>" class="button predefined-date-button button-group__item text-sm <?php echo 'day' == $selected_predefined_date ? 'active' : '' ?> "><?php esc_html_e('24 Hours', 'anbarak'); ?></button>
        <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-1 week")); ?>" class="button predefined-date-button button-group__item text-sm <?php echo 'week' == $selected_predefined_date ? 'active' : '' ?> "><?php esc_html_e('Week', 'anbarak'); ?></button>
        <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-1 month")); ?>" class="button predefined-date-button button-group__item text-sm <?php echo 'month' == $selected_predefined_date ? 'active' : '' ?> "><?php esc_html_e('Month', 'anbarak'); ?></button>
        <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-3 months")); ?>" class="button predefined-date-button button-group__item text-sm <?php echo '3-months' == $selected_predefined_date ? 'active' : '' ?>"><?php esc_html_e('3 Months', 'anbarak'); ?></button>
        <button type="button" data-micromodal-trigger="modal-custom-date-range-<?php echo esc_attr($rand) ?>" class="button btn-select-custom-date button-group__item text-sm"><?php esc_html_e('More', 'anbarak'); ?> <span class="icon icon-arrow-down"></span></button>
    </div>

    <div id="modal-custom-date-range-<?php echo esc_attr($rand) ?>" class="micro-modal micromodal-slide select-date-modal" aria-hidden="false">
        <div class="modal__overlay" tabindex="-1" data-micromodal-close="">
            <div class="modal__container box" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
                <header class="modal__header">
                    <h2 class="modal__title"><?php esc_html_e('Select Date', 'anbarak'); ?></h2>
                    <button class="modal__close" type="button" aria-label="Close modal" data-micromodal-close></button>
                </header>
                <main class="modal__content">
                    <div class="flex flex-col gap-5">
                        <div class="flex gap-5">
                            <div class="flex items-center ">
                                <label class="text-sm me-2" for=""><?php esc_html_e('Date From:', 'anbarak') ?></label>
                                <?php \Anbarak\Input::renderDatePicker([
                                    'name' => 'date-from',
                                    'timestamp' => $date_from,
                                    'class' => 'me-2',
                                ]); ?>
                            </div>
                            <div class="flex items-center">
                                <label class="text-sm me-2" for=""><?php esc_html_e('Date To:', 'anbarak') ?></label>
                                <?php \Anbarak\Input::renderDatePicker([
                                    'name' => 'date-to',
                                    'timestamp' => $date_to,
                                    'class' => 'me-2',
                                ]); ?>
                            </div>
                        </div>
                        <div class="predefined-time-ranges-buttons button-group inline-flex items-center text-sm">
                            <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-6 months")); ?>" class="button flex-grow button-group__item predefined-date-button text-sm"><?php esc_html_e('6 Months', 'anbarak'); ?></button>
                            <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(strtotime("-1 year")); ?>" class="button flex-grow button-group__item predefined-date-button text-sm"><?php esc_html_e('12 Months', 'anbarak'); ?></button>
                            <button type="button" data-date-to="<?php echo esc_attr(time()) ?>" data-date-from="<?php echo esc_attr(0) ?>" class="button flex-grow button-group__item predefined-date-button text-sm"><?php esc_html_e('All Time', 'anbarak'); ?></button>
                        </div>
                    </div>
                </main>
            </div>
        </div>
    </div>
</div>
