<?php

if (!defined('ABSPATH')) { exit; }
?>
<div class="aieo-dmm-section">
    <h2><?php esc_html_e('Waitlist (back-in-stock notifications)', 'ai-eshop-optimizer'); ?></h2>
    <p class="description">
        <?php esc_html_e('Out-of-stock products show a "Notify me" form. When the product flips back to in-stock, every subscriber gets an email — once.', 'ai-eshop-optimizer'); ?>
    </p>

    <form id="aieo-dmm-waitlist-form" class="aieo-dmm-form">

        <div class="aieo-dmm-card">
            <h3><?php esc_html_e('Front-end gate', 'ai-eshop-optimizer'); ?></h3>
            <p class="description" style="margin:0 0 8px;">
                <?php esc_html_e('Off by default — keep PPE\'s wait-list module authoritative until you\'re ready to switch. When ON, AIEO renders the form on every out-of-stock product page and PPE\'s output should be disabled to avoid duplicates.', 'ai-eshop-optimizer'); ?>
            </p>
            <table class="form-table">
                <tr>
                    <th><?php esc_html_e('Render front-end form', 'ai-eshop-optimizer'); ?></th>
                    <td>
                        <label class="aieo-dmm-choice">
                            <input type="checkbox" name="frontend_enabled" value="1" <?php checked($settings['frontend_enabled'] === 'yes'); ?>>
                            <?php esc_html_e('Render the AIEO waitlist form on out-of-stock products.', 'ai-eshop-optimizer'); ?>
                        </label>
                    </td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Show on backorder products', 'ai-eshop-optimizer'); ?></th>
                    <td>
                        <label class="aieo-dmm-choice">
                            <input type="checkbox" name="display_on_backorders" value="1" <?php checked($settings['display_on_backorders'] === 'yes'); ?>>
                            <?php esc_html_e('Also show the form when stock status is "on backorder".', 'ai-eshop-optimizer'); ?>
                        </label>
                    </td>
                </tr>
            </table>
        </div>

        <div class="aieo-dmm-card">
            <h3><?php esc_html_e('Form text', 'ai-eshop-optimizer'); ?></h3>
            <table class="form-table">
                <tr>
                    <th><?php esc_html_e('Form title', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="form_title" value="<?php echo esc_attr($settings['form_title']); ?>" class="large-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Email field label', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="form_email_label" value="<?php echo esc_attr($settings['form_email_label']); ?>" class="large-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Submit button text', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="form_button_text" value="<?php echo esc_attr($settings['form_button_text']); ?>" class="large-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Success message', 'ai-eshop-optimizer'); ?></th>
                    <td><textarea name="form_success_message" rows="2" class="large-text"><?php echo esc_textarea($settings['form_success_message']); ?></textarea></td>
                </tr>
            </table>
        </div>

        <div class="aieo-dmm-card">
            <h3><?php esc_html_e('Appearance — card + button', 'ai-eshop-optimizer'); ?></h3>
            <p class="description" style="margin:0 0 8px;">
                <?php esc_html_e('Style the form card on out-of-stock product pages. Defaults match the original neutral grey look.', 'ai-eshop-optimizer'); ?>
            </p>
            <table class="form-table">
                <tr>
                    <th><?php esc_html_e('Title size (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="8" max="48" name="title_size" value="<?php echo (int) ($settings['title_size'] ?? 16); ?>" class="small-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Body text size (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="8" max="32" name="text_size" value="<?php echo (int) ($settings['text_size'] ?? 14); ?>" class="small-text">
                        <p class="description"><?php esc_html_e('Drives label, email field, and submit-button text size.', 'ai-eshop-optimizer'); ?></p>
                    </td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Background color', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="bg_color" value="<?php echo esc_attr((string) ($settings['bg_color'] ?? '#f8f9fa')); ?>" class="aieo-dmm-waitlist-color" data-default-color="#f8f9fa"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border color', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="border_color" value="<?php echo esc_attr((string) ($settings['border_color'] ?? '#e9ecef')); ?>" class="aieo-dmm-waitlist-color" data-default-color="#e9ecef"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border thickness (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="0" max="10" name="border_width" value="<?php echo (int) ($settings['border_width'] ?? 1); ?>" class="small-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border radius (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="0" max="40" name="border_radius" value="<?php echo (int) ($settings['border_radius'] ?? 8); ?>" class="small-text"></td>
                </tr>
                <tr>
                    <th colspan="2" style="padding-top:14px;color:#374151;"><?php esc_html_e('Submit button', 'ai-eshop-optimizer'); ?></th>
                </tr>
                <tr>
                    <th><?php esc_html_e('Background color', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="btn_bg_color" value="<?php echo esc_attr((string) ($settings['btn_bg_color'] ?? '#0073aa')); ?>" class="aieo-dmm-waitlist-color" data-default-color="#0073aa"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Text color', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="btn_text_color" value="<?php echo esc_attr((string) ($settings['btn_text_color'] ?? '#ffffff')); ?>" class="aieo-dmm-waitlist-color" data-default-color="#ffffff"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border color', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="btn_border_color" value="<?php echo esc_attr((string) ($settings['btn_border_color'] ?? '#0073aa')); ?>" class="aieo-dmm-waitlist-color" data-default-color="#0073aa"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border thickness (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="0" max="10" name="btn_border_width" value="<?php echo (int) ($settings['btn_border_width'] ?? 0); ?>" class="small-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Border radius (px)', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="number" min="0" max="40" name="btn_border_radius" value="<?php echo (int) ($settings['btn_border_radius'] ?? 4); ?>" class="small-text"></td>
                </tr>
            </table>
        </div>

        <div class="aieo-dmm-card">
            <h3><?php esc_html_e('Restock notification email', 'ai-eshop-optimizer'); ?></h3>
            <p class="description" style="margin:0 0 8px;">
                <?php
                printf(
                    
                    esc_html__('Use %1$s for the product name and %2$s for the product URL.', 'ai-eshop-optimizer'),
                    '<code>{product_name}</code>',
                    '<code>{product_url}</code>'
                );
                ?>
            </p>
            <table class="form-table">
                <tr>
                    <th><?php esc_html_e('Subject', 'ai-eshop-optimizer'); ?></th>
                    <td><input type="text" name="email_subject" value="<?php echo esc_attr($settings['email_subject']); ?>" class="large-text"></td>
                </tr>
                <tr>
                    <th><?php esc_html_e('Body', 'ai-eshop-optimizer'); ?></th>
                    <td><textarea name="email_message" rows="5" class="large-text"><?php echo esc_textarea($settings['email_message']); ?></textarea></td>
                </tr>
            </table>
        </div>

        <p class="submit">
            <button type="submit" class="button button-primary aieo-dmm-btn-fixed" data-action="aieo_dmm_waitlist_save">
                <?php esc_html_e('Save settings', 'ai-eshop-optimizer'); ?>
            </button>
        </p>
    </form>
</div>
