<?php
if (defined('ELEMENTOR_VERSION')) {
    require_once WP_PLUGIN_DIR . '/elementor/elementor.php';
}
include plugin_dir_path(__FILE__) . '../vendor/autoload.php';



use Bookingor\Backend\Controller\Bookings\BookingsControl;
use Bookingor\Backend\Controller\BusinessProfile\BusinessProfileControl;
use Bookingor\Backend\Controller\Calendar\FullCalendarControl;
use Bookingor\Backend\Controller\Category\CategoryControl;
use Bookingor\Backend\Controller\Customer\CustomerControl;
use Bookingor\Backend\Controller\Location\LocationControl;
use Bookingor\Backend\Controller\Notification\NotificationControl;
use Bookingor\Backend\Controller\Payment\PaymentControl;
use Bookingor\Backend\Controller\Service\ServiceControl;
use Bookingor\Backend\Controller\Settings\SettingsControl;
use Bookingor\Backend\Controller\Staff\StaffControl;
use Bookingor\Backend\Controller\Starter\StarterController;
use Bookingor\Backend\Controller\Templates\TemplatesControl;
use Bookingor\Frontend\Controller\Booking\BookingControlFront;
use Bookingor\Frontend\Controller\Category\CategoryControlFront;
use Bookingor\Frontend\Controller\Customer\CustomerControlFront;
use Bookingor\Frontend\Controller\Location\LocationControlFront;
use Bookingor\Frontend\Controller\Service\ServiceControlFront;
use Bookingor\Frontend\Controller\Staff\StaffControlFront;
use Bookingor\Frontend\Controller\TimeSheet\WeeklyTimeSheetControlFront;
use Bookingor\Integrations\WooCommerce\WooCommercePaymentService;
use Bookingor\Integrations\Elementor\ElementorIntegration;
use Bookingor\Routes\AdminRoute;
use Bookingor\Routes\PublicRoute;

/**
 * The file that defines the core plugin class.
 *
 * A class definition that includes attributes and functions used across both the
 * public-facing side of the site and the admin area.
 *
 * @see       The Creative Next
 * @since      1.0.0
 */
/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      1.0.0
 *
 * @author     The Creative Next <contact@thecreative-next.com>
 */
class Bookingor
{
    /**
     * The loader that's responsible for maintaining and registering all hooks that power
     * the plugin.
     *
     * @since    1.0.0
     *
     * @var Bookingor_Loader Maintains and registers all hooks for the plugin.
     */
    protected $loader;
    /**
     * The unique identifier of this plugin.
     *
     * @since    1.0.0
     *
     * @var string The string used to uniquely identify this plugin.
     */
    protected $plugin_name;
    /**
     * The current version of the plugin.
     *
     * @since    1.0.0
     *
     * @var string The current version of the plugin.
     */
    protected $version;

    /**
     * Define the core functionality of the plugin.
     *
     * Set the plugin name and the plugin version that can be used throughout the plugin.
     * Load the dependencies, define the locale, and set the hooks for the admin area and
     * the public-facing side of the site.
     *
     * @since    1.0.0
     */
    public function __construct()
    {
        if (defined('BOOKINGOR_VERSION')) {
            $this->version = BOOKINGOR_VERSION;
        } else {
            $this->version = '2.0.13';
        }
        $this->plugin_name = 'bookingor';
        $this->load_dependencies();
        $this->set_locale();
        $this->define_admin_hooks();
        $this->define_public_hooks();
    }

