<?php
if (!defined('ABSPATH')) exit;

function acwbsrh_how_to_use_page() {
    if (!current_user_can('manage_options')) {
        wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'auto-content-writer-by-srh'));
    }

    $settings_url  = esc_url(admin_url('admin.php?page=acwbsrh-main'));
    $api_url       = esc_url(admin_url('admin.php?page=acwbsrh-api'));
    $manual_url    = esc_url(admin_url('admin.php?page=acwbsrh-manual'));
    $schedule_url  = esc_url(admin_url('admin.php?page=acwbsrh-schedule'));
    ?>

    <div class="wrap">
        <h1><?php esc_html_e('🚀 How to Use Auto Content Writer By SRH', 'auto-content-writer-by-srh'); ?></h1>

        <div class="notice notice-success" style="margin-top: 15px;">
            <p><strong><?php esc_html_e('Welcome!', 'auto-content-writer-by-srh'); ?></strong> <?php esc_html_e('This guide will help you get started with Auto Content Writer By SRH in just a few minutes.', 'auto-content-writer-by-srh'); ?></p>
        </div>

        <h2 style="margin-top: 30px;"><?php esc_html_e('🛠️ Step 1: Enter Your Business Details', 'auto-content-writer-by-srh'); ?></h2>
        <p>
            <?php
            // translators: %s is the URL to the plugin settings page.
            echo wp_kses_post(sprintf(__('Go to <a href="%s">Settings</a> and fill out the important fields like your business name, type, services offered, tone of voice, etc.', 'auto-content-writer-by-srh'), $settings_url));
            ?>
        </p>

        <ul style="list-style-type: disc; padding-left: 20px;">
            <li><?php esc_html_e('These details are used as the foundation for every blog generated.', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('The more specific and rich your input is, the better and more relevant your blog results will be.', 'auto-content-writer-by-srh'); ?></li>
        </ul>

        <div class="notice notice-warning">
            <p><strong><?php esc_html_e('Important:', 'auto-content-writer-by-srh'); ?></strong> <?php esc_html_e('This information is like the "bible" of your blog generation. It gives the AI context about your business, which results in higher-quality blogs.', 'auto-content-writer-by-srh'); ?></p>
        </div>

        <h2 style="margin-top: 30px;"><?php esc_html_e('🔑 Step 2: Add Your Gemini API Key', 'auto-content-writer-by-srh'); ?></h2>
        <p>
            <?php
            // translators: %s is the URL to the API submenu page.
            echo wp_kses_post(sprintf(__('Go to the <a href="%s">API</a> submenu and paste your Gemini API key there.', 'auto-content-writer-by-srh'), $api_url));
            ?>
        </p>
        <p><?php esc_html_e('Follow these steps to get your API key:', 'auto-content-writer-by-srh'); ?></p>

        <ol style="line-height: 1.8; padding-left: 20px;">
            <li><a href="https://aistudio.google.com/app/apikey" target="_blank" rel="noopener noreferrer">https://aistudio.google.com/app/apikey</a></li>
            <li><?php esc_html_e('Log in with your Google account.', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Click “Get API Key”', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Accept the terms and click “I accept”', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Click “+ Create API Key” in the dashboard', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Select “Create API Key in new project”', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Copy the API key and paste it into the field on the plugin’s API page', 'auto-content-writer-by-srh'); ?></li>
            <li><?php esc_html_e('Click Save API Key', 'auto-content-writer-by-srh'); ?></li>
        </ol>

        <div class="notice notice-error" style="margin-top: 20px;">
            <p><strong><?php esc_html_e('Security Tip:', 'auto-content-writer-by-srh'); ?></strong> <?php esc_html_e('Never share your API key publicly or use it in public code repositories.', 'auto-content-writer-by-srh'); ?></p>
        </div>

        <h2 style="margin-top: 30px;"><?php esc_html_e('🧠 Step 3: Generate a Blog', 'auto-content-writer-by-srh'); ?></h2>
        <p>
            <?php 
            // translators: %s is the URL to the Generate Blog page.
            echo wp_kses_post(sprintf(__('Once your settings and API key are added, head over to <a href="%s">Generate Blog</a> submenu.', 'auto-content-writer-by-srh'), $manual_url));
            ?>
        </p>
        <p><strong><?php esc_html_e('Click the big “Generate Blog Now” button. That’s it!', 'auto-content-writer-by-srh'); ?></strong></p>
        <ul style="list-style-type: disc; padding-left: 20px;">
            <li><?php esc_html_e('A new blog post will be created based on your settings.', 'auto-content-writer-by-srh'); ?></li>
            <li>
                <?php
                // translators: %s is the URL to the settings page.
                echo wp_kses_post(sprintf(__('The post will either be saved as a Draft or Published based on your preference in <a href="%s">Settings</a>.', 'auto-content-writer-by-srh'), $settings_url));
                ?>
            </li>
            <li><?php esc_html_e('A future blog will automatically be scheduled based on your selected frequency (Weekly = 7 days, Bi-Weekly = 14 days, Monthly = 28 days).', 'auto-content-writer-by-srh'); ?></li>
        </ul>

        <h2 style="margin-top: 30px;"><?php esc_html_e('📆 Step 4: Monitor Blog Activity', 'auto-content-writer-by-srh'); ?></h2>
        <p>
            <?php 
            // translators: %s is the URL to the schedule page.
            echo wp_kses_post(sprintf(__('Visit the <a href="%s">Scheduled</a> page to view:', 'auto-content-writer-by-srh'), $schedule_url));
            ?>
        </p>
        <ul style="list-style-type: disc; padding-left: 20px;">
            <li><strong><?php esc_html_e('Next Scheduled Blog', 'auto-content-writer-by-srh'); ?></strong> – <?php esc_html_e('Shows when the next blog will auto-generate', 'auto-content-writer-by-srh'); ?></li>
            <li><strong><?php esc_html_e('Last Generated Blog', 'auto-content-writer-by-srh'); ?></strong> – <?php esc_html_e('Shows title, date, and post status of the last created blog', 'auto-content-writer-by-srh'); ?></li>
        </ul>
        <div class="notice notice-info">
            <p><?php esc_html_e('Blog scheduling happens automatically based on your selected frequency. You don’t need to manually trigger future posts.', 'auto-content-writer-by-srh'); ?></p>
        </div>

        <hr style="margin: 40px 0;">

        <h2><?php esc_html_e('✅ You\'re All Set!', 'auto-content-writer-by-srh'); ?></h2>
        <p>
            <?php esc_html_e('Your Auto Content Writer By SRH plugin is now ready to generate smart, relevant blog posts for your business — automatically.', 'auto-content-writer-by-srh'); ?>
        </p>
        <p>
            <?php 
            // translators: %s is the URL to the settings page.
            echo wp_kses_post(sprintf(__('If you ever want to change your tone, services, or frequency, just update your <a href="%s">Settings</a> — the plugin adapts dynamically.', 'auto-content-writer-by-srh'), $settings_url));
            ?>
        </p>

        <div class="notice notice-success">
            <p><strong><?php esc_html_e('Need Help?', 'auto-content-writer-by-srh'); ?></strong> <?php esc_html_e('Feel free to reach out to support or consult documentation if anything’s unclear.', 'auto-content-writer-by-srh'); ?></p>
        </div>

        <hr style="margin: 40px 0;">

        <h2><?php esc_html_e('❓ Frequently Asked Questions (FAQ)', 'auto-content-writer-by-srh'); ?></h2>

        <details style="margin-bottom: 15px;">
            <summary><strong><?php esc_html_e('What happens if I don’t enter business details?', 'auto-content-writer-by-srh'); ?></strong></summary>
            <p><?php esc_html_e('AI won’t have any context, so the blog output may be generic or irrelevant. Always fill in those fields.', 'auto-content-writer-by-srh'); ?></p>
        </details>

        <details style="margin-bottom: 15px;">
            <summary><strong><?php esc_html_e('Can I change the tone or services later?', 'auto-content-writer-by-srh'); ?></strong></summary>
            <p>
                <?php
                // translators: %s is the URL to the settings page.
                echo wp_kses_post(sprintf(__('Yes! Just go to <a href="%s">Settings</a> and update anytime. Changes will apply to future blogs.', 'auto-content-writer-by-srh'), $settings_url));
                ?>
            </p>
        </details>

        <details style="margin-bottom: 15px;">
            <summary><strong><?php esc_html_e('How do I stop the automatic scheduling?', 'auto-content-writer-by-srh'); ?></strong></summary>
            <p>
                <?php 
                // translators: %s is the URL to the schedule page.
                echo wp_kses_post(sprintf(__('To pause the automatic blog scheduling, go to the <a href="%s">Scheduled Settings</a> page and click the "Pause Auto Blog Schedule" button.', 'auto-content-writer-by-srh'), $schedule_url));
                ?>
            </p>
        </details>

        <details style="margin-bottom: 15px;">
            <summary><strong><?php esc_html_e('Why is my blog not publishing?', 'auto-content-writer-by-srh'); ?></strong></summary>
            <p><?php esc_html_e('Check if your API key is valid and that your post status in settings is set to "Published".', 'auto-content-writer-by-srh'); ?></p>
        </details>
    </div>

    <?php
}
