<?php

namespace Bookingor\Integrations\Elementor;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;

class BookingorElementorWidget extends Widget_Base
{

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

    public function get_title()
    {
        return esc_html__('Bookingor Widget', 'bookingor');
    }

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

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

    protected function _register_controls()
    {
        $this->start_controls_section(
            'section_button',
            [
                'label' => esc_html__('Button', 'bookingor'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'button_text',
            [
                'label' => esc_html__('Button Text', 'bookingor'),
                'type' => Controls_Manager::TEXT,
                'default' => '',
            ]
        );

        $this->add_control(
            'button_url',
            [
                'label' => esc_html__('Button URL', 'bookingor'),
                'type' => Controls_Manager::URL,
                'default' => '',
            ]
        );

        $this->add_control(
            'button_type',
            [
                'label' => esc_html__('Button Type', 'bookingor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'primary' => esc_html__('Primary', 'bookingor'),
                    'secondary' => esc_html__('Secondary', 'bookingor'),
                ],
                'default' => 'primary',
            ]
        );

        $this->end_controls_section();
    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        echo '<a href="' . esc_url($settings['button_url']['url']) . '" class="elementor-button elementor-button-' . esc_attr($settings['button_type']) . '">';
        echo esc_html($settings['button_text']);
        echo '</a>';
    }
}
