<?php
if (!defined('ABSPATH')) {
    exit;
}

if (!did_action('elementor/loaded') || !class_exists('\Elementor\Widget_Base')) {
    return;
}

if (!class_exists('EEP_Elementor_Widget_Shortcode')) {
    class EEP_Elementor_Widget_Shortcode extends \Elementor\Widget_Base {
        private $eep_config = [];

        public function __construct($data = [], $args = null) {
            if (is_array($args) && isset($args['eep_config']) && is_array($args['eep_config'])) {
                $this->eep_config = $args['eep_config'];
            }
            if (!is_array($args)) {
                $args = [];
            }
            if (!is_array($data)) {
                $data = [];
            }
            parent::__construct($data, $args);
        }

        public function set_eep_config(array $config = []) {
            $this->eep_config = $config;
            return $this;
        }

        public function get_name() {
            return (string) ($this->eep_config['name'] ?? 'eep_widget');
        }

        public function get_title() {
            return (string) ($this->eep_config['title'] ?? __('Events Widget', 'nexdirectory'));
        }

        public function get_icon() {
            return (string) ($this->eep_config['icon'] ?? 'eicon-calendar');
        }

        public function get_categories() {
            return ['eep-widgets'];
        }

        protected function register_controls() {
            $controls = isset($this->eep_config['controls']) && is_array($this->eep_config['controls']) ? $this->eep_config['controls'] : [];
            if (empty($controls)) {
                return;
            }
            $this->start_controls_section('eep_widget_controls', [
                'label' => __('Widget Settings', 'nexdirectory'),
            ]);
            foreach ($controls as $key => $control) {
                if (!is_array($control)) {
                    continue;
                }
                $this->add_control($key, $control);
            }
            $this->end_controls_section();
        }

        protected function render() {
            if (!function_exists('eep_get_plugin_instance')) {
                return;
            }
            $plugin = eep_get_plugin_instance();
            if (!$plugin || !method_exists($plugin, 'render_shortcode_tag')) {
                return;
            }
            $shortcode_tag = (string) ($this->eep_config['shortcode'] ?? '');
            if ($shortcode_tag === '') {
                return;
            }
            $settings = $this->get_settings_for_display();
            $atts_map = isset($this->eep_config['atts']) && is_array($this->eep_config['atts']) ? $this->eep_config['atts'] : [];
            $atts = [];
            foreach ($atts_map as $att_key => $setting_key) {
                if (!is_string($setting_key) || $setting_key === '') {
                    continue;
                }
                if (!array_key_exists($setting_key, $settings)) {
                    continue;
                }
                $value = $settings[$setting_key];
                if (is_bool($value)) {
                    $value = $value ? 'yes' : 'no';
                } elseif (is_array($value)) {
                    if (isset($value['url'])) {
                        $value = esc_url_raw((string) $value['url']);
                    } elseif (isset($value['value'])) {
                        $value = (string) $value['value'];
                    } else {
                        $value = wp_json_encode($value);
                    }
                } else {
                    $value = (string) $value;
                }
                $atts[$att_key] = $value;
            }
            $output = $plugin->render_shortcode_tag($shortcode_tag, $atts);
            echo (string) $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        }
    }
}

