<?php

/**
 * Plugin Name: CPlanTeam Content Planner with AI
 * Plugin URI: https://contentplan.app/
 * Description: Plan, organize, and generate content for your WordPress site with AI.
 * Version: 1.0.0
 * Author: CPlanTeam
 * Text Domain: cplanteam-ai-content-planner
 * Domain Path: /languages
 * License: GPLv2
 * Requires PHP: 7.4
 */
if ( !defined( 'WPINC' ) ) {
    die;
}
if ( !function_exists( 'cpepai_fs' ) ) {
    function cpepai_fs() {
        // Global Freemius SDK instance
        global $cpepai_fs;
        if ( !isset( $cpepai_fs ) ) {
            // Activate multisite network integration
            if ( !defined( 'WP_FS__PRODUCT_21341_MULTISITE' ) ) {
                define( 'WP_FS__PRODUCT_21341_MULTISITE', true );
            }
            // Include Freemius SDK
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $cpepai_fs = fs_dynamic_init( [
                'id'               => '21341',
                'slug'             => 'cplanteam-ai-content-planner',
                'type'             => 'plugin',
                'public_key'       => 'pk_dfbfbc16f46029f954f515d03f27f',
                'is_premium'       => false,
                'has_addons'       => false,
                'has_paid_plans'   => false,
                'menu'             => [
                    'slug'       => 'cplanteam-ai-content-planner',
                    'first-path' => 'admin.php?page=cplanteam-ai-content-planner',
                    'contact'    => false,
                    'support'    => false,
                ],
                'is_live'          => true,
                'is_org_compliant' => true,
            ] );
        }
        return $cpepai_fs;
    }

    // Init Freemius.
    cpepai_fs();
    // Signal that SDK was initiated.
    do_action( 'cpepai_fs_loaded' );
}
// Customize Freemius opt-in message
if ( function_exists( 'cpepai_fs' ) ) {
    // Customize the opt-in message body
    cpepai_fs()->add_filter(
        'connect_message',
        function (
            $message,
            $user_first_name,
            $product_title,
            $user_login,
            $site_link,
            $freemius_link
        ) {
            return __( 'Opting in enables task automation and helps us deliver important security and feature updates.', 'cplanteam-ai-content-planner' ) . '<br><br>' . __( 'It also allows us to better understand your WordPress environment so the plugin works more reliably.', 'cplanteam-ai-content-planner' ) . '<br><br>' . __( 'If you choose not to opt in, that\'s completely fine - AI Editorial Content Planner will continue to work normally, but automated features will be disabled.', 'cplanteam-ai-content-planner' );
        },
        10,
        6
    );
}
// Plugin version
define( 'CPEPAI_VERSION', '1.0.0' );
define( 'CPEPAI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'CPEPAI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
// Load plugin classes
require_once dirname( __FILE__ ) . '/includes/class-cpepai-plugin.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-admin-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-assets-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-options-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-api-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-database-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-logging-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-posts-service.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-content-plan-helper.php';
require_once dirname( __FILE__ ) . '/includes/class-cpepai-backend-service.php';
// Plugin activation hook
register_activation_hook( __FILE__, 'cpepai_activate' );
function cpepai_activate() {
    $database_service = new CPEPAI_Database_Service();
    // Create content plan items table
    $database_service->create_table( CPEPAI_Database_Service::TABLE_CPEPAI_ITEMS );
    // Create tasks table
    $database_service->create_table( CPEPAI_Database_Service::TABLE_TASKS );
}

// Plugin deactivation hook
register_deactivation_hook( __FILE__, 'cpepai_deactivate' );
function cpepai_deactivate() {
    // Optionally clean up on deactivation
    // $database_service = new CPEPAI_Database_Service();
    // $database_service->drop_tables();
}

// Initialize plugin
if ( class_exists( 'CPEPAI_Plugin' ) ) {
    $plugin = new CPEPAI_Plugin();
    $plugin->run();
}