<?php
/**
 * مالی — مدیریت کوپن‌های ووکامرس.
 */
if (!defined('ABSPATH')) {
    exit;
}

$wc_ok = zerti_wc_coupons_available();
$can_manage = zerti_user_can_manage_wc_coupons();
?>
<?php
zerti_ui_component_open('financial-coupons', [
    'class' => 'zerti-component-financial zerti-financial-sub-slot',
    'data-zerti-fin-active' => 'coupons',
    'data-zerti-fin-component' => 'coupons',
    'data-zerti-coupons-root' => '1',
]);
?>
    <?php if (!$wc_ok) : ?>
        <?php zerti_ui_wc_required_notice(__('WooCommerce must be installed and active to manage coupons.', 'zerti')); ?>
    <?php elseif (!$can_manage) : ?>
        <?php zerti_ui_alert(__('You do not have permission to manage coupons.', 'zerti'), 'warning', ['class' => 'mb-0']); ?>
    <?php else : ?>
        <div class="zerti-coupons-panel">
            <div class="zerti-coupons-list" data-zerti-coupons-list="1">
                <div class="alert alert-success py-2 small d-none zerti-coupons-list-flash mb-2" role="status" aria-live="polite"></div>
                <div class="zerti-coupons-wrap">
                    <?php
                    zerti_ui_toolbar_open(
                        __('Search and filter coupons list', 'zerti'),
                        'zerti-coupons-grid-toolbar'
                    );
                    ?>
                        <div class="zerti-coupons-grid-toolbar-search"></div>
                        <?php
                        zerti_ui_toolbar_section_open('zerti-coupons-actions');
                        zerti_ui_button([
                            'class' => 'zerti-coupons-add-btn',
                            'icon' => 'fa-solid fa-plus',
                            'label' => __('Add coupon', 'zerti'),
                            'title' => __('Add coupon', 'zerti'),
                            'attrs' => ['data-zerti-coupons-add' => '1'],
                        ]);
                        zerti_ui_toolbar_section_close();
                        ?>
                    <?php zerti_ui_toolbar_close(); ?>
                    <?php
                    zerti_ui_ag_grid_region(
                        'zertiCouponsGrid',
                        'zerti-coupons-grid',
                        __('Coupons table', 'zerti')
                    );
                    ?>
                </div>
            </div>

            <div class="zerti-coupons-editor d-none" data-zerti-coupons-editor="1" aria-hidden="true">
                <div class="zerti-coupons-editor-bar d-flex flex-wrap align-items-center gap-2 mb-3">
                    <div class="zerti-coupons-editor-bar-start d-flex flex-wrap align-items-center gap-2 min-w-0">
                        <button type="button" class="btn btn-sm btn-outline-secondary zerti-coupons-back-btn" data-zerti-coupons-back>
                            <i class="fa-solid fa-arrow-right ms-1" aria-hidden="true"></i>
                            <?php esc_html_e('Back to list', 'zerti'); ?>
                        </button>
                        <h2 class="h6 mb-0 zerti-coupons-editor-title" data-zerti-coupons-editor-title></h2>
                    </div>
                    <div class="zerti-coupons-editor-actions d-flex flex-wrap gap-2 ms-auto">
                        <button type="button" class="btn btn-sm btn-outline-danger zerti-coupons-delete-btn d-none" data-zerti-coupons-delete>
                            <?php esc_html_e('Move to trash', 'zerti'); ?>
                        </button>
                        <button type="button" class="btn btn-sm btn-primary zerti-coupons-save-btn" data-zerti-coupons-save>
                            <?php esc_html_e('Save coupon', 'zerti'); ?>
                        </button>
                    </div>
                </div>
                <div class="zerti-coupons-editor-scroll">
                    <div class="zerti-coupons-editor-slot" data-zerti-coupons-editor-slot></div>
                </div>
            </div>
        </div>
    <?php endif; ?>
<?php zerti_ui_component_close(); ?>
