<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


class TH90_T_Sidebar extends \Elementor\Widget_Base {

	public function get_name() {
		return 't-sidebar';
	}

	public function get_title() {
		return __( 'Sidebar Template', 'atlas-core' );
	}

	public function get_icon() {
		return 'eicon-sidebar th90-widget-icon';
	}

	public function get_categories() {
		return [ sanitize_key( wp_get_theme()->name ) . '-templates' ];
	}

	protected function register_controls() {

		/* Section General */
		$this->start_controls_section(
			'section_block_general',
			[
				'label' => __( 'Sidebar Template', 'atlas-core' ),
			]
		);
		$this->add_control(
			'note',
			[
				'type' => \Elementor\Controls_Manager::RAW_HTML,
				'raw' => sprintf( esc_html__( 'You can add and edit the sidebar template from %1$shere%2$s.', 'atlas-core' ), '<a href="' . admin_url('edit.php?post_type=th90_sidebar') . '" target="_blank"><strong>', '</strong></a>' ),
				//'content_classes' => 'elementor-descriptor',
				'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
			]
		);
		$this->add_control(
			'sidebar',
			[
				'label'       => esc_html__('Sidebar Template', 'atlas-core'),
				'description' => esc_html__('Select the sidebar template.', 'atlas-core'),
				'type'        => \Elementor\Controls_Manager::SELECT,
				'options'     => th90_get_query_post_list( 'th90_sidebar' ),
			]
		);

		$this->end_controls_section();

	}

	/**
	 * Render the widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 */
	protected function render() {
		$atts = $this->get_settings_for_display();

		if ( $atts['sidebar'] ) {
			echo th90_display_elementor_content( $atts['sidebar'] );
		}
	}

	/**
	 * Render the widget output in the editor.
	 *
	 * Written as a Backbone JavaScript template and used to generate the live preview.
	 */
	protected function content_template() {}
}
