<?php
/*
 *  Plugin Name:    Click To Dial
 *  Plugin URI:     https://wpchatplugins.com/click-to-dial/
 *  Description:    Click To Dial bubble, button, gutenberg block and Elementor widget.
 *  Author:         ThemeAtelier
 *  Author URI:     http://themeatelier.net/
 *  Requirements:   PHP 7.0 or above, WordPress 4.0 or above.
 *  Version:       1.2.11
 * Text Domain:  click-to-dial
 * Domain Path:  /languages
 */

// Block Direct access

if (!defined('ABSPATH')) {
    die('You should not access this file directly!.');
}

// click to dial version

if (!defined('CTD_VERSION'))
    define('CTD_VERSION', '1.2.11');

// Define constants for plugin directory path.
if (!defined('CTD_DIR_PATH'))
    define('CTD_DIR_PATH', plugin_dir_path(__FILE__));


// Define constants for view directory path.
if (!defined('CTD_VIEW_DIR_PATH'))
    define('CTD_VIEW_DIR_PATH', CTD_DIR_PATH . 'view/');

// Define constants for elementor widget directory path.
if (!defined('CTD_EW_DIR_PATH'))
    define('CTD_EW_DIR_PATH', CTD_VIEW_DIR_PATH . 'elementor-widgets/');


// Define constants for plugin directory path.
if (!defined('CTD_DIR_URL'))
    define('CTD_DIR_URL', plugin_dir_url(__FILE__));

// load text domain from plugin folder
function ctd_load_textdomain()
{
    load_plugin_textdomain('', false, dirname(__FILE__) . "/languages");
}
add_action("plugins_loaded", 'ctd_load_textdomain');

// Plugin settings in plugin list
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ctd_settings_link');
function ctd_settings_link(array $links)
{
    $url = get_admin_url() . "admin.php?page=ctd";
    $settings_link = '<a href="' . esc_url($url) . '">' . esc_html__('Settings', 'click-to-dial') . '</a>';
    $links[] = $settings_link;
    return $links;
}

// Pro version link
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ctd_pro_link');
function ctd_pro_link(array $links)
{
    $url = "https://1.envato.market/n17Pv7";
    $settings_link = '<a style="color: #289951; font-weight: 700;" href="' . esc_url($url) . '">' . esc_html__('Go Pro!', 'click-to-dial') . '</a>';
    $links[] = $settings_link;
    return $links;
}

// Register block
function create_ctd_block_init()
{
    register_block_type_from_metadata(CTD_VIEW_DIR_PATH . 'blocks/');
}
add_action('init', 'create_ctd_block_init');

// Register block category 

function ctd_plugin_block_categories($categories)
{
    return array_merge(
        $categories,
        [
            [
                'slug'  => 'click-to-dial-block',
                'title' => __('Click To Dial Block', 'click-to-dial'),
            ],
        ]
    );
}
add_action('block_categories_all', 'ctd_plugin_block_categories', 10, 2);

add_action('admin_menu', 'ctd_plugin_page');
function ctd_plugin_page()
{
    // This page will be under "Settings"
    add_menu_page(
        esc_html__('Click To Dial', 'click-to-dial'),
        esc_html__('Click To Dial', 'click-to-dial'),
        'manage_options',
        'ctd',
        'click_to_dial_settings',
        'dashicons-phone',
        9
    );
    do_action('click_to_dial_before_upgrade_pro_menu');
    add_submenu_page(
        'ctd',
        __('👑 Upgrade to Pro!',
        'ctd'),
        sprintf('<span class="click-to-dial-get-pro-text">%s</span>', __('👑 Upgrade to Pro!', 'click-to-dial')),
        'manage_options', 
        'https://1.envato.market/n17Pv7');
    do_action('click_to_dial_after_upgrade_pro_menu');
}

/**
 * Options page callback
 */
function click_to_dial_settings() {}

add_action('after_setup_theme', 'click_to_dial_init');

function click_to_dial_init() {
// Script enqueue class include
require_once CTD_DIR_PATH . 'inc/class-enqueue.php';
// View Shortcodes
require_once CTD_DIR_PATH . '/view/elementor-widgets/elementor-widget.php';
require_once CTD_DIR_PATH . 'view/shortcodes/custom-shortcode.php';

// buttons functions
require_once CTD_DIR_PATH . 'inc/functions.php';
// Button template class
require_once CTD_DIR_PATH . 'inc/class-custom-buttons-templates.php';

// single chat bubble template
require_once CTD_DIR_PATH . '/view/chat-bubbles/chat-bubbles.php';

// include framework for admin panel
require_once CTD_DIR_PATH . 'admin/classes/setup.class.php';
require_once CTD_DIR_PATH . 'inc/ctd-plugin-options.php';
// Offer Banner
if ( ! defined( 'THEMEATELIER_OFFER_BANNER_LOADED' ) ) {
define( 'THEMEATELIER_OFFER_BANNER_LOADED', true );
    require_once CTD_DIR_PATH . 'Helpers/ThemeAtelier_Offer_Banner.php';
    ThemeAtelier_Offer_Banner::instance();
}

}

/**
 * Initialize the plugin tracker
 *
 * @return void
 */
function Ctd_appsero_init()
{

    if (!class_exists('CtdAppSero\Insights')) {
        require_once CTD_DIR_PATH . 'admin/appsero/Client.php';
    }

    $client = new CtdAppSero\Client('9ead1183-9a70-4b15-8191-ff8984e04b28', 'Click To Dial', __FILE__);

    // Active insights
    $client->insights()->init();
}

Ctd_appsero_init();
