<?php
/**
 * Plugin Name: Live Support Chat
 * Plugin URI:  https://example.com/live-support-chat
 * Description: A complete live support chat plugin with admin management, chatter roles, and real-time messaging.
 * Version:     1.0.0
 * Author:      Your Name
 * Author URI:  https://example.com
 * License:     GPL-2.0+
 * Text Domain: live-support-chat
 * Domain Path: /languages
 */

// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Plugin constants.
define( 'LSC_VERSION',     '1.0.0' );
define( 'LSC_PLUGIN_FILE', __FILE__ );
define( 'LSC_PLUGIN_DIR',  plugin_dir_path( __FILE__ ) );
define( 'LSC_PLUGIN_URL',  plugin_dir_url( __FILE__ ) );

/**
 * Autoloader for plugin classes.
 *
 * Maps class names to files:
 *   LSC_Foo       → includes/class-lsc-foo.php
 *   LSC_Foo_Bar   → includes/class-lsc-foo-bar.php
 */
spl_autoload_register( function ( $class ) {
    if ( strpos( $class, 'LSC_' ) !== 0 ) {
        return;
    }
    // Convert LSC_Admin_Users → lsc-admin-users
    $slug = strtolower( str_replace( '_', '-', $class ) );
    $file = LSC_PLUGIN_DIR . 'includes/class-' . $slug . '.php';
    if ( file_exists( $file ) ) {
        require_once $file;
    }
} );

/**
 * Activation hook – create database tables and set defaults.
 */
register_activation_hook( __FILE__, [ 'LSC_Activator', 'activate' ] );

/**
 * Deactivation hook.
 */
register_deactivation_hook( __FILE__, [ 'LSC_Activator', 'deactivate' ] );

/**
 * Bootstrap the plugin on 'plugins_loaded'.
 */
function lsc_init() {
    // Load text domain.
    load_plugin_textdomain( 'live-support-chat', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

    // Core.
    new LSC_Roles();
    new LSC_Ajax();
    new LSC_Sessions(); // Login/logout activity logging.

    // Admin.
    if ( is_admin() ) {
        new LSC_Admin();
        new LSC_Admin_Users();
        new LSC_Admin_Chats();
    }

    // Frontend.
    new LSC_Widget();
    new LSC_Shortcodes();
}
add_action( 'plugins_loaded', 'lsc_init' );
