<?php
class Mobile_API_Elementor_Vehicle_Archive extends \Elementor\Widget_Base {

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

	public function get_title() {
		return esc_html__( 'Vehicle Archive', 'ad-integration-for-mobile-de-api' );
	}

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

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

	public function get_keywords() {
		return [ 'cars', 'vehicles', 'archive', 'mobile' ];
	}

	protected function register_controls() {
		$this->start_controls_section(
			'section_title',
			[
				'label' => esc_html__( 'Vehicle Archive Attributes', 'ad-integration-for-mobile-de-api' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$options = [];
		$terms = get_terms([
			'taxonomy' => 'mobile_api_vehicle_category',
			'hide_empty' => false
		]);
		foreach ( $terms as $term )
			$options[$term->slug] = $term->name;

		$this->add_control(
			'category',
			[
				'label' => esc_html__( 'Vehicle Category', 'ad-integration-for-mobile-de-api' ),
				'type' => \Elementor\Controls_Manager::SELECT2,
				'label_block' => true,
				'multiple' => true,
				'default' => '',
				'options' => $options
			]
		);

		$this->end_controls_section();
	}

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

		echo wp_kses_post( mobile_api_shortcode_vehicle_archive( $atts ) );
	}
}