<?php
defined('ABSPATH') or die('No script kiddies please!!');
/**
 * Plugin Name:       Chat in Website
 * Plugin URI:        https://wpshuffle.com/wordpress-plugins/
 * Description:       Chat in Website is your ultimate WordPress plugin to engage users with dynamic chat and quick interaction options to Whatsapp.
 * Version:           1.0.6
 * Requires at least: 6.2
 * Requires PHP:      7.2
 * Author:            WP Shuffle
 * Author URI:        https://wpshuffle.com
 * License:           GPLv2 or later
 * License URI:       https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Text Domain:       chat-in-website
 * Domain Path:       /languages
 */
if (!class_exists('CIWS_Main')) {
    class CIWS_Main {
        function __construct() {
            $this->define_constants();
            $this->includes();
            register_activation_hook(__FILE__, [$this, 'create_ciws_tables']);
            add_action('plugins_loaded', [$this, 'ciws_initialize_woocommerce_integration']);
        }

        function define_constants() {
            global $wpdb;
            defined('CIWS_PATH') or define('CIWS_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
            defined('CIWS_URL') or define('CIWS_URL', untrailingslashit(plugin_dir_url(__FILE__)));
            defined('CIWS_VERSION') or define('CIWS_VERSION', '1.0.5');
            defined('CIWS_IMG_DIR') or define('CIWS_IMG_DIR', plugin_dir_url(__FILE__) . 'images');
            defined('CIWS_CSS_DIR') or define('CIWS_CSS_DIR', untrailingslashit(plugin_dir_url(__FILE__)) . '/assets/css'); // plugin's CSS directory URL
            defined('CIWS_TABLE') or define('CIWS_TABLE', $wpdb->prefix . 'ciws_whatsapp_details');
        }

        function includes() {

            include(CIWS_PATH . '/includes/classes/admin/class-ciws-library.php');
            include(CIWS_PATH . '/includes/classes/admin/class-ciws-admin.php');
            include(CIWS_PATH . '/includes/classes/admin/class-ciws-crud.php');
            include(CIWS_PATH . '/includes/classes/admin/class-ciws-account-ajax.php');
            include(CIWS_PATH . '/includes/classes/class-ciws-floating-icon.php');
            include(CIWS_PATH . '/includes/classes/class-ciws-enqueue.php');
            include(CIWS_PATH . '/includes/classes/class-ciws-shortcode.php');
            include(CIWS_PATH . '/includes/classes/class-ciws-api.php');
        }
        function ciws_initialize_woocommerce_integration() {
            include(CIWS_PATH . '/includes/classes/class-ciws-woocommerce.php');
        }


        function create_ciws_tables() {

            global $wpdb;
            $charset_collate = $wpdb->get_charset_collate();

            /**
             * Account Table
             * 
             */
            $ciws_details_table = CIWS_TABLE;

            /**
             * CIWP Account Settings Table Query
             */
            $ciws_details_sql = "CREATE TABLE $ciws_details_table (
				account_id mediumint(9) NOT NULL AUTO_INCREMENT,
                account_name varchar(255),
                ciws_account_details longtext,
                UNIQUE KEY account_id (account_id)
							  ) $charset_collate;";
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($ciws_details_sql);
        }
    }

    new CIWS_Main();
}
