<?php
/**
 * Plugin Name: AgentForms
 * Plugin URI:  https://agentforms.io
 * Description: Embed AI-powered forms from AgentForms. Use the [agentforms] shortcode or Gutenberg block. Zero backend logic — all processing on agentforms.io.
 * Version:     1.0.0
 * Author:      AgentForms
 * Author URI:  https://agentforms.io
 * License:     GPL-2.0-or-later
 * Text Domain: agentforms
 * Requires at least: 6.0
 * Requires PHP: 7.4
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

define( 'AGENTFORMS_VERSION', '1.0.0' );
define( 'AGENTFORMS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'AGENTFORMS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'AGENTFORMS_BASE_URL', 'https://agentforms.io' );
define( 'AGENTFORMS_CACHE_TTL', 86400 ); // 24 hours

// Load includes
require_once AGENTFORMS_PLUGIN_DIR . 'includes/api.php';
require_once AGENTFORMS_PLUGIN_DIR . 'includes/shortcode.php';
require_once AGENTFORMS_PLUGIN_DIR . 'includes/form-renderer.php';
require_once AGENTFORMS_PLUGIN_DIR . 'includes/settings.php';
require_once AGENTFORMS_PLUGIN_DIR . 'includes/gutenberg.php';

/**
 * Plugin activation hook
 */
function agentforms_activate() {
    // Set default options
    if ( get_option( 'agentforms_settings' ) === false ) {
        add_option( 'agentforms_settings', array(
            'default_theme'          => 'light',
            'default_success_message' => 'Thank you! We will be in touch.',
            'api_base_url'           => AGENTFORMS_BASE_URL,
        ) );
    }
}
register_activation_hook( __FILE__, 'agentforms_activate' );

/**
 * Plugin deactivation hook
 */
function agentforms_deactivate() {
    // Clear all cached form configs
    $keys = array_keys( wp_cache_get_keys() );
    foreach ( $keys as $key ) {
        if ( strpos( $key, 'agentforms_config_' ) === 0 ) {
            delete_option( str_replace( 'agentforms_config_', 'agentforms_config_', $key ) );
        }
    }
}
register_deactivation_hook( __FILE__, 'agentforms_deactivate' );