<?php
/**
 * CSS Selectors page — Content & Blocked selectors
 *
 * @package    TTSWP
 * @subpackage Mementor_TTS/admin/partials/pages
 */

if (!defined('ABSPATH')) {
    exit;
}

if (!current_user_can('manage_options')) {
    wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'text-to-speech-tts'));
}

$tts_page_title = __('CSS Selectors', 'text-to-speech-tts');
$tts_topbar_actions = '';
$tts_requires_connection = true; // gate page behind SaaS connection

include MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/layout-open.php';
?>
<?php include(MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/navigation.php'); ?>

            <?php
            $content_selectors_string = get_option('mementor_tts_include_selectors', '.post-content, .wp-block-post-content, .page-content');
            $blocked_selectors_string = get_option('mementor_tts_exclude_selectors', '#ad-wrapper, .sidebar, .comments, .advertisement, .mementor-tts-player-container, .mementor-tts-player, .mementor-tts-player-wrapper');
            $truncate_after_string    = get_option('mementor_tts_truncate_after', '');
            ?>
            <form method="post" action="options.php">
                <?php
                // Both selectors share a single options group, so they must
                // submit together. Splitting into two forms cleared the unused
                // field on save.
                settings_fields('mementor_tts_css_selectors_settings');
                do_settings_sections('mementor_tts_css_selectors_settings');
                ?>

                <!-- Content Selectors -->
                <div class="tts-card tts-card-inset">
                    <div class="tts-card-header tts-card-header-inline">
                        <h3 class="tts-card-title"><?php esc_html_e('Content Selectors', 'text-to-speech-tts'); ?></h3>
                        <p class="tts-card-desc"><?php esc_html_e('CSS selectors to target content for speech conversion.', 'text-to-speech-tts'); ?></p>
                    </div>
                    <div class="tts-audio-field">
                        <label class="tts-audio-label" for="mementor_tts_include_selectors"><?php esc_html_e('Include Selectors', 'text-to-speech-tts'); ?></label>
                        <textarea id="mementor_tts_include_selectors" name="mementor_tts_include_selectors" rows="3" placeholder="<?php esc_html_e('Enter selectors separated by commas', 'text-to-speech-tts'); ?>"><?php echo esc_textarea($content_selectors_string); ?></textarea>
                    </div>
                    <p class="tts-content-description"><?php esc_html_e('Default: .post-content, .wp-block-post-content, .page-content', 'text-to-speech-tts'); ?></p>
                </div>

                <!-- Blocked Selectors -->
                <div class="tts-card tts-card-inset">
                    <div class="tts-card-header tts-card-header-inline">
                        <h3 class="tts-card-title"><?php esc_html_e('Blocked Selectors', 'text-to-speech-tts'); ?></h3>
                        <p class="tts-card-desc"><?php esc_html_e('CSS selectors to exclude from speech conversion.', 'text-to-speech-tts'); ?></p>
                    </div>
                    <div class="tts-audio-field">
                        <label class="tts-audio-label" for="mementor_tts_exclude_selectors"><?php esc_html_e('Exclude Selectors', 'text-to-speech-tts'); ?></label>
                        <textarea id="mementor_tts_exclude_selectors" name="mementor_tts_exclude_selectors" rows="3" placeholder="<?php esc_html_e('Enter selectors separated by commas', 'text-to-speech-tts'); ?>"><?php echo esc_textarea($blocked_selectors_string); ?></textarea>
                    </div>
                    <p class="tts-content-description"><?php esc_html_e('Default: #ad-wrapper, .sidebar, .comments, .advertisement', 'text-to-speech-tts'); ?></p>
                </div>

                <!-- Truncate After -->
                <div class="tts-card tts-card-inset">
                    <div class="tts-card-header tts-card-header-inline">
                        <h3 class="tts-card-title"><?php esc_html_e('Truncate After', 'text-to-speech-tts'); ?></h3>
                        <p class="tts-card-desc"><?php esc_html_e('Stop audio generation once a given string appears in the page. Everything after the first match is dropped before narration.', 'text-to-speech-tts'); ?></p>
                    </div>
                    <div class="tts-audio-field">
                        <label class="tts-audio-label" for="mementor_tts_truncate_after"><?php esc_html_e('Cut-off Strings', 'text-to-speech-tts'); ?></label>
                        <textarea id="mementor_tts_truncate_after" name="mementor_tts_truncate_after" rows="3" placeholder="&lt;strong&gt;Footnotes&lt;/strong&gt;"><?php echo esc_textarea($truncate_after_string); ?></textarea>
                    </div>
                    <p class="tts-content-description"><?php esc_html_e('One string per line. Matched against the rendered HTML, case-insensitive. Example: <strong>Footnotes</strong>', 'text-to-speech-tts'); ?></p>
                    <div class="tts-content-submit">
                        <button type="submit" name="submit-selectors" class="tts-btn tts-btn-primary"><?php esc_html_e('Save Selectors', 'text-to-speech-tts'); ?></button>
                    </div>
                </div>
            </form>

<?php include MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/layout-close.php'; ?>
