<?php

/**
 * Plugin Name:       Easy Booking Calendar
 * Description:       Enables customers to easily select and book date ranges on product pages.
 * Version:           1.1.4
 * Requires at least: 6.4
 * Requires PHP:      7.4
 * Author:            Devnet
 * Author URI:        https://devnet.hr
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       easy-booking-calendar
 * Domain Path:       /languages
 * Requires Plugins:  woocommerce
 * WC tested up to:   10.9
 */

use Devnet\EBC\Includes\Activator;
use Devnet\EBC\Includes\Deactivator;
use Devnet\EBC\Includes\Plugin;
use Devnet\EBC\Includes\Uninstaller;

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

if (!function_exists('devnet_ebc_fs')) {
    // Create a helper function for easy SDK access.
    function devnet_ebc_fs()
    {
        global $devnet_ebc_fs;

        if (!isset($devnet_ebc_fs)) {
            // Include Freemius SDK.
            require_once dirname(__FILE__) . '/vendor/freemius/wordpress-sdk/start.php';

            $devnet_ebc_fs = fs_dynamic_init([
                'id'               => '16856',
                'slug'             => 'easy-booking-calendar',
                'type'             => 'plugin',
                'public_key'       => 'pk_78a8e2f1c980924fbce5439634135',
                'is_premium'       => false,
                'has_addons'       => false,
                'has_paid_plans'   => false,
                'is_org_compliant' => true,
                'menu'             => [
                    'slug'       => 'easy-booking-calendar-settings',
                    'first-path' => 'edit.php?post_type=product&page=easy-booking-calendar-settings',
                    'parent'     => [
                        'slug' => 'edit.php?post_type=product'
                    ]
                ]
            ]);
        }

        return $devnet_ebc_fs;
    }

    // Init Freemius.
    devnet_ebc_fs();
    // Signal that SDK was initiated.
    do_action('devnet_ebc_fs_loaded');
}

if (!function_exists('devnet_ebc_is_submenu_visible')) {
    function devnet_ebc_is_submenu_visible($is_visible, $menu_id)
    {
        if ('contact' != $menu_id) {
            return $is_visible;
        }
        return devnet_ebc_fs()->can_use_premium_code();
    }
}

if (!function_exists('devnet_ebc_fs_uninstall_cleanup')) {
    function devnet_ebc_fs_uninstall_cleanup()
    {
        require_once plugin_dir_path(__FILE__) . 'includes/uninstaller.php';
        Uninstaller::cleanup();
    }
}

if (!function_exists('devnet_ebc_fs_custom_icon')) {
    function devnet_ebc_fs_custom_icon()
    {
        return dirname(__FILE__) . '/assets/images/logo.gif';
    }
}

if (function_exists('devnet_ebc_fs')) {
    devnet_ebc_fs()->add_filter('is_submenu_visible', 'devnet_ebc_is_submenu_visible', 10, 2);
    devnet_ebc_fs()->add_action('after_uninstall', 'devnet_ebc_fs_uninstall_cleanup');
    devnet_ebc_fs()->add_filter('plugin_icon', 'devnet_ebc_fs_custom_icon');
}

define('DEVNET_EBC_VERSION', '1.1.4');
define('DEVNET_EBC_NAME', 'easy-booking-calendar');
define('DEVNET_EBC_PATH', plugin_basename(__FILE__));
define('DEVNET_EBC_OPTIONS', [
    'general'  => get_option('devnet_ebc_general'),
    'calendar' => get_option('devnet_ebc_calendar'),
    'product'  => get_option('devnet_ebc_product')
]);

function activate_devnet_easy_booking_calendar()
{
    require_once plugin_dir_path(__FILE__) . 'includes/activator.php';
    Activator::activate();
}

function deactivate_devnet_easy_booking_calendar()
{
    require_once plugin_dir_path(__FILE__) . 'includes/deactivator.php';
    Deactivator::deactivate();
}

register_activation_hook(__FILE__, 'activate_devnet_easy_booking_calendar');
register_deactivation_hook(__FILE__, 'deactivate_devnet_easy_booking_calendar');

add_action('plugins_loaded', function () {

    require plugin_dir_path(__FILE__) . 'includes/plugin.php';
    $plugin = new Plugin();
    $plugin->run();
});
