<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : strategies.php
 * @location     : /modules/thinker/strategies.php
 * @type         : Admin Page
 * @scope        : Module Only
 * @allowed      : Content strategy management, AI generation patterns, strategic approaches
 * @reusability  : Single Use
 * @notes        : Content strategy management interface for thinker module
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}
?>
<div class="igny8-module-page">
    <div class="igny8-container">
        <!-- Page title removed - titles should not appear inside page content -->

        <!-- Strategy Templates Section -->
        <div class="igny8-dashboard-section">
            <div class="igny8-standard-header">
                <div class="igny8-card-header-content">
                    <div class="igny8-card-title-text">
                        <h3>Strategy Templates</h3>
                        <p class="igny8-card-subtitle">Pre-built content strategies for different use cases</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-admin-page igny8-dashboard-icon-lg igny8-dashboard-icon-blue"></span>
                    </div>
                </div>
            </div>
            <div class="igny8-grid-4">
                        <!-- Blog Post Strategy -->
                        <div class="igny8-card">
                            <div class="igny8-standard-header">
                                <div class="igny8-card-header-content">
                                    <div class="igny8-card-title-text">
                                        <h4>Blog Post Strategy</h4>
                                        <p class="igny8-card-subtitle">Comprehensive blog post creation with SEO optimization</p>
                                    </div>
                                    <div class="igny8-card-icon">
                                        <span class="dashicons dashicons-edit-page igny8-dashboard-icon-lg igny8-dashboard-icon-green"></span>
                                    </div>
                                </div>
                            </div>
                            <div class="igny8-card-body">
                                <p>Comprehensive blog post creation with SEO optimization, internal linking, and engagement elements.</p>
                                <div class="igny8-strategy-features">
                                    <span class="igny8-badge igny8-badge-info">SEO Optimized</span>
                                    <span class="igny8-badge igny8-badge-info">Internal Links</span>
                                    <span class="igny8-badge igny8-badge-info">CTA Included</span>
                                </div>
                                <div class="igny8-form-actions">
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-primary" onclick="igny8EditStrategy('blog_post')">
                                        <span class="dashicons dashicons-edit"></span>
                                        Edit
                                    </button>
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-outline" onclick="igny8TestStrategy('blog_post')">
                                        <span class="dashicons dashicons-admin-network"></span>
                                        Test
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Product Description Strategy -->
                        <div class="igny8-card">
                            <div class="igny8-standard-header">
                                <div class="igny8-card-header-content">
                                    <div class="igny8-card-title-text">
                                        <h4>Product Description Strategy</h4>
                                        <p class="igny8-card-subtitle">E-commerce focused product descriptions with conversion optimization</p>
                                    </div>
                                    <div class="igny8-card-icon">
                                        <span class="dashicons dashicons-cart igny8-dashboard-icon-lg igny8-dashboard-icon-orange"></span>
                                    </div>
                                </div>
                            </div>
                            <div class="igny8-card-body">
                                <p>E-commerce focused product descriptions with conversion optimization and feature highlighting.</p>
                                <div class="igny8-strategy-features">
                                    <span class="igny8-badge igny8-badge-warning">Conversion Focused</span>
                                    <span class="igny8-badge igny8-badge-warning">Feature Rich</span>
                                    <span class="igny8-badge igny8-badge-warning">Benefit Driven</span>
                                </div>
                                <div class="igny8-form-actions">
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-primary" onclick="igny8EditStrategy('product_description')">
                                        <span class="dashicons dashicons-edit"></span>
                                        Edit
                                    </button>
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-outline" onclick="igny8TestStrategy('product_description')">
                                        <span class="dashicons dashicons-admin-network"></span>
                                        Test
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Landing Page Strategy -->
                        <div class="igny8-card">
                            <div class="igny8-standard-header">
                                <div class="igny8-card-header-content">
                                    <div class="igny8-card-title-text">
                                        <h4>Landing Page Strategy</h4>
                                        <p class="igny8-card-subtitle">High-converting landing pages with persuasive copy and social proof</p>
                                    </div>
                                    <div class="igny8-card-icon">
                                        <span class="dashicons dashicons-admin-home igny8-dashboard-icon-lg igny8-dashboard-icon-purple"></span>
                                    </div>
                                </div>
                            </div>
                            <div class="igny8-card-body">
                                <p>High-converting landing pages with persuasive copy, social proof, and clear value propositions.</p>
                                <div class="igny8-strategy-features">
                                    <span class="igny8-badge igny8-badge-success">Persuasive Copy</span>
                                    <span class="igny8-badge igny8-badge-success">Social Proof</span>
                                    <span class="igny8-badge igny8-badge-success">Clear CTA</span>
                                </div>
                                <div class="igny8-form-actions">
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-primary" onclick="igny8EditStrategy('landing_page')">
                                        <span class="dashicons dashicons-edit"></span>
                                        Edit
                                    </button>
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-outline" onclick="igny8TestStrategy('landing_page')">
                                        <span class="dashicons dashicons-admin-network"></span>
                                        Test
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Email Campaign Strategy -->
                        <div class="igny8-card">
                            <div class="igny8-standard-header">
                                <div class="igny8-card-header-content">
                                    <div class="igny8-card-title-text">
                                        <h4>Email Campaign Strategy</h4>
                                        <p class="igny8-card-subtitle">Engaging email sequences with personalization and automation</p>
                                    </div>
                                    <div class="igny8-card-icon">
                                        <span class="dashicons dashicons-email igny8-dashboard-icon-lg igny8-dashboard-icon-teal"></span>
                                    </div>
                                </div>
                            </div>
                            <div class="igny8-card-body">
                                <p>Engaging email sequences with personalization, segmentation, and automated follow-ups.</p>
                                <div class="igny8-strategy-features">
                                    <span class="igny8-badge igny8-badge-info">Personalized</span>
                                    <span class="igny8-badge igny8-badge-info">Segmented</span>
                                    <span class="igny8-badge igny8-badge-info">Automated</span>
                                </div>
                                <div class="igny8-form-actions">
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-primary" onclick="igny8EditStrategy('email_campaign')">
                                        <span class="dashicons dashicons-edit"></span>
                                        Edit
                                    </button>
                                    <button type="button" class="igny8-btn igny8-btn-sm igny8-btn-outline" onclick="igny8TestStrategy('email_campaign')">
                                        <span class="dashicons dashicons-admin-network"></span>
                                        Test
                                    </button>
                                </div>
                            </div>
                        </div>
            </div>
        </div>

        <!-- Custom Strategy Builder -->
        <div class="igny8-dashboard-section">
            <div class="igny8-standard-header">
                <div class="igny8-card-header-content">
                    <div class="igny8-card-title-text">
                        <h3>Custom Strategy Builder</h3>
                        <p class="igny8-card-subtitle">Create custom content strategies tailored to your needs</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-plus-alt igny8-dashboard-icon-lg igny8-dashboard-icon-green"></span>
                    </div>
                </div>
            </div>
            <div class="igny8-card">
                <div class="igny8-card-body">
                    <form id="igny8-custom-strategy-form">
                        <div class="igny8-form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                            <div class="igny8-form-group" style="flex: 1;">
                                <label for="strategy_name" class="igny8-field-label">Strategy Name</label>
                                <input type="text" name="strategy_name" id="strategy_name" class="igny8-input" style="width: 100%;" placeholder="Enter strategy name...">
                                <small class="igny8-field-description">Choose a descriptive name for your strategy</small>
                            </div>
                            <div class="igny8-form-group" style="flex: 1;">
                                <label for="strategy_type" class="igny8-field-label">Strategy Type</label>
                                <select name="strategy_type" id="strategy_type" class="igny8-select" style="width: 100%;">
                                    <option value="content">Content Creation</option>
                                    <option value="marketing">Marketing Campaign</option>
                                    <option value="seo">SEO Strategy</option>
                                    <option value="social">Social Media</option>
                                    <option value="email">Email Marketing</option>
                                </select>
                                <small class="igny8-field-description">Select the category for your strategy</small>
                            </div>
                        </div>

                        <div class="igny8-form-group" style="margin-bottom: 20px;">
                            <label for="strategy_description" class="igny8-field-label">Strategy Description</label>
                            <textarea name="strategy_description" id="strategy_description" rows="4" class="igny8-textarea igny8-textarea-blue" style="width: 100%;" placeholder="Describe the purpose and goals of this strategy..."></textarea>
                            <small class="igny8-field-description">Provide a clear description of what this strategy aims to achieve</small>
                        </div>

                        <div class="igny8-form-group" style="margin-bottom: 20px;">
                            <label for="strategy_goals" class="igny8-field-label">Goals & Objectives</label>
                            <textarea name="strategy_goals" id="strategy_goals" rows="3" class="igny8-textarea igny8-textarea-green" style="width: 100%;" placeholder="List the specific goals and objectives for this strategy..."></textarea>
                            <small class="igny8-field-description">Define the specific goals and measurable objectives</small>
                        </div>

                        <div class="igny8-form-group" style="margin-bottom: 20px;">
                            <label for="strategy_instructions" class="igny8-field-label">AI Instructions</label>
                            <textarea name="strategy_instructions" id="strategy_instructions" rows="6" class="igny8-textarea igny8-textarea-purple" style="width: 100%;" placeholder="Provide specific instructions for how the AI should approach this strategy..."></textarea>
                            <small class="igny8-field-description">Detailed instructions for AI behavior and approach</small>
                        </div>

                        <div class="igny8-form-actions">
                            <button type="button" id="igny8-save-strategy" class="igny8-btn igny8-btn-success">
                                <span class="dashicons dashicons-yes"></span>
                                Save Strategy
                            </button>
                            <button type="button" id="igny8-test-strategy" class="igny8-btn igny8-btn-primary">
                                <span class="dashicons dashicons-admin-network"></span>
                                Test Strategy
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Strategy Performance -->
        <div class="igny8-dashboard-section">
            <div class="igny8-standard-header">
                <div class="igny8-card-header-content">
                    <div class="igny8-card-title-text">
                        <h3>Strategy Performance</h3>
                        <p class="igny8-card-subtitle">Track the performance and success of your strategies</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-chart-bar igny8-dashboard-icon-lg igny8-dashboard-icon-purple"></span>
                    </div>
                </div>
            </div>
            <div class="igny8-card">
                <div class="igny8-card-body">
                    <div class="igny8-performance-grid">
                        <div class="igny8-performance-item">
                            <div class="igny8-performance-value"><?php echo esc_html(igny8_get_ai_setting('strategies_created', 0)); ?></div>
                            <div class="igny8-performance-label">Strategies Created</div>
                        </div>
                        <div class="igny8-performance-item">
                            <div class="igny8-performance-value"><?php echo esc_html(igny8_get_ai_setting('strategy_success_rate', '0%')); ?></div>
                            <div class="igny8-performance-label">Success Rate</div>
                        </div>
                        <div class="igny8-performance-item">
                            <div class="igny8-performance-value"><?php echo esc_html(igny8_get_ai_setting('content_generated', 0)); ?></div>
                            <div class="igny8-performance-label">Content Generated</div>
                        </div>
                        <div class="igny8-performance-item">
                            <div class="igny8-performance-value"><?php echo esc_html(igny8_get_ai_setting('avg_engagement', '0%')); ?></div>
                            <div class="igny8-performance-label">Avg Engagement</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Recent Strategy Activity -->
        <div class="igny8-dashboard-section">
            <div class="igny8-standard-header">
                <div class="igny8-card-header-content">
                    <div class="igny8-card-title-text">
                        <h3>Recent Strategy Activity</h3>
                        <p class="igny8-card-subtitle">Monitor recent strategy usage and activity</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-clock igny8-dashboard-icon-lg igny8-dashboard-icon-orange"></span>
                    </div>
                </div>
            </div>
            <div class="igny8-card">
                <div class="igny8-card-body">
                    <div class="igny8-activity-list">
                        <div class="igny8-empty-state">
                            <p>No recent strategy activity. Create and use strategies to see activity here.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