    /**
     * Create an instance of the loader which will be used to register the hooks
     * with WordPress.
     *
     * @since    1.0.0
     */
    private function load_dependencies()
    {
        /**
         * The class responsible for orchestrating the actions and filters of the
         * core plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-bookingor-loader.php';
        /**
         * The class responsible for defining internationalization functionality
         * of the plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-bookingor-i18n.php';

        $this->loader = new Bookingor_Loader();
    }

    /**
     * Uses the Bookingor_i18n class in order to set the domain and to register the hook
     * with WordPress.
     *
     * @since    1.0.0
     */
    private function set_locale()
    {
        $plugin_i18n = new Bookingor_i18n();
        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
    }

    /**
     * Register all of the hooks related to the admin area functionality
     * of the plugin.
     *
     * @since    1.0.0
     */
    private function define_admin_hooks()
    {
        if (is_admin()) {
            $plugin_admin = new AdminRoute($this->get_plugin_name(), $this->get_version());
            $plugin_admin_category = new CategoryControl();
            $plugin_admin_services = new ServiceControl();
            $plugin_admin_staff = new StaffControl();
            $plugin_admin_location = new LocationControl();
            $plugin_admin_notification = new NotificationControl();
            $plugin_admin_profile = new BusinessProfileControl();
            $plugin_admin_settings = new SettingsControl();
            $plugin_admin_customer = new CustomerControl();
            $plugin_admin_payment = new PaymentControl();
            $plugin_admin_booking = new BookingsControl();
            $plugin_admin_calendar = new FullCalendarControl();
            $plugin_admin_templates = new TemplatesControl();
            $plugin_admin_starter = new StarterController();
            $elementorIntegration = new ElementorIntegration();




            $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
            $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
            $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_pages');
            $this->loader->add_action('admin_init', $plugin_admin, 'default_image');
            $this->loader->add_action('admin_init', $plugin_admin, 'check_activation_redirect');

            //category
            $this->loader->add_action('admin_init', $plugin_admin_category, 'bp_category_view');
            $this->loader->add_action('wp_ajax_bp_add_category', $plugin_admin_category, 'bp_add_category');
            $this->loader->add_action('wp_ajax_bp_get_category', $plugin_admin_category, 'bp_get_category');
            $this->loader->add_action('wp_ajax_bp_update_category', $plugin_admin_category, 'bp_update_category');
            $this->loader->add_action('wp_ajax_bp_delete_category', $plugin_admin_category, 'bp_delete_category');
            $this->loader->add_action('admin_post_bp_category_view', $plugin_admin_category, 'bp_category_view');
            $this->loader->add_action('wp_ajax_bp_add_boooking_buttons', $plugin_admin, 'bp_add_boooking_buttons');
            // services ========================================
            $this->loader->add_action('wp_ajax_bp_add_service', $plugin_admin_services, 'bp_add_service');
            $this->loader->add_action('wp_ajax_bp_delete_service', $plugin_admin_services, 'bp_delete_service');
            $this->loader->add_action('admin_init', $plugin_admin_services, 'bp_update_service');
            $this->loader->add_action('admin_init', $plugin_admin_services, 'bp_view_service');
            $this->loader->add_action('wp_ajax_bp_service_update', $plugin_admin_services, 'bp_service_update');
            $this->loader->add_action('admin_init', $plugin_admin_services, 'bp_get_category_for_services');
            $this->loader->add_action('admin_post_bp_view_service', $plugin_admin_services, 'bp_view_service');
            $this->loader->add_action('wp_ajax_bp_add_timesheet', $plugin_admin_services, 'bp_add_service');
            $this->loader->add_action('wp_ajax_bp_get_subcategory_for_services', $plugin_admin_services, 'bp_get_subcategory_for_services');
            //settings================================
            $this->loader->add_action('wp_ajax_bp_settings_update', $plugin_admin_settings, 'bp_settings_update');
            $this->loader->add_action('wp_ajax_bp_settings_email_test', $plugin_admin_settings, 'bp_settings_email_test');
            $this->loader->add_action('admin_init', $plugin_admin_settings, 'Adds_Options');
            $this->loader->add_action('wp_ajax_myaction', $plugin_admin, 'so_wp_ajax_function');
            $this->loader->add_action('wp_ajax_nopriv_myaction', $plugin_admin, 'so_wp_ajax_function');
            $this->loader->add_action('wp_ajax_secureBookingor', $plugin_admin_settings, 'secureBookingor');

            // profile
            $this->loader->add_action('admin_init', $plugin_admin_profile, 'profile_adds_Options');
            $this->loader->add_action('wp_ajax_profile_update_Options', $plugin_admin_profile, 'profile_update_Options');

            // starter
            $this->loader->add_action('wp_ajax_bookingor_create_booking_page', $plugin_admin_starter, 'create_booking_page');
            $this->loader->add_action('wp_ajax_bookingor_import_demo', $plugin_admin_starter, 'import_demo');
            $this->loader->add_action('wp_ajax_bookingor_save_wizard_service', $plugin_admin_starter, 'save_wizard_service');
            $this->loader->add_action('wp_ajax_bookingor_save_wizard_staff', $plugin_admin_starter, 'save_wizard_staff');
            $this->loader->add_action('wp_ajax_bookingor_mark_setup_complete', $plugin_admin_starter, 'mark_setup_complete');
            //staff======================================
            $this->loader->add_action('wp_ajax_bp_add_staff', $plugin_admin_staff, 'bp_add_staff');
            $this->loader->add_action('wp_ajax_bp_staff_update', $plugin_admin_staff, 'bp_staff_update');
            $this->loader->add_action('wp_ajax_bp_delete_staff', $plugin_admin_staff, 'bp_delete_staff');
            $this->loader->add_action('admin_init', $plugin_admin_staff, 'bp_view_staff');
            $this->loader->add_action('admin_init', $plugin_admin_staff, 'bp_get_staff_data');
            $this->loader->add_action('admin_init', $plugin_admin_staff, 'bp_get_location_fr_staff');

            // Templates
            $this->loader->add_action('wp_ajax_updates_design_templates', $plugin_admin_templates, 'updates_design_templates');
            $this->loader->add_action('wp_ajax_updates_design_templates', $plugin_admin_templates, 'updates_design_templates');
            $this->loader->add_action('wp_ajax_bp_settings_get_design_templates_data', $plugin_admin_templates, 'bp_settings_get_design_templates_data');
            $this->loader->add_action('wp_ajax_nopriv_bp_settings_get_design_templates_data', $plugin_admin_templates, 'bp_settings_get_design_templates_data');

            //location
            $this->loader->add_action('wp_ajax_bp_add_location', $plugin_admin_location, 'bp_add_location');
            $this->loader->add_action('wp_ajax_bp_update_location', $plugin_admin_location, 'bp_update_location');
            $this->loader->add_action('admin_init', $plugin_admin_location, 'bp_get_location_view');
            $this->loader->add_action('wp_ajax_bp_delete_location', $plugin_admin_location, 'bp_delete_location');
            $this->loader->add_action('wp_ajax_bp_get_location', $plugin_admin_location, 'bp_get_location');
            // customer order
            $this->loader->add_action('admin_init', $plugin_admin_booking, 'bp_booking_order');
            $this->loader->add_action('wp_ajax_change_booking_status', $plugin_admin_booking, 'change_booking_status');
            //Customer Admin
            $this->loader->add_action('admin_init', $plugin_admin_customer, 'bp_get_customer_view');
            $this->loader->add_action('wp_ajax_customer_delete', $plugin_admin_customer, 'customer_delete');
            // admin settings
            // notification
            $this->loader->add_action('admin_init', $plugin_admin_notification, 'bp_get_emails_all');
            $this->loader->add_action('wp_ajax_bp_notification_email_update', $plugin_admin_notification, 'bp_notification_email_update');
            // payment
            $this->loader->add_action('wp_ajax_change_pay_status', $plugin_admin_payment, 'change_pay_status');
            $this->loader->add_action('wp_ajax_update_paid_n_pay_status', $plugin_admin_payment, 'update_paid_n_pay_status');
            $this->loader->add_action('wp_ajax_update_paid_amount', $plugin_admin_payment, 'update_paid_amount');
            $this->loader->add_action('admin_init', $plugin_admin_payment, 'customer_payment_view');
            // booking
            // google Calendar
            //full calender show_events_full_calender
            $this->loader->add_action('wp_ajax_show_events_full_calender', $plugin_admin_calendar, 'show_events_full_calender');
            $this->loader->add_action('wp_ajax_nopriv_show_events_full_calender', $plugin_admin_calendar, 'show_events_full_calender');
            // get_last_booking_data
            //payment customer
        }
    }

    /**===============================================================================================================
     *
     * Public folder action and ajax and more
     *
     * ===============================================================================================================
     */

    /**
     * Register all of the hooks related to the public-facing functionality
     * of the plugin.
     *
     * @since    1.0.0
     */
    private function define_public_hooks()
    {
        $plugin_public = new PublicRoute($this->get_plugin_name(), $this->get_version());

        $plugin_public_category = new CategoryControlFront();
        $plugin_public_service = new ServiceControlFront();
        $plugin_public_staff = new StaffControlFront();
        $plugin_public_location = new LocationControlFront();
        $plugin_public_timesheet = new WeeklyTimeSheetControlFront();
        $plugin_public_customer = new CustomerControlFront();
        $plugin_public_booking_confirm_payment = new BookingControlFront();
        $plugin_public_woo_commerce = new WooCommercePaymentService();
        $elementorIntegration = new ElementorIntegration();
        // $elementorIntegration->init();
        // $elementorIntegration->register_widgets();
        // $elementorIntegration->register_controls();
        // $elementorIntegration->register_form_actions();

        if (defined('ELEMENTOR_VERSION')) {
            ElementorIntegration::instance();
        }

        $plugin_public_settings = new SettingsControl();
        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles', 1);
        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts', 1);
        // shortcodes
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_1', $plugin_public, 'bp_booking_design_one');
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_2', $plugin_public, 'bp_booking_design_two');
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_3', $plugin_public, 'bp_booking_design_six');
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_4', $plugin_public, 'bp_booking_design_seven'); // progress bar at bottom with single show
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_5', $plugin_public, 'bookingor_booking_widget'); // widget booking
        $this->loader->add_shortcode('BOOKINGOR_DESIGN_6', $plugin_public, 'bp_booking_design_four');
        $this->loader->add_shortcode('BOOKINGOR_START_CATEGORY', $plugin_public, 'bookingor_start_category_booking');
        $this->loader->add_shortcode('BOOKINGOR_STARTER', $plugin_public, 'bookingor_starter');
        $this->loader->add_shortcode('BOOKINGOR_START_SERVICE', $plugin_public, 'bookingor_starter');
        $this->loader->add_shortcode('BOOKINGOR_START_STAFF', $plugin_public, 'bookingor_start_staff_booking');

        // timesheet
        $this->loader->add_action('wp_ajax_front_get_staff_time_sheet', $plugin_public_timesheet, 'front_get_staff_time_sheet');
        $this->loader->add_action('wp_ajax_nopriv_front_get_staff_time_sheet', $plugin_public_timesheet, 'front_get_staff_time_sheet');

        $this->loader->add_action('wp_ajax_front_get_service_time_sheet', $plugin_public_timesheet, 'front_get_service_time_sheet');
        $this->loader->add_action('wp_ajax_nopriv_front_get_service_time_sheet', $plugin_public_timesheet, 'front_get_service_time_sheet');

        $this->loader->add_action('wp_ajax_bookingor_front_business_weekly_time_sheet', $plugin_public_timesheet, 'bookingor_front_business_weekly_time_sheet');
        $this->loader->add_action('wp_ajax_nopriv_bookingor_front_business_weekly_time_sheet', $plugin_public_timesheet, 'bookingor_front_business_weekly_time_sheet');

        // confirm booking
        $this->loader->add_action('wp_ajax_bp_confirm_booking', $plugin_public_booking_confirm_payment, 'bp_confirm_booking');
        $this->loader->add_action('wp_ajax_nopriv_bp_confirm_booking', $plugin_public_booking_confirm_payment, 'bp_confirm_booking');

        // service
        $this->loader->add_action('wp_ajax_bp_front_services_data', $plugin_public_service, 'bp_front_services_data');
        $this->loader->add_action('wp_ajax_nopriv_bp_front_services_data', $plugin_public_service, 'bp_front_services_data');
        $this->loader->add_action('wp_ajax_bp_front_services_data_w_location', $plugin_public_service, 'bp_front_services_data_w_location');
        $this->loader->add_action('wp_ajax_nopriv_bp_front_services_data_w_location', $plugin_public_service, 'bp_front_services_data_w_location');
        // category
        $this->loader->add_action('init', $plugin_public_category, 'bp_font_category_view');
        $this->loader->add_action('init', $plugin_public_category, 'bp_font_widget_category_view');
        $this->loader->add_action('wp_ajax_bp_front_get_subcategory_ajx', $plugin_public, 'bp_front_get_subcategory_ajx');
        $this->loader->add_action('wp_ajax_nopriv_bp_front_get_subcategory_ajx', $plugin_public, 'bp_front_get_subcategory_ajx');
        // staff


        $this->loader->add_action('init', $plugin_public_staff, 'bp_front_staff_view');
        $this->loader->add_action('wp_ajax_bp_front_staff_assigns', $plugin_public_staff, 'bp_front_staff_assigns');
        $this->loader->add_action('wp_ajax_nopriv_bp_front_staff_assigns', $plugin_public_staff, 'bp_front_staff_assigns');
        $this->loader->add_action('wp_ajax_bp_get_staff_email', $plugin_public_staff, 'bp_get_staff_email');
        $this->loader->add_action('wp_ajax_nopriv_bp_get_staff_email', $plugin_public_staff, 'bp_get_staff_email');


        // location front_get_location
        $this->loader->add_action('init', $plugin_public_location, 'bp_front_location_view');
        $this->loader->add_action('init', $plugin_public_location, 'service_location_assign');
        $this->loader->add_action('init', $plugin_public_location, 'location_all_services');
        $this->loader->add_action('wp_ajax_front_get_location', $plugin_public_location, 'front_get_location');
        $this->loader->add_action('wp_ajax_nopriv_front_get_location', $plugin_public_location, 'front_get_location');
        $this->loader->add_action('wp_ajax_service_staff_location_assign_maps', $plugin_public_location, 'service_staff_location_assign_maps');
        $this->loader->add_action('wp_ajax_nopriv_service_staff_location_assign_maps', $plugin_public_location, 'service_staff_location_assign_maps');
        $this->loader->add_action('wp_ajax_service_location_assign_with_id', $plugin_public_location, 'service_location_assign_with_id');
        $this->loader->add_action('wp_ajax_nopriv_service_location_assign_with_id', $plugin_public_location, 'service_location_assign_with_id');
        // get Settings Data
        $this->loader->add_action('wp_ajax_nopriv_secureBookingor', $plugin_public_settings, 'secureBookingor');

        $this->loader->add_action('wp_ajax_bp_settings_get_data', $plugin_public_settings, 'bp_settings_get_data');
        $this->loader->add_action('wp_ajax_nopriv_bp_settings_get_data', $plugin_public_settings, 'bp_settings_get_data');
        // customer
        $this->loader->add_action('wp_ajax_validateCustomerForm', $plugin_public_customer, 'validateCustomerForm');
        $this->loader->add_action('wp_ajax_nopriv_validateCustomerForm', $plugin_public_customer, 'validateCustomerForm');
        // woocommerce bookingor_wc_cart_page
        $this->loader->add_action('init', $plugin_public_woo_commerce, 'get_all_wooCommerce_products');
        $this->loader->add_action('init', $plugin_public_woo_commerce, 'get_all_wooCoomerce_Product_front');
        $this->loader->add_action('wp_ajax_bookingor_wc_cart_page', $plugin_public_woo_commerce, 'bookingor_wc_cart_page');
        $this->loader->add_action('wp_ajax_nopriv_bookingor_wc_cart_page', $plugin_public_woo_commerce, 'bookingor_wc_cart_page');
        $this->loader->add_action('wp_ajax_bookingor_wc_created', $plugin_public_woo_commerce, 'bookingor_wc_created');
        $this->loader->add_action('wp_ajax_nopriv_bookingor_wc_created', $plugin_public_woo_commerce, 'bookingor_wc_created');
        $this->loader->add_action('woocommerce_thankyou', $plugin_public_woo_commerce, 'bookingor_wc_created', 10, 1);

        // Cron hooks for Next Day Reminders
        $plugin_public_notification = new NotificationControl();
        $this->loader->add_action('init', $plugin_public_notification, 'bookingor_schedule_reminder_cron');
        $this->loader->add_action('bookingor_send_reminders_cron_hook', $plugin_public_notification, 'bookingor_send_reminders_callback');
        $this->loader->add_action('wp_ajax_bookingor_api', $plugin_public_notification, 'bookingor_api_handler');
        $this->loader->add_action('wp_ajax_nopriv_bookingor_api', $plugin_public_notification, 'bookingor_api_handler');
    }

    /**
     * Run the loader to execute all of the hooks with WordPress.
     *
     * @since    1.0.0
     */
    public function run()
    {
        $this->loader->run();
    }

    /**
     * The name of the plugin used to uniquely identify it within the context of
     * WordPress and to define internationalization functionality.
     *
     * @since     1.0.0
     *
     * @return string The name of the plugin.
     */
    public function get_plugin_name()
    {
        return $this->plugin_name;
    }

    /**
     * The reference to the class that orchestrates the hooks with the plugin.
     *
     * @since     1.0.0
     *
     * @return Bookingor_Loader Orchestrates the hooks of the plugin.
     */
    public function get_loader()
    {
        return $this->loader;
    }

    /**
     * Retrieve the version number of the plugin.
     *
     * @since     1.0.0
     *
     * @return string The version number of the plugin.
     */
    public function get_version()
    {
        return $this->version;
    }
}
