<?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 BookingorElementorStarterWidget extends Widget_Base
{
    public $version =   BOOKINGOR_VERSION;
    public $plugin_name = 'bookingor';

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

    public function get_title()
    {
        return __('Bookingor Starter Design', 'bookingor');
    }


    public function get_icon()
    {
        return 'eicon-info-box';
    }

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

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

        $this->add_control(
            'bookingor_starter_bookings',
            [
                'label' => __('Bookingor Starter', 'bookingor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'design_service' => __('Services', 'bookingor'),
                    'design_staff' => __('Staff', 'bookingor'),
                    'design_category' => __('Category', 'bookingor'),
                ],
                'default' => 'design_service'
            ]
        );

        $this->end_controls_section();

        // Style Section

    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $ajax_nonce = wp_create_nonce('bookingor_ajax_nonce');
        $base_url = plugin_dir_url(dirname(dirname(__FILE__)));
?>
        <script type="text/javascript">
            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_starter_bookings']) {
                case 'design_service':
                    $shortcode = '[BOOKINGOR_START_SERVICE]';
                    break;
                case 'design_staff':
                    $shortcode = '[BOOKINGOR_START_STAFF]';
                    break;
                case 'design_category':
                    $shortcode = '[BOOKINGOR_START_CATEGORY]';
                    break;
                case 'design_6':
                    $shortcode = '[BOOKINGOR_DESIGN_6]';
                    break;
                default:
                    $shortcode = 'Default modal content';
                    break;
            }
        ?>

            <div class="bookingor-starter-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;
                ">
                    You are in the Elementor Editor. Preview is displayed in actual page and load on published 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 ($settings['bookingor_starter_bookings']) {
            case 'design_service':
                echo do_shortcode('[BOOKINGOR_START_SERVICE]');
                break;
            case 'design_staff':
                echo do_shortcode('[BOOKINGOR_START_STAFF]');
                break;
            case 'design_category':
                echo do_shortcode('[BOOKINGOR_START_CATEGORY]');
                break;
            case 'design_6':
                echo do_shortcode('[BOOKINGOR_DESIGN_6]');
                break;
            default:
                echo 'Default modal content';
                break;
        }
    }
}
