<div class="wrap unlockafe-coupon-generator">
    <h1><?php echo esc_html__('Bulk Coupon Generator', 'unlock-addons-for-elementor'); ?></h1>

    <form method="post" action="">
        <?php wp_nonce_field('unlockafe_bulk_coupon_action', 'unlockafe_bulk_coupon_nonce'); ?>

        <div id="unlockafe-accordion">
            <!-- General Settings -->
            <h3><?php echo esc_html__('General Settings', 'unlock-addons-for-elementor'); ?></h3>
            <div>
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row">
                            <label for="coupon_count"><?php echo esc_html__('Number of Coupons', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="number" id="coupon_count" name="coupon_count" class="regular-text" value="10" min="1" max="1000" required />
                            <p class="description"><?php echo esc_html__('Number of coupons to generate (1-1000).', 'unlock-addons-for-elementor'); ?></p>
                        </td>
                    </tr>
                </table>
            </div>

            <!-- Coupon Data -->
            <h3><?php echo esc_html__('Coupon Details', 'unlock-addons-for-elementor'); ?></h3>
            <div>
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row">
                            <label for="discount_type"><?php echo esc_html__('Discount type', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <select id="discount_type" name="discount_type" class="wc-enhanced-select">
                                <?php foreach (wc_get_coupon_types() as $type => $label) : ?>
                                    <option value="<?php echo esc_attr($type); ?>"><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row">
                            <label for="coupon_amount"><?php echo esc_html__('Coupon amount', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="text" id="coupon_amount" name="coupon_amount" class="wc_input_price regular-text" required />
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row">
                            <label for="expiry_date"><?php echo esc_html__('Expiry date', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="text" id="expiry_date" name="expiry_date" class="unlockafe-datepicker regular-text" placeholder="YYYY-MM-DD" />
                        </td>
                    </tr>
                </table>
            </div>

            <!-- Code Format -->
            <h3><?php echo esc_html__('Code Format', 'unlock-addons-for-elementor'); ?></h3>
            <div>
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row">
                            <label for="prefix"><?php echo esc_html__('Prefix', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="text" id="prefix" name="prefix" class="regular-text" />
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row">
                            <label for="suffix"><?php echo esc_html__('Suffix', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="text" id="suffix" name="suffix" class="regular-text" />
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row">
                            <label for="code_length"><?php echo esc_html__('Code Length', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="number" id="code_length" name="code_length" class="regular-text" value="8" min="4" max="20"/>
                            <p class="description"><?php echo esc_html__('Length of the random part of the code.', 'unlock-addons-for-elementor'); ?></p>
                        </td>
                    </tr>
                </table>
            </div>

             <!-- Email Settings -->
            <h3><?php echo esc_html__('Email Recipients (Optional)', 'unlock-addons-for-elementor'); ?></h3>
            <div>
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row">
                            <label for="recipients"><?php echo esc_html__('Email Addresses', 'unlock-addons-for-elementor'); ?></label>
                        </th>
                        <td>
                            <textarea id="recipients" name="recipients" class="large-text" rows="5" placeholder="Enter one email address per line"></textarea>
                            <p class="description"><?php echo esc_html__('If provided, each generated coupon will be sent to one recipient. The number of emails should match the number of coupons.', 'unlock-addons-for-elementor'); ?></p>
                        </td>
                    </tr>
                </table>
            </div>

        </div>

        <?php submit_button(__('Generate Coupons', 'unlock-addons-for-elementor'), 'primary', 'unlockafe_generate_coupons'); ?>
    </form>

    <!-- CSV Tools -->
    <div class="unlockafe-csv-tools">
        <h2><?php echo esc_html__('CSV Import / Export', 'unlock-addons-for-elementor'); ?></h2>
        <p><?php echo esc_html__('Import or export coupons using a CSV file.', 'unlock-addons-for-elementor'); ?></p>
        <a href="<?php echo esc_url(wp_nonce_url(admin_url('admin.php?page=unlockafe-coupon-bulk-tools&action=export_coupons'), 'export_coupons_nonce')); ?>" class="button-secondary"><?php echo esc_html__('Export All Coupons to CSV', 'unlock-addons-for-elementor'); ?></a>
        
        <form method="post" enctype="multipart/form-data" style="margin-top: 1rem;">
             <?php wp_nonce_field('unlockafe_import_csv_action', 'unlockafe_import_csv_nonce'); ?>
            <label for="coupon_csv_file"><?php echo esc_html__('Select CSV file to import:', 'unlock-addons-for-elementor'); ?></label>
            <input type="file" id="coupon_csv_file" name="coupon_csv_file" accept=".csv" />
            <?php submit_button(__('Import Coupons from CSV', 'unlock-addons-for-elementor'), 'secondary', 'unlockafe_import_coupons'); ?>
        </form>
    </div>

</div>
