<?php

/**
 * Pages Tab for Design Settings
 */

namespace MovieEngine\Admin\Design\Tabs;

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

class PagesTab {

    public static function render($options, $standalone = true) {
        $dashboard_page = isset($options['dashboard_page']) ? $options['dashboard_page'] : '';
        $pricing_page   = isset($options['pricing_page']) ? $options['pricing_page'] : '';
        $browse_page    = isset($options['browse_page']) ? $options['browse_page'] : '';
        $tv_series_page = isset($options['tv_series_page']) ? $options['tv_series_page'] : '';
        $movie_archive_page = isset($options['movie_archive_page']) ? $options['movie_archive_page'] : '';
        $series_archive_page = isset($options['series_archive_page']) ? $options['series_archive_page'] : '';
?>
        <?php if ($standalone) : ?>
            <input type="hidden" name="movie_engine_design_settings[active_sub_tab]" value="pages">
        <?php endif; ?>



        <div class="movie-engine-settings-modern">
            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Official Movie Archive', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[movie_archive_page]',
                        'selected'          => absint($movie_archive_page),
                        'show_option_none'  => esc_html__('— Default Archive (Auto) —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('Select a page to act as your official Movies Archive. If selected, the default /movies/ URL will redirect to this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Official TV Series Archive', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[series_archive_page]',
                        'selected'          => absint($series_archive_page),
                        'show_option_none'  => esc_html__('— Default Archive (Auto) —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('Select a page for your TV Series archive. If selected, the default /tv-series/ URL will redirect to this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Official Person Archive', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[person_archive_page]',
                        'selected'          => absint(isset($options['person_archive_page']) ? $options['person_archive_page'] : ''),
                        'show_option_none'  => esc_html__('— Default Archive (Auto) —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('Select a page for your Person / Cast archive. If selected, the default /person/ URL will redirect to this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('User Dashboard Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[dashboard_page]',
                        'selected'          => absint($dashboard_page),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('This is the dashboard page that lets your users login and interact from the frontend. The [movie_engine_dashboard] shortcode must be on this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>



            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Browse Content Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[browse_page]',
                        'selected'          => absint($browse_page),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('The main library page where users can search and filter movies. The [movie_engine_search] shortcode must be on this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('TV Series Library Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[tv_series_page]',
                        'selected'          => absint($tv_series_page),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('Dedicated page for browsing TV shows and serials. The [movie_engine_search post_type="movie_engine_series"] shortcode must be on this page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Search Results Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[search_page]',
                        'selected'          => absint(isset($options['search_page']) ? $options['search_page'] : ''),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('The page where users are redirected after performing a search from the header or widgets. Should contain [movie_engine_search].', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Custom Login Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[login_page]',
                        'selected'          => absint(isset($options['login_page']) ? $options['login_page'] : ''),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('The branded login page for your users. Should contain [movie_engine_login].', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Custom Register Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control me-mb-3">
                    <?php
                    wp_dropdown_pages([
                        'name'              => 'movie_engine_design_settings[register_page]',
                        'selected'          => absint(isset($options['register_page']) ? $options['register_page'] : ''),
                        'show_option_none'  => esc_html__('— Select Page —', 'cine-movie-engine'),
                        'option_none_value' => '',
                        'class'             => 'movie-engine-select-modern'
                    ]);
                    ?>
                    <p class="description"><?php esc_html_e('The branded registration page. Should contain [movie_engine_login action="register"].', 'cine-movie-engine'); ?></p>
                </div>
            </div>
            <?php do_action('movie_engine_design_page_settings_after', $options); ?>
        </div>

        <div class="movie-engine-modern-footer-info me-page-setup-info">
            <span class="fa-solid fa-circle-info"></span>
            <p><?php esc_html_e('MovieEngine automatically creates these pages on activation. You only need to change them here if you want to use custom pages.', 'cine-movie-engine'); ?></p>
        </div>
<?php
    }
}
