<?php

namespace MovieEngine\Admin\General;

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

class GeneralSettings {

    public static function render() {
        settings_fields('movie_engine_general');
        $options = get_option('movie_engine_general_settings', []);
?>
        <input type="hidden" name="movie_engine_general_settings[active_sub_tab]" id="movie-engine-active-sub-tab" value="general">
        <div class="movie-engine-settings-section">
            <div class="movie-engine-section-header">
                <h2><?php esc_html_e('General Settings', 'cine-movie-engine'); ?></h2>
                <p class="description"><?php esc_html_e('Configure basic plugin settings', 'cine-movie-engine'); ?></p>
            </div>

            <div class="movie-engine-card-grid">
                <?php
                if (has_action('movie_engine_render_review_settings')) {
                    do_action('movie_engine_render_review_settings', $options);
                } else {
                ?>
                    <div class="movie-engine-card">
                        <div class="movie-engine-card-header">
                            <h3>
                                <span class="dashicons dashicons-admin-comments"></span>
                                <?php esc_html_e('Review & Feedback', 'cine-movie-engine'); ?>
                                <span class="me-pro-badge"><?php esc_html_e('Pro', 'cine-movie-engine'); ?></span>
                            </h3>
                        </div>
                        <div class="movie-engine-card-body">
                            <div class="me-pro-notice-box">
                                <span class="dashicons dashicons-lock"></span>
                                <div class="me-pro-notice-message">
                                    <strong><?php esc_html_e('Review & Feedback', 'cine-movie-engine'); ?></strong>
                                    <p><?php esc_html_e('This is a PRO feature.', 'cine-movie-engine'); ?></p>
                                </div>
                                <a href="<?php echo esc_url(\MovieEngine\Admin\Upgrade::get_pro_url('pricing')); ?>" target="_blank" class="button button-primary me-pro-notice-btn">
                                    <?php esc_html_e('Learn More', 'cine-movie-engine'); ?>
                                </a>
                            </div>

                            <div style="opacity: 0.6; pointer-events: none; margin-top: 15px;">
                                <div class="movie-engine-form-group">
                                    <label class="movie-engine-checkbox-label">
                                        <input type="checkbox" disabled checked>
                                        <span><?php esc_html_e('Enable Review Editing', 'cine-movie-engine'); ?></span>
                                    </label>
                                    <p class="movie-engine-help-text"><?php esc_html_e('Allow users to edit their own reviews', 'cine-movie-engine'); ?></p>
                                </div>

                                <div class="movie-engine-form-group">
                                    <label><?php esc_html_e('Review Editing Time Limit', 'cine-movie-engine'); ?></label>
                                    <select class="movie-engine-select" disabled>
                                        <option><?php esc_html_e('Unlimited', 'cine-movie-engine'); ?></option>
                                    </select>
                                    <p class="movie-engine-help-text"><?php esc_html_e('How long users can edit their reviews after posting.', 'cine-movie-engine'); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php } ?>


                <div class="movie-engine-card">
                    <div class="movie-engine-card-header">
                        <h3><span class="dashicons dashicons-search"></span> <?php esc_html_e('SEO Settings', 'cine-movie-engine'); ?></h3>
                    </div>
                    <div class="movie-engine-card-body">
                        <div class="movie-engine-form-group">
                            <label class="movie-engine-checkbox-label">
                                <input type="hidden" name="movie_engine_general_settings[movie_engine_enable_schema]" value="0">
                                <input type="checkbox"
                                    name="movie_engine_general_settings[movie_engine_enable_schema]"
                                    value="1"
                                    <?php checked($options['movie_engine_enable_schema'] ?? ($options['enable_schema'] ?? 1), 1); ?>>
                                <span><?php esc_html_e('Enable Schema.org Markup', 'cine-movie-engine'); ?></span>
                            </label>
                            <p class="movie-engine-help-text"><?php esc_html_e('Add structured data for better SEO', 'cine-movie-engine'); ?></p>
                        </div>

                        <div class="movie-engine-form-group">
                            <label class="movie-engine-checkbox-label">
                                <input type="hidden" name="movie_engine_general_settings[movie_engine_enable_og_tags]" value="0">
                                <input type="checkbox"
                                    name="movie_engine_general_settings[movie_engine_enable_og_tags]"
                                    value="1"
                                    <?php checked($options['movie_engine_enable_og_tags'] ?? ($options['enable_og_tags'] ?? 1), 1); ?>>
                                <span><?php esc_html_e('Enable Open Graph Tags', 'cine-movie-engine'); ?></span>
                            </label>
                            <p class="movie-engine-help-text"><?php esc_html_e('Better social media sharing', 'cine-movie-engine'); ?></p>
                        </div>
                    </div>
                </div>

                <div class="movie-engine-card">
                    <div class="movie-engine-card-header">
                        <h3><span class="dashicons dashicons-performance"></span> <?php esc_html_e('Maintenance & Performance', 'cine-movie-engine'); ?></h3>
                    </div>
                    <div class="movie-engine-card-body">
                        <div class="movie-engine-form-group">
                            <label class="movie-engine-checkbox-label">
                                <input type="hidden" name="movie_engine_general_settings[movie_engine_enable_cache]" value="0">
                                <input type="checkbox"
                                    id="movie_engine_enable_cache"
                                    name="movie_engine_general_settings[movie_engine_enable_cache]"
                                    value="1"
                                    <?php checked($options['movie_engine_enable_cache'] ?? 1, 1); ?>>
                                <span><?php esc_html_e('Enable Cache System', 'cine-movie-engine'); ?></span>
                            </label>
                            <p class="movie-engine-help-text"><?php esc_html_e('Speed up your site by caching API responses and design assets.', 'cine-movie-engine'); ?></p>
                        </div>

                        <div class="movie-engine-form-group">
                            <label><?php esc_html_e('Cache Management', 'cine-movie-engine'); ?></label>
                            <p class="movie-engine-help-text me-mb-2"><?php esc_html_e('Clear all cached data including CSS assets and temporary database transients.', 'cine-movie-engine'); ?></p>
                            <button type="button" id="movie-engine-purge-cache-btn" class="me-btn-primary me-py-3 me-px-3">
                                <span class="fa-solid fa-trash"></span>
                                <?php esc_html_e('Purge All Cache', 'cine-movie-engine'); ?>
                            </button>
                            <input type="hidden" id="movie-engine-purge-cache-nonce" value="<?php echo esc_attr(wp_create_nonce('movie_engine_purge_cache')); ?>">
                        </div>
                    </div>
                </div>
            </div>

            <div class="movie-engine-form-actions">
                <?php submit_button(__('Save Changes', 'cine-movie-engine'), 'primary me-btn-primary', 'submit', false); ?>
            </div>
        </div>
<?php
    }
}
