<?php
/**
 * Content settings page
 *
 * @link       https://mementor.no
 * @since      1.0.0
 *
 * @package    TTSWP
 * @subpackage Mementor_TTS/admin/partials/pages
 */

// If this file is called directly, abort.
if (!defined('ABSPATH')) {
    exit;
}

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

// Check if API key is set
$has_api_key = !empty(get_option('mementor_tts_api_key'));

// Check if user has a paid plan via SaaS
$is_pro_active = ttswp_has_paid_plan();
$has_pro_license = $is_pro_active;

$tts_page_title = __('Content Control Settings', 'text-to-speech-tts');
$tts_topbar_actions = '<button type="submit" form="content-settings-form" class="tts-btn tts-btn-primary">' . esc_html__('Save content settings', 'text-to-speech-tts') . '</button>';
$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'); ?>

        <!-- Post Types + Auto Generation — side by side -->
        <div class="tts-content-grid-row">
            <!-- Post Types -->
            <div class="tts-card tts-card-inset tts-content-grid-card">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title"><?php esc_html_e('Post Types', 'text-to-speech-tts'); ?></h3>
                    <p class="tts-card-desc"><?php esc_html_e('Select which post types should have text-to-speech enabled.', 'text-to-speech-tts'); ?></p>
                </div>
                <form method="post" action="options.php" class="post-types-form">
                    <?php
                    settings_fields('mementor_tts_post_types_settings');
                    do_settings_sections('mementor_tts_post_types_settings');
                    ?>
                    <div class="tts-type-selector" tabindex="0">
                        <div class="tts-type-tags">
                            <?php
                            $selected_types = get_option('mementor_tts_post_types', array('post'));

                            foreach ($selected_types as $type) {
                                $post_type_obj = get_post_type_object($type);
                                if ($post_type_obj) {
                                    echo sprintf(
                                        '<div class="tts-type-tag" data-type="%s">
                                            %s
                                            <span class="remove-type dashicons dashicons-no-alt"></span>
                                            <input type="hidden" name="mementor_tts_post_types[]" value="%s">
                                        </div>',
                                        esc_attr($type),
                                        esc_html($post_type_obj->labels->singular_name),
                                        esc_attr($type)
                                    );
                                }
                            }
                            ?>
                        </div>
                        <span class="tts-type-dropdown-icon dashicons dashicons-arrow-down-alt2"></span>
                        <div class="tts-type-dropdown">
                            <?php
                            $post_types = get_post_types(['public' => true], 'objects');
                            unset($post_types['attachment']);

                            foreach ($post_types as $type => $post_type) {
                                if (!in_array($type, $selected_types)) {
                                    echo sprintf(
                                        '<div class="tts-type-dropdown-item" data-type="%s">%s</div>',
                                        esc_attr($type),
                                        esc_html($post_type->labels->singular_name)
                                    );
                                }
                            }
                            ?>
                        </div>
                    </div>
                    <p class="tts-card-desc"><?php esc_html_e('Click to see available post types.', 'text-to-speech-tts'); ?></p>
                    <div class="tts-info-row" id="mementor-tts-product-hint">
                        <span class="tts-info-icon">&#8505;</span>
                        <span class="tts-info-text">
                        <?php
                        printf(
                            /* translators: %s: link to Product Audio Settings section */
                            esc_html__('Product post type selected — configure what product data to include in audio in the %s section below.', 'text-to-speech-tts'),
                            '<a href="#mementor-tts-product-audio-section" class="tts-info-link">' . esc_html__('Product Audio Settings', 'text-to-speech-tts') . '</a>'
                        );
                        ?>
                        </span>
                    </div>
                    <div class="tts-content-submit">
                        <button type="submit" name="submit-post-types" class="tts-btn tts-btn-primary"><?php esc_html_e('Save Post Types', 'text-to-speech-tts'); ?></button>
                    </div>
                </form>
            </div>

            <!-- Automatic Audio Generation -->
            <div class="tts-card tts-card-inset tts-content-grid-card">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title">
                        <?php esc_html_e('Automatic Audio Generation', 'text-to-speech-tts'); ?>
                        <?php if (!$has_pro_license): ?>
                            <span class="tts-pro-badge"><?php esc_html_e('PRO', 'text-to-speech-tts'); ?></span>
                        <?php endif; ?>
                    </h3>
                    <p class="tts-card-desc"><?php esc_html_e('Generate audio automatically.', 'text-to-speech-tts'); ?></p>
                </div>
                <form method="post" action="options.php">
                    <?php
                    settings_fields('mementor_tts_auto_generation_settings');
                    do_settings_sections('mementor_tts_auto_generation_settings');
                    ?>
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Auto-generate on publish', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox"
                                   id="mementor_tts_auto_generate_on_publish"
                                   name="mementor_tts_auto_generate_on_publish"
                                   value="1"
                                   <?php checked(1, get_option('mementor_tts_auto_generate_on_publish', 0)); ?>
                                   <?php echo (!$has_pro_license) ? 'disabled' : ''; ?>>
                            <label for="mementor_tts_auto_generate_on_publish">
                                <span class="slider"></span>
                            </label>
                        </div>
                    </div>
                    <p class="tts-content-description">
                        <strong><?php esc_html_e('Important:', 'text-to-speech-tts'); ?></strong>
                        <?php esc_html_e('Only enable after thoroughly testing your settings. This will consume API credits for each published post.', 'text-to-speech-tts'); ?>
                    </p>
                    <?php if (!$has_pro_license): ?>
                        <div class="tts-content-pro-notice">
                            <span><?php esc_html_e('This feature requires an active PRO license.', 'text-to-speech-tts'); ?></span>
                            <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-upgrade')); ?>" class="tts-btn tts-btn-primary">
                                <?php esc_html_e('Upgrade to PRO', 'text-to-speech-tts'); ?>
                            </a>
                        </div>
                    <?php else: ?>
                        <div class="tts-content-submit">
                            <button type="submit" name="submit-auto-generation" class="tts-btn tts-btn-primary"><?php esc_html_e('Save Settings', 'text-to-speech-tts'); ?></button>
                        </div>
                    <?php endif; ?>
                </form>
            </div>
        </div>

        <!-- Content Settings -->
        <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 Settings', 'text-to-speech-tts'); ?></h3>
                <p class="tts-card-desc"><?php esc_html_e('Control how your content sounds when spoken.', 'text-to-speech-tts'); ?></p>
            </div>

            <form method="post" action="options.php" id="content-settings-form">
                <?php
                settings_fields('mementor_tts_content_settings');
                do_settings_sections('mementor_tts_content_settings');
                ?>

                <!-- Include toggles: Title, Author, Date, Excerpt, Image Captions -->
                <div class="tts-controls-grid tts-controls-grid-5">
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Title', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox" id="mementor_tts_include_title" name="mementor_tts_include_title" value="1" <?php checked(1, get_option('mementor_tts_include_title', 1)); ?>>
                            <label for="mementor_tts_include_title"><span class="slider"></span></label>
                        </div>
                    </div>
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Author Name', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox" id="mementor_tts_include_author" name="mementor_tts_include_author" value="1" <?php checked(1, get_option('mementor_tts_include_author', 0)); ?>>
                            <label for="mementor_tts_include_author"><span class="slider"></span></label>
                        </div>
                    </div>
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Post Date', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox" id="mementor_tts_include_date" name="mementor_tts_include_date" value="1" <?php checked(1, get_option('mementor_tts_include_date', 0)); ?>>
                            <label for="mementor_tts_include_date"><span class="slider"></span></label>
                        </div>
                    </div>
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Post Excerpt', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox" id="mementor_tts_include_excerpt" name="mementor_tts_include_excerpt" value="1" <?php checked(1, get_option('mementor_tts_include_excerpt', 0)); ?>>
                            <label for="mementor_tts_include_excerpt"><span class="slider"></span></label>
                        </div>
                    </div>
                    <div class="tts-control-item">
                        <span class="tts-control-label"><?php esc_html_e('Image Captions', 'text-to-speech-tts'); ?></span>
                        <div class="mementor-tts-toggle">
                            <input type="checkbox" id="mementor_tts_include_image_captions" name="mementor_tts_include_image_captions" value="1" <?php checked(1, get_option('mementor_tts_include_image_captions', 0)); ?>>
                            <label for="mementor_tts_include_image_captions"><span class="slider"></span></label>
                        </div>
                    </div>
                </div>

                <!-- Pause Settings -->
                <div class="tts-audio-separator"><?php esc_html_e('Pause settings (in seconds)', 'text-to-speech-tts'); ?></div>
                <div class="tts-audio-grid">
                    <div class="tts-audio-field <?php echo (!$has_pro_license) ? 'is-pro' : ''; ?>">
                        <label class="tts-audio-label">
                            <?php esc_html_e('Pause After Title', 'text-to-speech-tts'); ?>
                            <?php if (!$has_pro_license): ?>
                                <span class="tts-pro-badge"><?php esc_html_e('PRO', 'text-to-speech-tts'); ?></span>
                            <?php endif; ?>
                        </label>
                        <div class="mementor-tts-input-group">
                            <input type="number"
                                   name="mementor_tts_pause_after_title"
                                   id="mementor_tts_pause_after_title"
                                   value="<?php echo esc_attr(get_option('mementor_tts_pause_after_title', '0.6')); ?>"
                                   min="0"
                                   max="10"
                                   step="0.1"
                                   <?php echo (!$has_pro_license) ? 'disabled' : ''; ?>>
                        </div>
                    </div>
                    <div class="tts-audio-field <?php echo (!$has_pro_license) ? 'is-pro' : ''; ?>">
                        <label class="tts-audio-label">
                            <?php esc_html_e('Pause Between Paragraphs', 'text-to-speech-tts'); ?>
                            <?php if (!$has_pro_license): ?>
                                <span class="tts-pro-badge"><?php esc_html_e('PRO', 'text-to-speech-tts'); ?></span>
                            <?php endif; ?>
                        </label>
                        <div class="mementor-tts-input-group">
                            <input type="number"
                                   name="mementor_tts_pause_between_paragraphs"
                                   id="mementor_tts_pause_between_paragraphs"
                                   value="<?php echo esc_attr(get_option('mementor_tts_pause_between_paragraphs', '0.6')); ?>"
                                   min="0"
                                   max="10"
                                   step="0.1"
                                   <?php echo (!$has_pro_license) ? 'disabled' : ''; ?>>
                        </div>
                    </div>
                    <div class="tts-audio-field <?php echo (!$has_pro_license) ? 'is-pro' : ''; ?>">
                        <label class="tts-audio-label">
                            <?php esc_html_e('Pause After Headings', 'text-to-speech-tts'); ?>
                            <?php if (!$has_pro_license): ?>
                                <span class="tts-pro-badge"><?php esc_html_e('PRO', 'text-to-speech-tts'); ?></span>
                            <?php endif; ?>
                        </label>
                        <div class="mementor-tts-input-group">
                            <input type="number"
                                   name="mementor_tts_pause_after_headings"
                                   id="mementor_tts_pause_after_headings"
                                   value="<?php echo esc_attr(get_option('mementor_tts_pause_after_headings', '0.6')); ?>"
                                   min="0"
                                   max="10"
                                   step="0.1"
                                   <?php echo (!$has_pro_license) ? 'disabled' : ''; ?>>
                        </div>
                    </div>
                </div>

                <!-- Custom Intro/Outro -->
                <div class="tts-audio-separator"><?php esc_html_e('Custom text', 'text-to-speech-tts'); ?></div>
                <div class="tts-audio-grid" style="grid-template-columns: 1fr 1fr;">
                    <div class="tts-audio-field">
                        <label class="tts-audio-label" for="mementor_tts_text_before"><?php esc_html_e('Custom Introduction', 'text-to-speech-tts'); ?></label>
                        <textarea name="mementor_tts_text_before" id="mementor_tts_text_before" rows="3"><?php echo esc_textarea(get_option('mementor_tts_text_before', '')); ?></textarea>
                    </div>
                    <div class="tts-audio-field">
                        <label class="tts-audio-label" for="mementor_tts_text_after"><?php esc_html_e('Custom Outro', 'text-to-speech-tts'); ?></label>
                        <textarea name="mementor_tts_text_after" id="mementor_tts_text_after" rows="3"><?php echo esc_textarea(get_option('mementor_tts_text_after', '')); ?></textarea>
                    </div>
                </div>
            </form>
        </div>


        <!-- Product Audio Settings -->
        <?php
        $selected_types = get_option('mementor_tts_post_types', array('post'));
        $has_product_type = in_array('product', $selected_types);
        $woo_active = class_exists('WooCommerce');
        ?>
        <div class="tts-card tts-card-inset tts-product-section <?php echo ($has_product_type && $woo_active) ? 'tts-product-visible' : ''; ?>" id="mementor-tts-product-audio-section">
            <div class="tts-card-header tts-card-header-inline">
                <h3 class="tts-card-title"><?php esc_html_e('Product Audio Settings', 'text-to-speech-tts'); ?></h3>
                <p class="tts-card-desc"><?php esc_html_e('Configure what product data to include when generating audio for WooCommerce products.', 'text-to-speech-tts'); ?></p>
            </div>

            <!-- Audio Content toggles -->
            <div class="tts-controls-grid tts-controls-grid-4">
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Title', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_title" name="mementor_tts_product_include_title" value="1" <?php checked(1, get_option('mementor_tts_product_include_title', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_title"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Price', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_price" name="mementor_tts_product_include_price" value="1" <?php checked(1, get_option('mementor_tts_product_include_price', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_price"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Stock Status', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_stock" name="mementor_tts_product_include_stock" value="1" <?php checked(1, get_option('mementor_tts_product_include_stock', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_stock"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Category', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_category" name="mementor_tts_product_include_category" value="1" <?php checked(1, get_option('mementor_tts_product_include_category', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_category"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Short Description', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_short_desc" name="mementor_tts_product_include_short_desc" value="1" <?php checked(1, get_option('mementor_tts_product_include_short_desc', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_short_desc"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Long Description', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_long_desc" name="mementor_tts_product_include_long_desc" value="1" <?php checked(1, get_option('mementor_tts_product_include_long_desc', 1)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_long_desc"><span class="slider"></span></label>
                    </div>
                </div>
                <div class="tts-control-item">
                    <span class="tts-control-label"><?php esc_html_e('Image Text', 'text-to-speech-tts'); ?></span>
                    <div class="mementor-tts-toggle">
                        <input type="checkbox" id="mementor_tts_product_include_image" name="mementor_tts_product_include_image" value="1" <?php checked(1, get_option('mementor_tts_product_include_image', 0)); ?> form="content-settings-form">
                        <label for="mementor_tts_product_include_image"><span class="slider"></span></label>
                    </div>
                </div>
            </div>

            <!-- Image sub-options (only when Image Text is checked) -->
            <div class="tts-image-sub-options <?php echo get_option('mementor_tts_product_include_image', 0) ? 'tts-sub-visible' : ''; ?>" id="mementor-tts-image-sub-options">
                <span class="tts-audio-label"><?php esc_html_e('Image fields:', 'text-to-speech-tts'); ?></span>
                <div class="tts-image-sub-checks">
                    <label>
                        <input type="checkbox" name="mementor_tts_product_image_alt" value="1" <?php checked(1, get_option('mementor_tts_product_image_alt', 1)); ?> form="content-settings-form">
                        <?php esc_html_e('Alt text', 'text-to-speech-tts'); ?>
                    </label>
                    <label>
                        <input type="checkbox" name="mementor_tts_product_image_title" value="1" <?php checked(1, get_option('mementor_tts_product_image_title', 1)); ?> form="content-settings-form">
                        <?php esc_html_e('Title', 'text-to-speech-tts'); ?>
                    </label>
                    <label>
                        <input type="checkbox" name="mementor_tts_product_image_caption" value="1" <?php checked(1, get_option('mementor_tts_product_image_caption', 0)); ?> form="content-settings-form">
                        <?php esc_html_e('Caption', 'text-to-speech-tts'); ?>
                    </label>
                    <label>
                        <input type="checkbox" name="mementor_tts_product_image_description" value="1" <?php checked(1, get_option('mementor_tts_product_image_description', 0)); ?> form="content-settings-form">
                        <?php esc_html_e('Description', 'text-to-speech-tts'); ?>
                    </label>
                </div>
            </div>

            <!-- Player Placement + Label -->
            <div class="tts-audio-separator"><?php esc_html_e('Product player', 'text-to-speech-tts'); ?></div>
            <div class="tts-audio-grid" style="grid-template-columns: 1fr 1fr;">
                <div class="tts-audio-field">
                    <label class="tts-audio-label" for="mementor_tts_product_player_position"><?php esc_html_e('Player Position', 'text-to-speech-tts'); ?></label>
                    <?php
                    // Derive combined value from the two separate options
                    $short = get_option('mementor_tts_product_player_short_desc', 'disabled');
                    $long = get_option('mementor_tts_product_player_long_desc', 'before');
                    $combined = 'short_before'; // default
                    if ($short === 'before') $combined = 'short_before';
                    elseif ($short === 'after') $combined = 'short_after';
                    elseif ($long === 'before') $combined = 'long_before';
                    elseif ($long === 'after') $combined = 'long_after';
                    else $combined = 'short_before';
                    ?>
                    <select name="mementor_tts_product_player_position" id="mementor_tts_product_player_position" form="content-settings-form">
                        <option value="short_before" <?php selected('short_before', $combined); ?>><?php esc_html_e('Before short description', 'text-to-speech-tts'); ?></option>
                        <option value="short_after" <?php selected('short_after', $combined); ?>><?php esc_html_e('After short description', 'text-to-speech-tts'); ?></option>
                        <option value="long_before" <?php selected('long_before', $combined); ?>><?php esc_html_e('Before long description', 'text-to-speech-tts'); ?></option>
                        <option value="long_after" <?php selected('long_after', $combined); ?>><?php esc_html_e('After long description', 'text-to-speech-tts'); ?></option>
                    </select>
                </div>
                <div class="tts-audio-field" id="mementor-tts-product-label-text-option">
                    <label class="tts-audio-label" for="mementor_tts_product_player_label"><?php esc_html_e('Player Label', 'text-to-speech-tts'); ?></label>
                    <div class="tts-product-label-row">
                        <label class="tts-product-hide-label">
                            <input type="checkbox" name="mementor_tts_product_hide_label" id="mementor_tts_product_hide_label" value="1" <?php checked(1, get_option('mementor_tts_product_hide_label', 0)); ?> form="content-settings-form">
                            <?php esc_html_e('Hide', 'text-to-speech-tts'); ?>
                        </label>
                        <input type="text" name="mementor_tts_product_player_label" id="mementor_tts_product_player_label" value="<?php echo esc_attr(get_option('mementor_tts_product_player_label', '')); ?>" form="content-settings-form" placeholder="<?php echo esc_attr(get_option('mementor_tts_player_label', __('Listen to this article:', 'text-to-speech-tts'))); ?>">
                    </div>
                </div>
            </div>

            <!-- Text Templates (collapsible) -->
            <div class="tts-audio-separator tts-collapsible-trigger" id="mementor-tts-text-templates-toggle">
                <span class="dashicons dashicons-arrow-right-alt2" id="mementor-tts-templates-arrow"></span>
                <span class="tts-separator-title"><?php esc_html_e('Text Templates', 'text-to-speech-tts'); ?></span>
                <span class="tts-separator-hint"><?php esc_html_e('Customize how product data is spoken (leave empty for English defaults)', 'text-to-speech-tts'); ?></span>
            </div>
            <div id="mementor-tts-text-templates-content" class="tts-collapsible-content">
                <div class="tts-audio-grid" style="grid-template-columns: 1fr 1fr;">
                    <?php
                    $templates = array(
                        'mementor_tts_product_text_price' => array(
                            'label' => __('Price', 'text-to-speech-tts'),
                            'placeholder' => 'Price: %s',
                            'hint' => '%s = price',
                        ),
                        'mementor_tts_product_text_sale' => array(
                            'label' => __('Sale Price', 'text-to-speech-tts'),
                            'placeholder' => 'Was %1$s, now %2$s',
                            'hint' => '%1$s = original, %2$s = sale',
                        ),
                        'mementor_tts_product_text_in_stock' => array(
                            'label' => __('In Stock', 'text-to-speech-tts'),
                            'placeholder' => 'In stock',
                            'hint' => '',
                        ),
                        'mementor_tts_product_text_out_of_stock' => array(
                            'label' => __('Out of Stock', 'text-to-speech-tts'),
                            'placeholder' => 'Out of stock',
                            'hint' => '',
                        ),
                        'mementor_tts_product_text_stock_qty' => array(
                            'label' => __('Stock Quantity', 'text-to-speech-tts'),
                            'placeholder' => '%d in stock',
                            'hint' => '%d = quantity',
                        ),
                        'mementor_tts_product_text_category' => array(
                            'label' => __('Category (singular)', 'text-to-speech-tts'),
                            'placeholder' => 'Category: %s',
                            'hint' => '%s = name',
                        ),
                        'mementor_tts_product_text_categories' => array(
                            'label' => __('Categories (plural)', 'text-to-speech-tts'),
                            'placeholder' => 'Categories: %s',
                            'hint' => '%s = names',
                        ),
                    );
                    foreach ($templates as $key => $tpl) : ?>
                        <div class="tts-audio-field">
                            <label class="tts-audio-label">
                                <?php echo esc_html($tpl['label']); ?>
                                <?php if (!empty($tpl['hint'])) : ?>
                                    <span class="tts-template-hint"><?php echo esc_html($tpl['hint']); ?></span>
                                <?php endif; ?>
                            </label>
                            <input type="text" name="<?php echo esc_attr($key); ?>" value="<?php echo esc_attr(get_option($key, '')); ?>" form="content-settings-form" placeholder="<?php echo esc_attr($tpl['placeholder']); ?>">
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>

            <script>
            jQuery(document).ready(function($) {
                $('#mementor-tts-text-templates-toggle').on('click', function() {
                    var $content = $('#mementor-tts-text-templates-content');
                    var $arrow = $('#mementor-tts-templates-arrow');
                    $content.slideToggle(200);
                    $arrow.css('transform', $content.is(':visible') ? 'rotate(90deg)' : 'rotate(0deg)');
                });
            });
            </script>
        </div>


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

