<?php

namespace MovieEngine\Admin\Design;

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

class DesignSettings {

    public static function render($active_tab_slug = 'design_general') {
        settings_fields('movie_engine_design');
        $options = get_option('movie_engine_design_settings', []);
        $current_sub_tab = str_replace('design_', '', $active_tab_slug);
        if ($current_sub_tab === 'design') {
            $current_sub_tab = 'general';
        }
?>
        <input type="hidden" name="movie_engine_design_settings[active_sub_tab]" id="movie-engine-active-sub-tab" value="<?php echo esc_attr($current_sub_tab); ?>">
        <div class="movie-engine-settings-section">
            <div class="movie-engine-section-header">
                <h2><?php esc_html_e('Appearance Settings', 'cine-movie-engine'); ?></h2>
                <p class="description"><?php esc_html_e('Customize the visual appearance and layout of your Movie Engine system.', 'cine-movie-engine'); ?></p>
            </div>

            <div class="movie-engine-sub-tabs">
                <a href="#general" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'general' ? 'active' : ''; ?>"><?php esc_html_e('General', 'cine-movie-engine'); ?></a>
                <a href="#pages" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'pages' ? 'active' : ''; ?>"><?php esc_html_e('Page Settings', 'cine-movie-engine'); ?></a>
                <a href="#pagination" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'pagination' ? 'active' : ''; ?>"><?php esc_html_e('Pagination', 'cine-movie-engine'); ?></a>
                <a href="#movie" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'movie' ? 'active' : ''; ?>"><?php esc_html_e('Single Movie', 'cine-movie-engine'); ?></a>
                <a href="#series" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'series' ? 'active' : ''; ?>"><?php esc_html_e('Single Series', 'cine-movie-engine'); ?></a>
                <a href="#episode" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'episode' ? 'active' : ''; ?>"><?php esc_html_e('Single Episode', 'cine-movie-engine'); ?></a>
                <a href="#archive" class="movie-engine-sub-tab <?php echo $current_sub_tab === 'archive' ? 'active' : ''; ?>"><?php esc_html_e('Archive & Listings', 'cine-movie-engine'); ?></a>
            </div>

            <div class="movie-engine-sub-tab-content">

                <div id="general" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'general' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/GeneralTab.php';
                    Tabs\GeneralTab::render($options, false);
                    ?>
                </div>
                <div id="pages" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'pages' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/PagesTab.php';
                    Tabs\PagesTab::render($options, false);
                    ?>
                </div>

                <div id="pagination" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'pagination' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/PaginationTab.php';
                    Tabs\PaginationTab::render($options, false);
                    ?>
                </div>
                <div id="movie" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'movie' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/MovieTab.php';
                    Tabs\MovieTab::render($options, false);
                    ?>
                </div>

                <div id="series" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'series' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/SeriesTab.php';
                    Tabs\SeriesTab::render($options, false);
                    ?>
                </div>

                <div id="episode" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'episode' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/EpisodeTab.php';
                    Tabs\EpisodeTab::render($options, false);
                    ?>
                </div>

                <div id="archive" class="movie-engine-sub-panel <?php echo esc_attr($current_sub_tab === 'archive' ? 'active' : ''); ?>">
                    <?php
                    require_once MOVIE_ENGINE_PATH . 'includes/Admin/Design/Tabs/ArchiveTab.php';
                    Tabs\ArchiveTab::render($options, false);
                    ?>
                </div>

            </div>

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

                <button type="button" id="movie-engine-dynamic-reset-btn" class="movie-engine-reset-section-btn <?php echo esc_attr($current_sub_tab === 'pages' ? 'me-hide' : ''); ?>" data-tab="design_<?php echo esc_attr($current_sub_tab); ?>">
                    <span class="dashicons dashicons-undo"></span>
                    <?php esc_html_e('Reset Section', 'cine-movie-engine'); ?>
                </button>
            </div>
        </div>

<?php
    }
}
