<?php

namespace Elementor;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Define our Pt Elementor Call Out settings.
 */
class lawyering_elementor_banner extends Widget_Base {
	/**
	 * Define our get_name settings.
	 */
	public function get_name() {
		return 'lawyering-banner';
	}
	/**
	 * Define our get_title settings.
	 */
	public function get_title() {
		return __( 'Banner', 'lawyering' );
	}
	/**
	 * Define our get_icon settings.
	 */
	public function get_icon() {
		return 'eicon-call-to-action';
	}
	/**
	 * Define our get_categories settings.
	 */
	public function get_categories() {
		return [ 'lawyering-elementor-widget' ];
	}
	/**
	 * Define our _register_controls settings.
	 */
	protected function register_controls()
    {
        /**
         * Info Box Title and Description Section.
         */
        $this->start_controls_section(
            'lawyering_banner_section',
            [
                'label' => esc_html__('Banner Options', 'lawyering'),
            ]
        );
        $this->add_control(
            'lawyering_banner_title',
            [
                'label' => __('Enter Title', 'lawyering'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __( 'Title', 'lawyering' ),
            ]
        );

        $this->add_control(
            'lawyering_banner_desc',
            [
                'label' => __('Enter Description', 'lawyering'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __( 'Description', 'lawyering' ),
            ]
        );


        $this->add_control(
            'lawyering_banner_button_text',
            [
                'label' => __('Enter Button Text', 'lawyering'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __( 'Button Text', 'lawyering' ),
            ]
        );

        $this->add_control(
            'lawyering_banner_button_url',
            [
                'label' => __( 'Button Link', 'lawyering' ),
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => __( 'https://your-link.com', 'lawyering' ),
                'show_external' => true,
                'default' => [
                    'url' => '',
                    'is_external' => true,
                    'nofollow' => true,
                ],
            ]
        );
        $this->add_control(
            'lawyering_banner_img',
            [
                'label' => __( 'Choose Banner Background Image', 'lawyering' ),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->end_controls_section();

    }
	/**
	 * Define our Content Display inline settings.
	 */
	protected function add_inline_editing_attributes( $key, $toolbar = 'basic' ) {
		if ( ! Plugin::$instance->editor->is_edit_mode() ) {
			return;
		}
		$this->add_render_attribute( $key, [
			'class' => 'elementor-inline-editing',
			'data-elementor-setting-key' => $key,
		] );
		if ( 'basic' !== $toolbar ) {
			$this->add_render_attribute( $key, [
				'data-elementor-inline-editing-toolbar' => $toolbar,
			] );
		}
	}

	/**
	 * Define our Content Display settings.
	 */
	protected function render() {
        $settings = $this->get_settings();
        $lawyering_banner_title = $settings['lawyering_banner_title'];
        $lawyering_banner_desc = $settings['lawyering_banner_desc'];
         $lawyering_banner_button_text = $settings['lawyering_banner_button_text'];
        $lawyering_banner_img = $settings['lawyering_banner_img']['url'];
        $lawyering_banner_button_url = $settings['lawyering_banner_button_url']['url'];
        if (!empty($lawyering_banner_img)) {
            $image_style = "style='background-image:url(" . esc_url($lawyering_banner_img) . ")'";
        } else {
            $image_style = '';
        }
        ?>


        <div class="banner-section section-overlay" <?php echo wp_kses_post($image_style); ?>>
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        
                                <?php
                                if ($lawyering_banner_title)
                                    echo '<h1>' . esc_html($lawyering_banner_title) . '</h1>';

                                if ($lawyering_banner_desc)
                                    echo '<span>' . esc_html($lawyering_banner_desc) . '</span>';
          if( $lawyering_banner_button_text && $lawyering_banner_button_url):?>
                                    <a href="<?php echo esc_url($lawyering_banner_button_url); ?>" class="btn-default"><?php echo esc_html($lawyering_banner_button_text); ?></a>
                                <?php endif; ?>

                    </div>
                </div>
            </div>
        </div>

    <?php

	}
	
}
/*=============Call this every widget ====================*/
Plugin::instance()->widgets_manager->register_widget_type( new lawyering_elementor_banner() );

