<?php
// Prevent direct access
if (! defined('ABSPATH')) {
  exit;
}
?>
<div class="boostify-dashboard-wrap">
    <div class="boostify-header">
        <div class="logo">
            <span class="logo-icon"><img src="./assets/img/logo.svg" alt="Boostify Logo" /></span>
        </div>
    </div>
    <div class="schedule-settings">
        <h2 class="tab-heading">Schedule Settings</h2>
        
        <?php if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true'): ?>
        <div class="notice notice-success is-dismissible">
            <p>Schedule settings have been saved successfully!</p>
        </div>
        <?php endif; ?>
        
        <div class="form-settings">
            <form action="" method="post" id="boostify-schedule-settings-form">
                <input type="hidden" name="boostify_dashboard_nonce" value="<?php echo esc_attr(wp_create_nonce('boostify_dashboard_nonce')); ?>" />
                <div class="form-row">
                    <div class="form-group half-column">
                        <label for="no-of-posts">No Of Posts</label>
                        <input type="number" id="no-of-posts" name="no-of-posts" placeholder="" value="<?php echo esc_attr($setting['quantity'] ?? ''); ?>" />
                    </div>
                    Per
                    <div class="form-group selectbox half-column">
                        <label for="per-post"></label><br>
                        <div class="select-wrapper">
                            <select name="per-post" id="per-post">
                                <option value="Day" <?php echo (isset($setting['duration']) && $setting['duration'] == 'Day') ? 'selected' : ''; ?>>Day</option>
                                <option value="Week" <?php echo (isset($setting['duration']) && $setting['duration'] == 'Week') ? 'selected' : ''; ?>>Week</option>
                                <option value="Month" <?php echo (isset($setting['duration']) && $setting['duration'] == 'Month') ? 'selected' : ''; ?>>Month</option>
                                <option value="Year" <?php echo (isset($setting['duration']) && $setting['duration'] == 'Year') ? 'selected' : ''; ?>>Year</option>
                            </select>
                            <svg width="11" height="7" viewBox="0 0 11 7" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M5.14 6.55L0 1.41L1.42 0L5.14 3.72L8.86 0L10.28 1.41L5.14 6.55Z" fill="white" />
                            </svg>
                        </div>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column">
                        <label for="topics">Topics</label>
                        <input type="text" id="topics" name="topics" placeholder="sports,Nfl" value="<?php echo esc_attr($setting['topics'] ?? ''); ?>" />
                        <p class="text-note">Note : Enter (comma separated) Topics</p>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column">
                        <label for="keywords">Keywords</label>
                        <input type="text" id="keywords" name="keywords" placeholder="FashionWeek,Couture" value="<?php echo esc_attr($setting['keywords'] ?? ''); ?>" />
                        <p class="text-note">Note : Enter (comma separated) Topics</p>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column form-checkbox">
                        <label for="trust-ai">Trust AI</label>
                        <div class="form-checkbox-content">
                            <label style="position:relative;">
                                <input type="checkbox" id="trust-ai" name="trust-ai" <?php echo !empty($setting['trust_ai']) ? 'checked' : ''; ?> />
                                <span></span>
                            </label>
                            Note : If checked, posts will be published automatically without admin approval.
                        </div>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column form-checkbox">
                        <label for="include-image">Include Image</label>
                        <div class="form-checkbox-content">
                            <label style="position:relative;">
                                <input type="checkbox" id="include-image" name="include-image" <?php echo !empty($setting['image']) ? 'checked' : ''; ?> />
                                <span></span>
                            </label>
                            Note : Add image in blog post
                        </div>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column selectbox">
                        <label for="image-position">Image Position</label>
                        <div class="select-wrapper">
                            <select name="image-position" id="image-position">
                                <option value="">Select</option>
                                <option value="top" <?php echo (isset($setting['image_position']) && $setting['image_position'] == 'top') ? 'selected' : ''; ?>>Top</option>
                                <option value="middle" <?php echo (isset($setting['image_position']) && $setting['image_position'] == 'middle') ? 'selected' : ''; ?>>Middle</option>
                                <option value="below" <?php echo (isset($setting['image_position']) && $setting['image_position'] == 'below') ? 'selected' : ''; ?>>Below</option>
                            </select>
                            <svg width="11" height="7" viewBox="0 0 11 7" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M5.14 6.55L0 1.41L1.42 0L5.14 3.72L8.86 0L10.28 1.41L5.14 6.55Z" fill="white" />
                            </svg>
                        </div>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group full-column submit-btn">
                        <input class="btn-styles" type="submit" value="Save Changes" name="save-changes" />
                        <button type="button" class="btn-styles" id="boostify-manual-run-btn" style="display:none;margin-left:10px;">Run Manually</button>
                    </div>
                </div>
            </form>
        </div>

        <!-- Success Modal -->
        <div class="modal modal-success" style="display:none;">
            <div class="modal-content">
                <button class="modal-close close-icon"><img src="./assets/img/close-icon.svg" alt="Close" /></button>
                <span class="modal-icon"><img src="./assets/img/modal-check-icon.svg" alt="Success" /></span>
                <h2 class="modal-title">Successfully</h2>
                <p class="modal-description">Schedule Settings has been saved Successfully</p>
                <button class="btn-styles modal-close">Ok</button>
            </div>
        </div>
        <!-- Error Modal -->
        <div class="modal modal-manage" style="display:none;">
            <div class="modal-content">
                <button class="modal-close close-icon"><img src="./assets/img/close-icon.svg" alt="Close" /></button>
                <span class="modal-icon"><img src="./assets/img/modal-manage-icon.svg" alt="Manage Icon" /></span>
                <h2 class="modal-title">Manage your schedule <br>right now</h2>
                <p class="modal-description">Our AI systems will create Post automatically for you </p>
                <button class="btn-styles modal-close" id="modal-manual-run-accept">Ok Lets go</button>
            </div>
        </div>
    </div>
</div>