<?php
/**
 * Keyideas RingBuilder - Jewelry
 *
 * @package       KeyideasRingBuilderJewelry
 * @author        Keyideas Infotech Pvt. Ltd.
 * @version       1.2.11
 *
 * @wordpress-plugin
 * Plugin Name:   Keyideas RingBuilder - Jewelry
 * Description:   Keyideas RingBuilder - Jewelry Plugin
 * Version:       1.2.11
 * Author:        Keyideas Infotech Pvt. Ltd.
 * Author URI:    https://www.keyideasinfotech.com/
 * Text Domain:   diamond-ring-builder-jewelry
 * Requires Plugins: woocommerce
 * Domain Path:  /translations
 * License: GPL-3.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

define('KIRB_VERSION',  '1.2.11');

define('KIRB_PLUGIN_DIR',  plugins_url('', __FILE__));

// KDM Lite base directory
define('KIRB_BASE_DIR', plugin_dir_path(__FILE__));

// KIRB Home File
define('KIRB_HOME_FILE', __FILE__);

// Endpoint URL
define('KIRB_ENDPOINT_URL', 'https://engagement-ring-builder-o4hk8.kinsta.app/api');

// WordPress.org review URL for this plugin
if ( ! defined('KIRB_REVIEW_URL') ) {
    define('KIRB_REVIEW_URL', 'https://wordpress.org/support/plugin/diamond-ring-builder-jewelry/reviews/?filter=5#new-post');
}

// Include the functions.php file
require_once('functions.php');

// Include the ajax-handler.php file
require_once('ajax-handler.php');

// Cache time in minutes for system level operations
define('KIRB_CACHE_DATA_TIME', 120);

// Cache time in minutes for specific operations
define('KIRB_CACHE_LISTING_PAGE', 30);
define('KIRB_CACHE_RC_ITEMS', 10);

// Enable/Disable cache
define('KIRB_CACHE_ENABLED', true);

// Items per page
define('KIRB_ITEMS_PER_PAGE', intval(kirbGetMeta('_setting_products_per_page', true)));

define('KIRB_ALL_CATEGORIES', array('NATURAL', 'LAB CREATED', 'GEMSTONE', 'COLORED DIAMONDS'));

$byor_strip_theme = kirbGetMeta('_byor_strip_theme');
define('KIRB_BYOR_STRIP_THEME', $byor_strip_theme != false ? $byor_strip_theme : 'circle-step');  

$page_ids_json = kirbGetMeta('_page_ids', true);

if($page_ids_json) {
    $page_ids_json = json_decode($page_ids_json, true);
    
    define('KIRB_ALL_PAGES_MAP', array(
        'NATURAL' =>  get_post_field( 'post_name', $page_ids_json['loose-diamonds']),
        'LAB CREATED' => get_post_field( 'post_name', $page_ids_json['lab-diamonds']),
        'GEMSTONE' => get_post_field( 'post_name', $page_ids_json['gemstone-diamonds']),
        'COLORED DIAMONDS' => get_post_field( 'post_name', $page_ids_json['color-diamonds'])
    ));
}else{
    define('KIRB_ALL_PAGES_MAP', array(
        'NATURAL' => 'loose-diamonds',
        'LAB CREATED' => 'lab-diamonds',
        'GEMSTONE' => 'gemstone-diamonds',
        'COLORED DIAMONDS' => 'color-diamonds'
    ));
}

define('KIRB_ALL_CATEGORIES_MAP', array(
    'NATURAL' => 'kirb-loose-diamonds',
    'LAB CREATED' => 'kirb-lab-diamonds',
    'GEMSTONE' => 'kirb-gemstone-diamonds',
    'COLORED DIAMONDS' => 'kirb-color-diamonds'
));

define('KIRB_SUPPORT_REQUEST_MAIL','sales@keyideasinfotech.com');
define('KIRB_SUPPORT_REQUEST_BCC_MAIL','shopify.keyideas@gmail.com');

define('KIRB_VERSION_CONTROL', array(
    'plugin_styles_min_css' =>  KIRB_VERSION,
    'sideload_styles_css' => KIRB_VERSION,
    'setting_styles_css' => KIRB_VERSION,
    'byor_strip_styles_css' => KIRB_VERSION,
    'common_js' => KIRB_VERSION,
    'byor_review_page_js' => KIRB_VERSION,
    'byor_strip_js' => KIRB_VERSION,
    'diamond-detail-page-js' => KIRB_VERSION,
    'diamond-listing-page-js' => KIRB_VERSION,
    'admin_panel_js' => KIRB_VERSION,
    'admin_activation_form_js' => KIRB_VERSION,
    'admin_tab_language_js' => KIRB_VERSION,
));

// Create dashboard menu item
function kirb_menu_pro() {
    add_menu_page(
        'Keyideas RingBuilder Dashboard',
        'Keyideas RingBuilder - Jewelry',
        'manage_options',
        'diamond-ring-builder-dashboard',
        'kirb_dashboard_page',
        plugins_url('assets/kirb-icon.svg', __FILE__),
        4
    );
}
add_action('admin_menu', 'kirb_menu_pro');

// Dashboard page content
function kirb_dashboard_page() {

    $is_plugin_active = kirbGetMeta('_is_plugin_active', true) == 'true';

    // Enqueue Styles
    wp_enqueue_style('kirb-custom-style', KIRB_PLUGIN_DIR . '/assets/style.min.css', array(), KIRB_VERSION_CONTROL['plugin_styles_min_css'], 'all');
    wp_enqueue_style('kirb-bootstrap-css', KIRB_PLUGIN_DIR . '/assets/libs/bootstrap.min.css', array(), '5.3.3', 'all');

    wp_enqueue_style('kirb-owl-carousel-css', KIRB_PLUGIN_DIR . '/assets/libs/owl.carousel.min.css', array(), '2.3.4', 'all');
    

    // Enqueue Scripts
    wp_enqueue_script('kirb-bootstrap-js', KIRB_PLUGIN_DIR . '/assets/libs/bootstrap.bundle.min.js', array('jquery'), '5.3.3', true);
    wp_enqueue_script('kirb-owl-carousel-js', KIRB_PLUGIN_DIR . '/assets/libs/owl.carousel.min.js', array('jquery'), '2.3.4', true);
    wp_enqueue_script('kirb-custom-script-admin', KIRB_PLUGIN_DIR . '/admin/scripts/admin.js',array('jquery','kirb-bootstrap-js','kirb-owl-carousel-js'), KIRB_VERSION_CONTROL['admin_panel_js'], true);


    wp_enqueue_script('kirb-custom-script-activation-form', KIRB_PLUGIN_DIR . '/admin/scripts/admin-activation-form.js',array('kirb-bootstrap-js','jquery','kirb-custom-script-admin'), KIRB_VERSION_CONTROL['admin_activation_form_js'], true);

    wp_localize_script( 'kirb-custom-script-admin', 'KIRB_PATHS', [
            'KIRB_PLUGIN_DIR' => KIRB_PLUGIN_DIR,
            'SITE_URL' => site_url()
        ]
    );

    $isScheduled = wp_next_scheduled('kirb_import_demo_products_cron') !== false;
    $isRunning   = get_option('kirb_import_running') === 'true';
    $done = (!$isScheduled && !$isRunning) ? "true" : "false";
    wp_localize_script( 'kirb-custom-script-admin', 'KIRB_importCheck', [
            'Import_finish' => $done,
        ]
    );

    global $kirb_is_plugin_initial_setup;
    $kirb_is_plugin_initial_setup = kirbGetMeta('_is_plugin_initial_setup') == 'false';

    wp_localize_script( 'kirb-custom-script-admin', 'KIRB_BOOLS', [
        'IS_PLUGIN_INITIAL_SETUP' => kirbGetMeta('_is_plugin_initial_setup')
    ]);

    if($is_plugin_active) {
        wp_enqueue_script('kirb-custom-script-language', KIRB_PLUGIN_DIR . '/admin/scripts/admin-tab-language.js',array('kirb-bootstrap-js','jquery','kirb-custom-script-admin'), KIRB_VERSION_CONTROL['admin_tab_language_js'], true);
    }

    // Admin UI and Libs
    require_once('ColorsHelper.php');
    include_once('admin/index.php');
}

// Include the hooks file
include_once('kirb_hooks.php');
