<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View template. ?>
<div class="wrap">
    <h1>SandboxPress AI (v2)</h1>
    <p>Powered by Action Scheduler. Tasks are queued and processed securely in the background.</p>

    <?php if ( isset( $_GET['deleted'] ) && 'true' === $_GET['deleted'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash ?>
        <div class="notice notice-success is-dismissible"><p>Successfully deleted dummy data!</p></div>
    <?php endif; ?>

    <div class="sbpai-global-settings" style="background:#fff; padding: 15px; margin-bottom: 20px; border:1px solid #ccd0d4; border-radius:4px;">
        <h3>Global Settings</h3>
        <label for="sbpai-niche"><strong>Niche:</strong></label>
        <select id="sbpai-niche" style="margin-right: 20px;">
            <option value="General">General / Random</option>
            <option value="Real Estate">Real Estate</option>
            <option value="Technology">Technology</option>
            <option value="Fitness">Fitness</option>
            <option value="E-commerce">E-commerce</option>
        </select>

        <label for="sbpai-ai"><strong>Use AI / Structured Content:</strong></label>
        <input type="checkbox" id="sbpai-ai" checked>
    </div>

    <div class="sbpai-scheduler-status" style="background:#f0f0f1; padding:15px; margin-bottom:20px; border-left:4px solid #2271b1; display:none;" id="sbpai-polling-area">
        <strong>Action Scheduler Live Status:</strong> Pending jobs: <span id="sbpai-pending-count" style="font-weight:bold; color:#d63638;">0</span>
    </div>

    <div class="sbpai-generator-cards">
        <div class="sbpai-card">
            <h3>📝 Posts</h3>
            <p>Generates Gutenberg blocks & featured images.</p>
            <input type="number" id="sbpai-posts-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="posts" data-input="sbpai-posts-count">Queue Posts</button>
            <div class="sbpai-progress" id="progress-posts"></div>
        </div>
        <div class="sbpai-card">
            <h3>🏗 Pages</h3>
            <p>Generates hierarchical pages with content.</p>
            <input type="number" id="sbpai-pages-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="pages" data-input="sbpai-pages-count">Queue Pages</button>
            <div class="sbpai-progress" id="progress-pages"></div>
        </div>
        <div class="sbpai-card">
            <h3>👥 Users</h3>
            <p>Generates realistic user accounts with avatars.</p>
            <input type="number" id="sbpai-users-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="users" data-input="sbpai-users-count">Queue Users</button>
            <div class="sbpai-progress" id="progress-users"></div>
        </div>
        <div class="sbpai-card">
            <h3>🛍 Products</h3>
            <p>Generates Simple, Variable, & Grouped WC products.</p>
            <input type="number" id="sbpai-products-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="products" data-input="sbpai-products-count">Queue Products</button>
            <div class="sbpai-progress" id="progress-products"></div>
        </div>
        <div class="sbpai-card">
            <h3>📦 Orders</h3>
            <p>Generates WooCommerce Orders associated with dummy users.</p>
            <input type="number" id="sbpai-orders-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="orders" data-input="sbpai-orders-count">Queue Orders</button>
            <div class="sbpai-progress" id="progress-orders"></div>
        </div>
        <div class="sbpai-card">
            <h3>🏷 Coupons</h3>
            <p>Generates discount coupons with advanced rules.</p>
            <input type="number" id="sbpai-coupons-count" placeholder="Count" max="10000">
            <button class="button button-primary sbpai-generate-btn" data-type="coupons" data-input="sbpai-coupons-count">Queue Coupons</button>
            <div class="sbpai-progress" id="progress-coupons"></div>
        </div>
    </div>

    <hr>
    
    <div class="sbpai-danger-zone">
        <h2>Danger Zone</h2>
        <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" onsubmit="return confirm('Are you sure you want to delete ALL dummy data?');">
            <input type="hidden" name="action" value="sbpai_delete_all">
            <?php wp_nonce_field( 'sbpai_delete_all' ); ?>
            <button class="button button-danger" style="background: #dc3232; color: white; border-color: #dc3232;">⚡ Delete All Dummy Data</button>
        </form>
    </div>
</div>
