<?php
namespace AIAutoTool\Features\CanonicalManager;

if ( ! defined( 'ABSPATH' ) ) exit; // Thoát nếu truy cập trực tiếp

/**
 * AI Auto Tool - Canonical Manager Feature
 * 
 * @package AIAutoTool\Features\CanonicalManager
 * @namespace AIAutoTool\Features\CanonicalManager
 */

// Include the full Canonical Manager implementation with all features
require_once dirname(__FILE__) . '/canonical.php';

// Create namespace wrapper
if (!class_exists('AIAutoTool\\Features\\CanonicalManager\\CanonicalManager')) {
    class CanonicalManager extends \Aiautotool_Canonical {
        public $active_option_name = 'Aiautotool_Canonical_active';
        public $icon = '<i class="fa-solid fa-link"></i>';
        
        public function __construct() {
            // Ensure correct option name
            $this->active_option_name = 'Aiautotool_Canonical_active';
            parent::__construct();
        }
        
        /**
         * Render feature for integrations page
         */
        public function render_feature() {
            // Load feature descriptions
            require_once plugin_dir_path(dirname(__FILE__)) . 'lib/feature-descriptions.php';
            
            $description = \AiAutoTool_Feature_Descriptions::get('canonical');
            if (!$description) {
                $description = __('Manage canonical URLs and redirects for better SEO', 'ai-auto-tool');
            }
            
            $autoToolBox = new \AutoToolBox(
                esc_html__('Canonical Manager', 'ai-auto-tool'),
                $description,
                "https://doc.aiautotool.com/features/canonical",
                $this->active_option_name,
                $this->active,
                plugins_url('../../images/logo.svg', __FILE__)
            );
            
            echo $autoToolBox->generateHTML();
        }
        
        /**
         * Render tab setting - Already inherited from parent class Aiautotool_Canonical
         * But we override to ensure it works correctly
         */
        public function render_tab_setting() {
            if ($this->active == 'true') {
                echo '<button href="#tab-canonical-setting" class="nav-tab sotab"><i class="fa-solid fa-link"></i> ' . esc_html__('Canonical Manager', 'ai-auto-tool') . '</button>';
            }
        }
        
        /**
         * Render settings page - Already inherited from parent class Aiautotool_Canonical
         * This method is already implemented in parent class, no need to override
         */
    }
}