jQuery(document).ready(function($) {
    // Edit Strategy
    window.igny8EditStrategy = function(strategyType) {
        // Open strategy editor modal or redirect to edit page
        igny8ShowNotification('Opening strategy editor for ' + strategyType, 'info', 'thinker');
    };

    // Test Strategy
    window.igny8TestStrategy = function(strategyType) {
        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: {
                action: 'igny8_test_strategy',
                strategy_type: strategyType,
                nonce: '<?php echo wp_create_nonce('igny8_thinker_strategies'); ?>'
            },
            success: function(response) {
                if (response.success) {
                    igny8ShowNotification('Strategy test successful for ' + strategyType, 'success', 'thinker');
                } else {
                    igny8ShowNotification('Strategy test failed: ' + response.data, 'error', 'thinker');
                }
            },
            error: function() {
                igny8ShowNotification('Error testing strategy', 'error', 'thinker');
            }
        });
    };

    // Save Custom Strategy
    $('#igny8-save-strategy').on('click', function() {
        var formData = {
            action: 'igny8_save_custom_strategy',
            nonce: '<?php echo wp_create_nonce('igny8_thinker_strategies'); ?>',
            strategy_name: $('#strategy_name').val(),
            strategy_type: $('#strategy_type').val(),
            strategy_description: $('#strategy_description').val(),
            strategy_goals: $('#strategy_goals').val(),
            strategy_instructions: $('#strategy_instructions').val()
        };

        if (!formData.strategy_name || !formData.strategy_description) {
            igny8ShowNotification('Please fill in required fields', 'warning', 'thinker');
            return;
        }

        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: formData,
            success: function(response) {
                if (response.success) {
                    igny8ShowNotification('Custom strategy saved successfully!', 'success', 'thinker');
                    $('#igny8-custom-strategy-form')[0].reset();
                } else {
                    igny8ShowNotification('Error saving strategy: ' + response.data, 'error', 'thinker');
                }
            },
            error: function() {
                igny8ShowNotification('Error saving strategy', 'error', 'thinker');
            }
        });
    });

    // Test Custom Strategy
    $('#igny8-test-strategy').on('click', function() {
        var formData = {
            action: 'igny8_test_custom_strategy',
            nonce: '<?php echo wp_create_nonce('igny8_thinker_strategies'); ?>',
            strategy_name: $('#strategy_name').val(),
            strategy_type: $('#strategy_type').val(),
            strategy_description: $('#strategy_description').val(),
            strategy_goals: $('#strategy_goals').val(),
            strategy_instructions: $('#strategy_instructions').val()
        };

        if (!formData.strategy_name || !formData.strategy_description) {
            igny8ShowNotification('Please fill in required fields before testing', 'warning', 'thinker');
            return;
        }

        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: formData,
            success: function(response) {
                if (response.success) {
                    igny8ShowNotification('Custom strategy test successful!', 'success', 'thinker');
                } else {
                    igny8ShowNotification('Custom strategy test failed: ' + response.data, 'error', 'thinker');
                }
            },
            error: function() {
                igny8ShowNotification('Error testing strategy', 'error', 'thinker');
            }
        });
    });
});
</script>

<!-- Notification Area -->
<!-- Global notification system is handled by core.js -->
<?php

