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

class IDSC_Elementor_Alert extends \Elementor\Widget_Base {

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

    public function get_title() {
        return __( 'Alert / Notice', 'idsc' );
    }

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

    public function get_categories() {
        return array( 'idsc' );
    }

    public function get_keywords() {
        return array( 'alert', 'notice', 'warning', 'info', 'error' );
    }

    protected function register_controls() {
        $this->start_controls_section( 'section_content', array(
            'label' => __( 'Alert', 'idsc' ),
        ) );

        $this->add_control( 'type', array(
            'label'   => __( 'Type', 'idsc' ),
            'type'    => \Elementor\Controls_Manager::SELECT,
            'default' => 'info',
            'options' => array(
                'info'    => __( 'Info', 'idsc' ),
                'success' => __( 'Success', 'idsc' ),
                'warning' => __( 'Warning', 'idsc' ),
                'error'   => __( 'Error', 'idsc' ),
            ),
        ) );

        $this->add_control( 'title', array(
            'label' => __( 'Title', 'idsc' ),
            'type'  => \Elementor\Controls_Manager::TEXT,
        ) );

        $this->add_control( 'message', array(
            'label' => __( 'Message', 'idsc' ),
            'type'  => \Elementor\Controls_Manager::TEXTAREA,
        ) );

        $this->add_control( 'dismissible', array(
            'label'        => __( 'Dismissible', 'idsc' ),
            'type'         => \Elementor\Controls_Manager::SWITCHER,
            'label_on'     => __( 'Yes', 'idsc' ),
            'label_off'    => __( 'No', 'idsc' ),
            'return_value' => 'yes',
            'default'      => '',
        ) );

        $this->add_control( 'icon', array(
            'label'        => __( 'Show Icon', 'idsc' ),
            'type'         => \Elementor\Controls_Manager::SWITCHER,
            'label_on'     => __( 'Yes', 'idsc' ),
            'label_off'    => __( 'No', 'idsc' ),
            'return_value' => 'yes',
            'default'      => 'yes',
        ) );

        $this->end_controls_section();
    }

    protected function render() {
        $s = $this->get_settings_for_display();

        $atts  = ' type="' . esc_attr( $s['type'] ) . '"';
        $atts .= ! empty( $s['title'] ) ? ' title="' . esc_attr( $s['title'] ) . '"' : '';
        $atts .= $s['dismissible'] === 'yes' ? ' dismissible="yes"' : '';
        $atts .= $s['icon'] !== 'yes' ? ' icon="no"' : '';

        echo do_shortcode( '[idsc_alert' . $atts . ']' . esc_html( $s['message'] ) . '[/idsc_alert]' );
    }
}
