<?php

namespace Bookingor\Integrations\Elementor;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Control_Media;
use Elementor\Control_Color;


class BookingorElementorTemplateWidget extends Widget_Base
{
    public $version =   BOOKINGOR_VERSION;
    public $plugin_name = 'bookingor';

    public function get_name()
    {
        return 'bookingor_design_template_widget';
    }

    public function get_title()
    {
        return __('Bookingor UI Designs', 'bookingor');
    }


    public function get_icon()
    {
        return 'eicon-kit-parts';
    }

    public function get_categories()
    {
        return ['general'];
    }

    protected function _register_controls()
    {
        $this->start_controls_section(
            'section_button',
            [
                'label' => __('Design Templates', 'bookingor'),
            ]
        );

        $this->add_control(
            'bookingor_design_bookings',
            [
                'label' => __('Bookingor Designs', 'bookingor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'design_one' => __('Design 1', 'bookingor'),
                    'design_two' => __('Design 2', 'bookingor'),
                    'design_three' => __('Design 3', 'bookingor'),
                    'design_four' => __('Design 4', 'bookingor'),
                    'design_five' => __('Design 5', 'bookingor'),
                    'design_six' => __('Design 6', 'bookingor'),
                ],
                'default' => 'design_two',
            ]
        );

        $this->end_controls_section();

        // Style Section

    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings['content'] = '[BOOKINGOR_DESIGN_2]'; // Set the content property
        $ajax_nonce = wp_create_nonce('bookingor_ajax_nonce');
        $base_url = plugin_dir_url(dirname(dirname(__FILE__)));
?>
        <script type="text/javascript">
            if (typeof TCN_BIND_FRONT === 'undefined') {
                window.TCN_BIND_FRONT = {
                    GET_URL: '<?php echo esc_url(admin_url('admin-ajax.php')); ?>',
                    nonce: '<?php echo esc_js($ajax_nonce); ?>'
                };
            }
        </script>
        <?php

        if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
            wp_enqueue_script('jquery-ui-slider');
            $shortcode = '';
            switch ($settings['bookingor_design_bookings']) {
                case 'design_one':
                    $shortcode = '[BOOKINGOR_DESIGN_1]';
                    break;
                case 'design_two':
                    $shortcode = '[BOOKINGOR_DESIGN_2]';
                    break;
                case 'design_three':
                    $shortcode = '[BOOKINGOR_DESIGN_3]';
                    break;
                case 'design_four':
                    $shortcode = '[BOOKINGOR_DESIGN_4]';
                    break;
                case 'design_five':
                    $shortcode = '[BOOKINGOR_DESIGN_5]';
                    break;
                case 'design_six':
                    $shortcode = '[BOOKINGOR_DESIGN_6]';
                    break;
                default:
                    $shortcode = 'Default modal content';
                    break;
            }
        ?>
            <script type="text/javascript">
                (function($) {
                    if (typeof $.fn.calendar === 'undefined') {
                        $.fn.calendar = function() {
                            this.getSelectedDate = function() {
                                return new Date();
                            };
                            this.getTimezone = function() {
                                return '';
                            };
                            return this;
                        };
                    }
                    if (typeof $.fn.slider === 'undefined') {
                        $.fn.slider = function(action, index) {
                            if (action === 'values') {
                                if (typeof index === 'number') {
                                    return index === 0 ? 0 : 500;
                                }
                                return [0, 500];
                            }
                            return this;
                        };
                    }
                })(jQuery);
            </script>
            <div class="bookingor-template-preview-card" style="
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                padding: 40px 20px;
                background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
                border: 2px dashed #a0aec0;
                border-radius: 12px;
                box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
                text-align: center;
                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
                max-width: 500px;
                margin: 30px auto;
            ">
                <p style="
                    margin: 0 0 20px 0;
                    color: #718096;
                    font-size: 13px;
                    line-height: 1.5;
                ">
                    Your are in the Elementor Editor. Booking will load on published page or in a preview page
                </p>
                <div style="
                    background: #ffffff;
                    border: 1px solid #e2e8f0;
                    border-radius: 8px;
                    padding: 12px 24px;
                    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
                    font-size: 14px;
                    color: #2b6cb0;
                    font-weight: 600;
                    letter-spacing: 0.05em;
                    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
                ">
                    <?php echo esc_html($shortcode); ?>
                </div>
            </div>
<?php
            return;
        }

        // Switch case for modal body content
        switch ($settings['bookingor_design_bookings']) {
            case 'design_one':
                wp_enqueue_style($this->plugin_name . '-design-1', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-1/design-1.css', [], $this->version, "all");
                wp_enqueue_style($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);
                wp_enqueue_script($this->plugin_name . '-design-1', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/js/design-1/design-1.js', ['jquery'], $this->version, true);

                echo do_shortcode('[BOOKINGOR_DESIGN_1]');
                break;
            case 'design_two':
                wp_enqueue_style($this->plugin_name . '-design-2', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-2/design-2.css', [], $this->version, "all");
                wp_enqueue_style($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-design-2-js', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/js/design-2/design-2.js', ['jquery'], $this->version, true);

                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);

                echo do_shortcode('[BOOKINGOR_DESIGN_2]');
                break;
            case 'design_three':
                wp_enqueue_style($this->plugin_name . '-design-3', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-3/design-3.css', [], $this->version, "all");
                wp_enqueue_style($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-design-3', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/js/design-3/design-3.js', ['jquery'], $this->version, true);

                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);

                echo do_shortcode('[BOOKINGOR_DESIGN_3]');
                break;
            case 'design_four':
                wp_enqueue_style($this->plugin_name . '-bootstraps', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style($this->plugin_name . '-design-4', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-4/design-4.css', [], $this->version, "all");
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-design-4', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/js/design-4/design-4.js', ['jquery'], $this->version, true);
                wp_localize_script($this->plugin_name . '-design-4', 'TCN_BIND_FRONT', array('GET_URL' => admin_url('admin-ajax.php')));
                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);

                echo do_shortcode('[BOOKINGOR_DESIGN_4]');
                break;
            case 'design_five':
                wp_enqueue_style($this->plugin_name . '-design-5', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-5/design-5.css', [], $this->version, "all");
                wp_enqueue_style($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-slick', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/slick/slick.js', ['jquery'], $this->version, true);
                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);

                echo do_shortcode('[BOOKINGOR_DESIGN_5]');
                break;
            case 'design_six':
                wp_enqueue_style($this->plugin_name . '-design-6', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/css/design-6/design-6.css', [], $this->version, "all");
                wp_enqueue_style($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.min.css', [], '5.3.3', 'all');
                wp_enqueue_style('jquery-ui-slider', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/jquery/jquery-ui.css', [], '1.12.1', 'all');
                wp_enqueue_script($this->plugin_name . '-design-6', plugin_dir_url(dirname(dirname(__FILE__))) . 'Frontend/assets/js/design-6/design-6.js', ['jquery'], $this->version, true);

                wp_enqueue_script($this->plugin_name . '-bootstrap', plugin_dir_url(dirname(dirname(__FILE__))) . 'includes/bootstrap/bootstrap.bundle.min.js', ['jquery'], '5.3.3', true);

                echo do_shortcode('[BOOKINGOR_DESIGN_6]');
                break;
            default:
                echo 'Default modal content';
                break;
        }
    }
}
