<?php

if (!defined('ABSPATH')) { exit; }
?>
<div class="aieo-dmm-grid">
    <p>
        <label><?php esc_html_e('Label (internal)', 'ai-eshop-optimizer'); ?></label>
        <input type="text" name="label" class="regular-text">
    </p>
    <p>
        <label><?php esc_html_e('Brands', 'ai-eshop-optimizer'); ?></label>
        <select name="brand_term_ids[]" multiple class="aieo-dmm-brand-select regular-text"></select>
        <span class="description"><?php esc_html_e('Leave empty to accept any brand.', 'ai-eshop-optimizer'); ?></span>
    </p>
    <p>
        <label><?php esc_html_e('Categories', 'ai-eshop-optimizer'); ?></label>
        <select name="category_term_ids[]" multiple class="aieo-dmm-category-select regular-text"></select>
        <span class="description"><?php esc_html_e('Leave empty to accept any category.', 'ai-eshop-optimizer'); ?></span>
    </p>
    <p>
        <label><?php esc_html_e('Needs', 'ai-eshop-optimizer'); ?></label>
        <select name="need_term_ids[]" multiple class="aieo-dmm-need-select regular-text"></select>
        <span class="description"><?php esc_html_e('Leave empty to accept any need.', 'ai-eshop-optimizer'); ?></span>
    </p>
    <p>
        <label><?php esc_html_e('Minimum qualifying subtotal', 'ai-eshop-optimizer'); ?></label>
        <input type="number" name="min_subtotal" step="0.01" min="0" placeholder="0.00">
        <span class="description"><?php esc_html_e('0 = no minimum; any matching product triggers the offer / qualifies the row for inclusion.', 'ai-eshop-optimizer'); ?></span>
    </p>
    <p>
        <label><?php esc_html_e('Combine targeting filters with', 'ai-eshop-optimizer'); ?></label>
        <span class="description" style="display:block;margin:6px 0 4px;">
            <label class="aieo-dmm-choice"><input type="radio" name="rule_operator" value="AND" checked> <strong>AND</strong> — <?php esc_html_e('every set targeting filter must match (brand AND category AND need AND specific-products), and the cart / candidate set totals at least the minimum subtotal', 'ai-eshop-optimizer'); ?></label>
        </span>
        <span class="description" style="display:block;">
            <label class="aieo-dmm-choice"><input type="radio" name="rule_operator" value="OR"> <strong>OR</strong> — <?php esc_html_e('any non-empty targeting filter that hits qualifies the row, OR the whole cart / candidate set reaches the minimum subtotal', 'ai-eshop-optimizer'); ?></label>
        </span>
    </p>
    <p>
        <label><?php esc_html_e('From', 'ai-eshop-optimizer'); ?></label>
        <input type="date" name="date_from">
    </p>
    <p>
        <label><?php esc_html_e('To', 'ai-eshop-optimizer'); ?></label>
        <input type="date" name="date_to">
    </p>
    <p>
        <label class="aieo-dmm-choice" style="margin-top:24px;">
            <input type="checkbox" name="enabled" checked value="1">
            <?php esc_html_e('Enabled', 'ai-eshop-optimizer'); ?>
        </label>
    </p>
</div>

<div style="margin-top:14px;">
    <?php echo AIEO_DMM_Product_Picker::render_field(array(
        'name'     => 'product_ids',
        'mode'     => 'include',
        'label'    => __('Specific products (optional)', 'ai-eshop-optimizer'),
        'help'     => __('Pick simple products, whole variable products, or specific variations. When set, the row qualifies ONLY when the cart / candidate set contains at least one of these (in addition to the brand / category / need filters above). Variations roll up to their parent.', 'ai-eshop-optimizer'),
        'selected' => isset($ts_include_ids) ? $ts_include_ids : array(),
    )); ?>
</div>

<details style="margin:14px 0;">
    <summary style="cursor:pointer;font-weight:600;color:#1f2937;"><?php esc_html_e('Show exclusions ▾', 'ai-eshop-optimizer'); ?></summary>
    <p class="description" style="margin:6px 0 8px;">
        <?php esc_html_e('Negative filters — when the cart / candidate row matches any of these, the row is NOT qualified (overrides the positive targeting above). Leave empty to apply no exclusions.', 'ai-eshop-optimizer'); ?>
    </p>
    <div class="aieo-dmm-grid">
        <p>
            <label><?php esc_html_e('Excluded brands', 'ai-eshop-optimizer'); ?></label>
            <select name="excluded_brand_ids[]" multiple class="aieo-dmm-brand-select regular-text"></select>
        </p>
        <p>
            <label><?php esc_html_e('Excluded categories', 'ai-eshop-optimizer'); ?></label>
            <select name="excluded_category_ids[]" multiple class="aieo-dmm-category-select regular-text"></select>
        </p>
        <p>
            <label><?php esc_html_e('Excluded needs', 'ai-eshop-optimizer'); ?></label>
            <select name="excluded_need_ids[]" multiple class="aieo-dmm-need-select regular-text"></select>
        </p>
    </div>
    <div style="margin-top:10px;">
        <?php echo AIEO_DMM_Product_Picker::render_field(array(
            'name'     => 'excluded_product_ids',
            'mode'     => 'exclude',
            'label'    => __('Excluded specific products', 'ai-eshop-optimizer'),
            'help'     => __('When the cart / candidate row matches ANY of these, it is NOT qualified (overrides the positive targeting above). Variations roll up to their parent.', 'ai-eshop-optimizer'),
            'selected' => isset($ts_exclude_ids) ? $ts_exclude_ids : array(),
        )); ?>
    </div>
</details>