if (!function_exists('eep_register_elementor_widgets')) {
    function eep_register_elementor_widgets($widgets_manager) {
        if (!is_object($widgets_manager) || !method_exists($widgets_manager, 'register')) {
            return;
        }

        $select_yes_no = [
            'type' => \Elementor\Controls_Manager::SELECT,
            'options' => [
                'yes' => __('Yes', 'nexdirectory'),
                'no' => __('No', 'nexdirectory'),
            ],
            'default' => 'yes',
        ];
        $template_options = [
            '1' => __('Template 1 - Classic', 'nexdirectory'),
            '2' => __('Template 2 - Minimal', 'nexdirectory'),
            '3' => __('Template 3 - Editorial', 'nexdirectory'),
            '4' => __('Template 4 - Split', 'nexdirectory'),
            '5' => __('Template 5 - Soft', 'nexdirectory'),
            '6' => __('Template 6 - Bold', 'nexdirectory'),
        ];
        $query_controls_common = [
            'title' => ['label' => __('Widget Title', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT],
            'subtitle' => ['label' => __('Widget Subtitle', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'rows' => 2],
            'limit' => ['label' => __('Result Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 60, 'default' => 9],
            'orderby' => [
                'label' => __('Order By', 'nexdirectory'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'start',
                'options' => [
                    'start' => __('Start Date', 'nexdirectory'),
                    'date' => __('Published Date', 'nexdirectory'),
                    'title' => __('Title', 'nexdirectory'),
                    'modified' => __('Modified Date', 'nexdirectory'),
                    'rand' => __('Random', 'nexdirectory'),
                ],
            ],
            'order' => [
                'label' => __('Sort Direction', 'nexdirectory'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'ASC',
                'options' => [
                    'ASC' => __('Ascending', 'nexdirectory'),
                    'DESC' => __('Descending', 'nexdirectory'),
                ],
            ],
            'search' => ['label' => __('Keyword Query', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('ai summit', 'nexdirectory')],
            'event_type' => ['label' => __('Event Type Slugs', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('conference,workshop', 'nexdirectory')],
            'event_mode' => ['label' => __('Event Mode Slugs', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('in-person,online-stream-event', 'nexdirectory')],
            'event_tag' => ['label' => __('Event Tag Slugs', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('ai,manufacturing', 'nexdirectory')],
            'event_price' => ['label' => __('Price Range Slugs', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('free,paid', 'nexdirectory')],
            'city' => ['label' => __('City Contains', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('London', 'nexdirectory')],
            'date_from' => ['label' => __('From Date (YYYY-MM-DD)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => date('Y-m-d')],
            'official' => [
                'label' => __('Official Status', 'nexdirectory'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '',
                'options' => [
                    '' => __('Any', 'nexdirectory'),
                    '1' => __('Official Only', 'nexdirectory'),
                    '0' => __('Unofficial Only', 'nexdirectory'),
                ],
            ],
            'include_past' => array_merge($select_yes_no, ['label' => __('Include Past Listings', 'nexdirectory'), 'default' => 'no']),
            'custom_taxonomy' => ['label' => __('Custom Taxonomy Slug', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('event_topic', 'nexdirectory')],
            'custom_terms' => ['label' => __('Custom Taxonomy Term Slugs', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('robotics,energy', 'nexdirectory')],
            'tax_relation' => [
                'label' => __('Taxonomy Relation', 'nexdirectory'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'AND',
                'options' => [
                    'AND' => __('AND (match all)', 'nexdirectory'),
                    'OR' => __('OR (match any)', 'nexdirectory'),
                ],
            ],
        ];
        $style_controls_common = [
            'columns_desktop' => ['label' => __('Columns Desktop', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 6, 'default' => 3],
            'columns_tablet' => ['label' => __('Columns Tablet', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 4, 'default' => 2],
            'columns_mobile' => ['label' => __('Columns Mobile', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 2, 'default' => 1],
            'gap' => ['label' => __('Card Gap (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 64, 'default' => 24],
            'radius' => ['label' => __('Card Radius (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 48, 'default' => 18],
            'image_height' => ['label' => __('Image Height (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 120, 'max' => 520, 'default' => 220],
            'accent_color' => ['label' => __('Accent Color', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
            'bg_color' => ['label' => __('Card Background', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
            'text_color' => ['label' => __('Text Color', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
            'custom_class' => ['label' => __('Custom CSS Class', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT],
            'custom_css' => ['label' => __('Custom CSS (use {{WRAPPER}})', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'rows' => 8],
        ];
        $query_atts_common = [
            'title' => 'title',
            'subtitle' => 'subtitle',
            'limit' => 'limit',
            'orderby' => 'orderby',
            'order' => 'order',
            'search' => 'search',
            'event_type' => 'event_type',
            'event_mode' => 'event_mode',
            'event_tag' => 'event_tag',
            'event_price' => 'event_price',
            'city' => 'city',
            'date_from' => 'date_from',
            'official' => 'official',
            'include_past' => 'include_past',
            'custom_taxonomy' => 'custom_taxonomy',
            'custom_terms' => 'custom_terms',
            'tax_relation' => 'tax_relation',
        ];
        $style_atts_common = [
            'columns_desktop' => 'columns_desktop',
            'columns_tablet' => 'columns_tablet',
            'columns_mobile' => 'columns_mobile',
            'gap' => 'gap',
            'radius' => 'radius',
            'image_height' => 'image_height',
            'accent_color' => 'accent_color',
            'bg_color' => 'bg_color',
            'text_color' => 'text_color',
            'custom_class' => 'custom_class',
            'custom_css' => 'custom_css',
        ];

        $widgets = [
            [
                'name' => 'eep_events_archive',
                'title' => __('Events Archive', 'nexdirectory'),
                'icon' => 'eicon-post-list',
                'shortcode' => 'eep_events_archive',
                'atts' => ['posts_per_page' => 'posts_per_page', 'show_sidebar' => 'show_sidebar'],
                'controls' => [
                    'posts_per_page' => ['label' => __('Posts Per Page', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 100, 'default' => 12],
                    'show_sidebar' => array_merge(['label' => __('Show Filters Sidebar', 'nexdirectory')], $select_yes_no),
                ],
            ],
            [
                'name' => 'eep_events_map',
                'title' => __('Events Map', 'nexdirectory'),
                'icon' => 'eicon-google-maps',
                'shortcode' => 'eep_events_map',
                'atts' => [
                    'max_events' => 'max_events',
                    'show_sidebar' => 'show_sidebar',
                    'show_search' => 'show_search',
                    'show_type' => 'show_type',
                    'show_mode' => 'show_mode',
                    'show_tag' => 'show_tag',
                    'show_price' => 'show_price',
                    'show_official' => 'show_official',
                    'show_date' => 'show_date',
                    'show_distance' => 'show_distance',
                    'show_list' => 'show_list',
                    'map_height' => 'map_height',
                    'view' => 'view',
                    'density' => 'density',
                ],
                'controls' => [
                    'max_events' => ['label' => __('Max Events', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 1000, 'default' => 200],
                    'map_height' => ['label' => __('Map Height (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 280, 'max' => 1400, 'default' => 620],
                    'view' => [
                        'label' => __('View', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '',
                        'options' => [
                            '' => __('Use Global Setting', 'nexdirectory'),
                            'default' => __('Map Default View', 'nexdirectory'),
                            'triple' => __('Triple View', 'nexdirectory'),
                        ],
                    ],
                    'density' => [
                        'label' => __('Results Density', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '',
                        'options' => [
                            '' => __('Use Global Setting', 'nexdirectory'),
                            'comfortable' => __('Comfortable', 'nexdirectory'),
                            'compact' => __('Compact', 'nexdirectory'),
                        ],
                    ],
                    'show_sidebar' => array_merge(['label' => __('Show Filter Sidebar', 'nexdirectory')], $select_yes_no),
                    'show_list' => array_merge(['label' => __('Show Results List/Grid', 'nexdirectory')], $select_yes_no),
                    'show_search' => array_merge(['label' => __('Show Search Filter', 'nexdirectory')], $select_yes_no),
                    'show_type' => array_merge(['label' => __('Show Event Type Filter', 'nexdirectory')], $select_yes_no),
                    'show_mode' => array_merge(['label' => __('Show Event Mode Filter', 'nexdirectory')], $select_yes_no),
                    'show_tag' => array_merge(['label' => __('Show Tag Filter', 'nexdirectory')], $select_yes_no),
                    'show_price' => array_merge(['label' => __('Show Price Filter', 'nexdirectory')], $select_yes_no),
                    'show_official' => array_merge(['label' => __('Show Official Filter', 'nexdirectory')], $select_yes_no),
                    'show_date' => array_merge(['label' => __('Show Date Filter', 'nexdirectory')], $select_yes_no),
                    'show_distance' => array_merge(['label' => __('Show Distance Filter', 'nexdirectory')], $select_yes_no),
                ],
            ],
            [
                'name' => 'eep_events_calendar',
                'title' => __('Events Calendar', 'nexdirectory'),
                'icon' => 'eicon-calendar',
                'shortcode' => 'eep_events_calendar',
                'atts' => [],
                'controls' => [],
            ],
            [
                'name' => 'eep_events_query_grid',
                'title' => __('Events Query Grid', 'nexdirectory'),
                'icon' => 'eicon-posts-grid',
                'shortcode' => 'eep_events_query_grid',
                'atts' => array_merge($query_atts_common, $style_atts_common, [
                    'template' => 'template',
                    'show_excerpt' => 'show_excerpt',
                    'show_meta' => 'show_meta',
                    'excerpt_length' => 'excerpt_length',
                ]),
                'controls' => array_merge($query_controls_common, [
                    'template' => [
                        'label' => __('Grid Template', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '1',
                        'options' => $template_options,
                    ],
                    'show_excerpt' => array_merge(['label' => __('Show Excerpt', 'nexdirectory')], $select_yes_no),
                    'show_meta' => array_merge(['label' => __('Show Date/Location Meta', 'nexdirectory')], $select_yes_no),
                    'excerpt_length' => ['label' => __('Excerpt Length (words)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 8, 'max' => 70, 'default' => 20],
                ], $style_controls_common),
            ],
            [
                'name' => 'eep_events_bento_grid',
                'title' => __('Events Bento Grid', 'nexdirectory'),
                'icon' => 'eicon-gallery-grid',
                'shortcode' => 'eep_events_bento_grid',
                'atts' => array_merge($query_atts_common, $style_atts_common, [
                    'template' => 'template',
                    'show_excerpt' => 'show_excerpt',
                    'show_meta' => 'show_meta',
                    'excerpt_length' => 'excerpt_length',
                    'hover_effect' => 'hover_effect',
                ]),
                'controls' => array_merge($query_controls_common, [
                    'template' => [
                        'label' => __('Bento Template', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '1',
                        'options' => $template_options,
                    ],
                    'hover_effect' => [
                        'label' => __('Hover Effect', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => 'lift',
                        'options' => [
                            'lift' => __('Lift', 'nexdirectory'),
                            'zoom' => __('Zoom', 'nexdirectory'),
                            'glow' => __('Glow', 'nexdirectory'),
                            'tilt' => __('Tilt', 'nexdirectory'),
                        ],
                    ],
                    'show_excerpt' => array_merge(['label' => __('Show Excerpt', 'nexdirectory')], $select_yes_no),
                    'show_meta' => array_merge(['label' => __('Show Date/Location Meta', 'nexdirectory')], $select_yes_no),
                    'excerpt_length' => ['label' => __('Excerpt Length (words)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 8, 'max' => 70, 'default' => 18],
                ], $style_controls_common),
            ],
            [
                'name' => 'eep_events_ajax_search',
                'title' => __('Events AJAX Search', 'nexdirectory'),
                'icon' => 'eicon-search',
                'shortcode' => 'eep_events_ajax_search',
                'atts' => [
                    'title' => 'title',
                    'subtitle' => 'subtitle',
                    'template' => 'template',
                    'limit' => 'limit',
                    'min_chars' => 'min_chars',
                    'search_placeholder' => 'search_placeholder',
                    'orderby' => 'orderby',
                    'order' => 'order',
                    'search' => 'search',
                    'event_type' => 'event_type',
                    'event_mode' => 'event_mode',
                    'event_tag' => 'event_tag',
                    'event_price' => 'event_price',
                    'city' => 'city',
                    'date_from' => 'date_from',
                    'official' => 'official',
                    'custom_taxonomy' => 'custom_taxonomy',
                    'custom_terms' => 'custom_terms',
                    'tax_relation' => 'tax_relation',
                    'include_past' => 'include_past',
                    'show_type' => 'show_type',
                    'show_mode' => 'show_mode',
                    'show_tag' => 'show_tag',
                    'show_price' => 'show_price',
                    'show_city' => 'show_city',
                    'show_date' => 'show_date',
                    'show_official' => 'show_official',
                    'show_excerpt' => 'show_excerpt',
                    'show_meta' => 'show_meta',
                    'excerpt_length' => 'excerpt_length',
                    'gap' => 'gap',
                    'radius' => 'radius',
                    'accent_color' => 'accent_color',
                    'bg_color' => 'bg_color',
                    'text_color' => 'text_color',
                    'custom_class' => 'custom_class',
                    'custom_css' => 'custom_css',
                ],
                'controls' => array_merge($query_controls_common, [
                    'template' => [
                        'label' => __('Search Template', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '1',
                        'options' => $template_options,
                    ],
                    'min_chars' => ['label' => __('Min Search Characters', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 8, 'default' => 2],
                    'search_placeholder' => ['label' => __('Search Placeholder', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __('Search listings by keyword...', 'nexdirectory')],
                    'show_type' => array_merge(['label' => __('Show Type Filter', 'nexdirectory')], $select_yes_no),
                    'show_mode' => array_merge(['label' => __('Show Mode Filter', 'nexdirectory')], $select_yes_no),
                    'show_tag' => array_merge(['label' => __('Show Tag Filter', 'nexdirectory')], $select_yes_no),
                    'show_price' => array_merge(['label' => __('Show Price Filter', 'nexdirectory')], $select_yes_no),
                    'show_city' => array_merge(['label' => __('Show City Filter', 'nexdirectory')], $select_yes_no),
                    'show_date' => array_merge(['label' => __('Show Date Filter', 'nexdirectory')], $select_yes_no),
                    'show_official' => array_merge($select_yes_no, ['label' => __('Show Official Filter', 'nexdirectory'), 'default' => 'no']),
                    'show_excerpt' => array_merge($select_yes_no, ['label' => __('Show Excerpt in Results', 'nexdirectory'), 'default' => 'no']),
                    'show_meta' => array_merge(['label' => __('Show Date/Location Meta', 'nexdirectory')], $select_yes_no),
                    'excerpt_length' => ['label' => __('Excerpt Length (words)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 8, 'max' => 70, 'default' => 14],
                    'gap' => ['label' => __('Row Gap (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 40, 'default' => 14],
                    'radius' => ['label' => __('Row Radius (px)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 40, 'default' => 14],
                    'accent_color' => ['label' => __('Accent Color', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
                    'bg_color' => ['label' => __('Row Background', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
                    'text_color' => ['label' => __('Text Color', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::COLOR],
                    'custom_class' => ['label' => __('Custom CSS Class', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXT],
                    'custom_css' => ['label' => __('Custom CSS (use {{WRAPPER}})', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'rows' => 8],
                ]),
            ],
            [
                'name' => 'eep_event_chatbot',
                'title' => __('AI Chatbot', 'nexdirectory'),
                'icon' => 'eicon-comments',
                'shortcode' => 'eep_event_chatbot',
                'atts' => [
                    'position' => 'position',
                    'position_desktop' => 'position_desktop',
                    'position_mobile' => 'position_mobile',
                    'name' => 'name',
                    'welcome' => 'welcome',
                    'theme_color' => 'theme_color',
                    'text_color' => 'text_color',
                ],
                'controls' => [
                    'position' => [
                        'label' => __('Legacy Position Override', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '',
                        'options' => [
                            '' => __('Use Global Setting', 'nexdirectory'),
                            'bottom-right' => __('Bottom Right (Floating)', 'nexdirectory'),
                            'bottom-left' => __('Bottom Left (Floating)', 'nexdirectory'),
                            'inline' => __('Inline Block', 'nexdirectory'),
                        ],
                    ],
                    'position_desktop' => [
                        'label' => __('Desktop Position', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '',
                        'options' => [
                            '' => __('Use Global Setting', 'nexdirectory'),
                            'bottom-right' => __('Bottom Right (Floating)', 'nexdirectory'),
                            'bottom-left' => __('Bottom Left (Floating)', 'nexdirectory'),
                            'right-edge-center' => __('Right Edge Center', 'nexdirectory'),
                            'left-edge-center' => __('Left Edge Center', 'nexdirectory'),
                            'inline' => __('Inline Block', 'nexdirectory'),
                        ],
                    ],
                    'position_mobile' => [
                        'label' => __('Mobile Position', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '',
                        'options' => [
                            '' => __('Use Global Setting', 'nexdirectory'),
                            'right-edge-center' => __('Right Edge Center + Centered Panel', 'nexdirectory'),
                            'left-edge-center' => __('Left Edge Center + Centered Panel', 'nexdirectory'),
                            'bottom-center' => __('Bottom Center', 'nexdirectory'),
                            'bottom-right' => __('Bottom Right', 'nexdirectory'),
                            'bottom-left' => __('Bottom Left', 'nexdirectory'),
                            'inline' => __('Inline Block', 'nexdirectory'),
                        ],
                    ],
                    'name' => [
                        'label' => __('Bot Name Override', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::TEXT,
                        'placeholder' => __('Listing Assistant', 'nexdirectory'),
                    ],
                    'welcome' => [
                        'label' => __('Welcome Text Override', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::TEXTAREA,
                        'rows' => 3,
                    ],
                    'theme_color' => [
                        'label' => __('Accent Color Override', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::COLOR,
                    ],
                    'text_color' => [
                        'label' => __('Header Text Color Override', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::COLOR,
                    ],
                ],
            ],
            [
                'name' => 'eep_submit_event',
                'title' => __('Submit Listing Form', 'nexdirectory'),
                'icon' => 'eicon-form-horizontal',
                'shortcode' => 'eep_submit_event',
                'atts' => ['show_nav' => 'show_nav'],
                'controls' => ['show_nav' => array_merge(['label' => __('Show Section Nav', 'nexdirectory')], $select_yes_no)],
            ],
            [
                'name' => 'eep_my_events',
                'title' => __('My Listings', 'nexdirectory'),
                'icon' => 'eicon-table',
                'shortcode' => 'eep_my_events',
                'atts' => ['limit' => 'limit'],
                'controls' => ['limit' => ['label' => __('Row Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 500, 'default' => 30]],
            ],
            [
                'name' => 'eep_my_tickets',
                'title' => __('Saved Listings', 'nexdirectory'),
                'icon' => 'eicon-check-circle',
                'shortcode' => 'eep_my_tickets',
                'atts' => ['limit' => 'limit'],
                'controls' => ['limit' => ['label' => __('Row Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 500, 'default' => 50]],
            ],
            [
                'name' => 'eep_owner_analytics',
                'title' => __('Owner Analytics', 'nexdirectory'),
                'icon' => 'eicon-chart-area',
                'shortcode' => 'eep_owner_analytics',
                'atts' => ['days' => 'days'],
                'controls' => [
                    'days' => [
                        'label' => __('Default Reporting Window', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'default' => '30',
                        'options' => [
                            '7' => __('Last 7 days', 'nexdirectory'),
                            '30' => __('Last 30 days', 'nexdirectory'),
                            '90' => __('Last 90 days', 'nexdirectory'),
                            '365' => __('Last 12 months', 'nexdirectory'),
                        ],
                    ],
                ],
            ],
            [
                'name' => 'eep_account',
                'title' => __('Account', 'nexdirectory'),
                'icon' => 'eicon-user-circle-o',
                'shortcode' => 'eep_account',
                'atts' => [],
                'controls' => [],
            ],
            [
                'name' => 'eep_auth',
                'title' => __('Auth (Login / Signup)', 'nexdirectory'),
                'icon' => 'eicon-lock-user',
                'shortcode' => 'eep_auth',
                'atts' => ['redirect_to' => 'redirect_to'],
                'controls' => [
                    'redirect_to' => ['label' => __('Redirect URL', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::URL, 'show_external' => false, 'placeholder' => home_url('/')],
                ],
            ],
            [
                'name' => 'eep_auth_links',
                'title' => __('Auth Buttons / Menu', 'nexdirectory'),
                'icon' => 'eicon-menu-bar',
                'shortcode' => 'eep_auth_links',
                'atts' => ['redirect_to' => 'redirect_to', 'show_logout' => 'show_logout'],
                'controls' => [
                    'redirect_to' => ['label' => __('Redirect URL', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::URL, 'show_external' => false, 'placeholder' => home_url('/')],
                    'show_logout' => array_merge(['label' => __('Show Logout In Dropdown', 'nexdirectory')], $select_yes_no),
                ],
            ],
            [
                'name' => 'eep_user_management',
                'title' => __('User Management', 'nexdirectory'),
                'icon' => 'eicon-users',
                'shortcode' => 'eep_user_management',
                'atts' => ['limit' => 'limit'],
                'controls' => ['limit' => ['label' => __('User Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 500, 'default' => 100]],
            ],
            [
                'name' => 'eep_moderation_queue',
                'title' => __('Moderation Queue', 'nexdirectory'),
                'icon' => 'eicon-review',
                'shortcode' => 'eep_moderation_queue',
                'atts' => ['pending_limit' => 'pending_limit', 'reports_limit' => 'reports_limit'],
                'controls' => [
                    'pending_limit' => ['label' => __('Pending Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 500, 'default' => 100],
                    'reports_limit' => ['label' => __('Reports Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 200, 'default' => 30],
                ],
            ],
            [
                'name' => 'eep_organizers',
                'title' => __('Organizers', 'nexdirectory'),
                'icon' => 'eicon-person',
                'shortcode' => 'eep_organizers',
                'atts' => ['limit' => 'limit', 'verified_only' => 'verified_only'],
                'controls' => [
                    'limit' => ['label' => __('Organizer Limit', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 1, 'max' => 500, 'default' => 200],
                    'verified_only' => [
                        'label' => __('Verified Organizers Only', 'nexdirectory'),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'options' => [
                            'no' => __('No', 'nexdirectory'),
                            'yes' => __('Yes', 'nexdirectory'),
                        ],
                        'default' => 'no',
                    ],
                ],
            ],
            [
                'name' => 'eep_claim_listing',
                'title' => __('Claim Listing', 'nexdirectory'),
                'icon' => 'eicon-site-search',
                'shortcode' => 'eep_claim_listing',
                'atts' => ['event_id' => 'event_id'],
                'controls' => [
                    'event_id' => ['label' => __('Event ID (optional)', 'nexdirectory'), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'default' => 0],
                ],
            ],
        ];

        foreach ($widgets as $config) {
            $widget = new EEP_Elementor_Widget_Shortcode([], ['eep_config' => (array) $config]);
            $widgets_manager->register($widget);
        }
    }
}
