<?php

if (!defined('ABSPATH')) { exit; }
?>
<div class="aieo-dmm-section">
    <h2><?php esc_html_e('Free shipping settings', 'ai-eshop-optimizer'); ?></h2>
    <p class="description">
        <?php esc_html_e('The frontend progress bar lives in om-free-shipping. These settings are kept in sync so the existing plugin keeps working. The exclusion list below is enforced by DMM directly (removes free shipping rates when any excluded product is in the cart).', 'ai-eshop-optimizer'); ?>
    </p>

    <form id="aieo-dmm-free-shipping-form" class="aieo-dmm-form">
        <input type="hidden" name="form_section" value="eligibility">
        <table class="form-table">
            <tr>
                <th><?php esc_html_e('Enabled', 'ai-eshop-optimizer'); ?></th>
                <td><input type="checkbox" name="enabled" value="1" <?php checked($settings['enabled'] === 'yes'); ?>></td>
            </tr>
            <tr>
                <th><?php esc_html_e('Threshold', 'ai-eshop-optimizer'); ?></th>
                <td><input type="number" step="0.01" min="0" name="free_shipping_threshold" value="<?php echo esc_attr((string) $settings['free_shipping_threshold']); ?>"></td>
            </tr>
            <tr>
                <th><?php esc_html_e('Include tax', 'ai-eshop-optimizer'); ?></th>
                <td><input type="checkbox" name="include_tax" value="1" <?php checked($settings['include_tax'] === 'yes'); ?>></td>
            </tr>
            <tr>
                <th><?php esc_html_e('Default country (ISO)', 'ai-eshop-optimizer'); ?></th>
                <td><input type="text" name="default_country" value="<?php echo esc_attr((string) $settings['default_country']); ?>" class="small-text"></td>
            </tr>
            <tr>
                <th><?php esc_html_e('Default postcode', 'ai-eshop-optimizer'); ?></th>
                <td><input type="text" name="default_postcode" value="<?php echo esc_attr((string) $settings['default_postcode']); ?>" class="small-text"></td>
            </tr>

            <tr>
                <th colspan="2" style="padding-top:18px;">
                    <h3 style="margin:0;"><?php esc_html_e('Cart weight cap', 'ai-eshop-optimizer'); ?></h3>
                    <p class="description" style="font-weight:400; margin:4px 0 0;">
                        <?php
                        $weight_unit = function_exists('get_option') ? (string) get_option('woocommerce_weight_unit', 'kg') : 'kg';
                        echo esc_html(sprintf(
                            
                            __('Strip free shipping when the total cart weight exceeds the threshold below. Uses WooCommerce\'s configured store weight unit (%s). Set the threshold to 0 to disable this rule.', 'ai-eshop-optimizer'),
                            $weight_unit
                        ));
                        ?>
                    </p>
                </th>
            </tr>
            <tr>
                <th><?php esc_html_e('Enable weight-based exclusion', 'ai-eshop-optimizer'); ?></th>
                <td>
                    <label class="aieo-dmm-choice">
                        <input type="checkbox" name="weight_exclusion_enabled" value="1"
                               <?php checked((isset($settings['weight_exclusion_enabled']) ? $settings['weight_exclusion_enabled'] : 'no') === 'yes'); ?>>
                        <?php esc_html_e('Remove free shipping when total cart weight is over the threshold.', 'ai-eshop-optimizer'); ?>
                    </label>
                </td>
            </tr>
            <tr>
                <th>
                    <?php
                    
                    echo esc_html(sprintf(__('Max cart weight (%s)', 'ai-eshop-optimizer'),
                        function_exists('get_option') ? (string) get_option('woocommerce_weight_unit', 'kg') : 'kg'));
                    ?>
                </th>
                <td>
                    <input type="number" step="0.01" min="0" name="max_cart_weight" value="<?php echo esc_attr((string) (isset($settings['max_cart_weight']) ? $settings['max_cart_weight'] : 0)); ?>" class="small-text">
                </td>
            </tr>
            <tr>
                <th><?php esc_html_e('Weight-cap notice text', 'ai-eshop-optimizer'); ?></th>
                <td>
                    <textarea name="weight_notify_message" rows="2" class="large-text"><?php echo esc_textarea(isset($settings['weight_notify_message']) ? (string) $settings['weight_notify_message'] : ''); ?></textarea>
                    <p class="description"><?php esc_html_e('Shown on the cart and checkout when the total weight has stripped free shipping. Leave blank to suppress the message (the rate is still removed).', 'ai-eshop-optimizer'); ?></p>
                </td>
            </tr>

            <tr>
                <th colspan="2" style="padding-top:18px;">
                    <p class="description" style="font-weight:400; margin:0;">
                        <?php
                        printf(
                            
                            esc_html__('Display settings — messages, where the bar appears, the early-signal notice, and the visual styling — moved to %s.', 'ai-eshop-optimizer'),
                            '<strong>' . esc_html__('Visual Display → Free Shipping Display', 'ai-eshop-optimizer') . '</strong>'
                        );
                        ?>
                    </p>
                </th>
            </tr>
        </table>
        <p class="submit">
            <button type="submit" class="button button-primary" data-action="aieo_dmm_free_shipping_save">
                <?php esc_html_e('Save settings', 'ai-eshop-optimizer'); ?>
            </button>
        </p>
    </form>
</div>

<?php

?>
