<?php
/*
 * Element: Store Location Map
 */
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Utils;
use Elementor\Group_Control_Typography;
use Elementor\Modules\DynamicTags\Module as TagsModule;
class PLS_Elementor_Store_Location_Map extends PLS_Elementor_Widget_Base {
	/**
	 * Retrieve the widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
        return 'pls-store-location-map';
    }

	/**
     * Get widget title.
     *
     * Retrieve Store Location Map widget title.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Store Location Map', 'modave-core' );
    }

    /**
     * Get widget icon.
     *
     * Retrieve Team widget icon.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'pls-icon eicon-google-maps';
    }
	
	/**
     * Register Team widget controls.
     *
     * Adds different input fields to allow the user to change and customize the widget settings.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function register_controls() {
		
		$this->start_controls_section(
			'section_content_tab',
			array(
				'label'     => esc_html__( 'Store Location List', 'modave-core' ),
				'tab'       => Controls_Manager::TAB_CONTENT,
			)
		);	
		$this->add_control(
            'location_view_mode',
            [
                'label' 	=> esc_html__( 'Location View Mode', 'modave-core' ),
                'type' 		=> Controls_Manager::SELECT,
                'options' 	=> [
					'horizontal'	=> esc_html__( 'Horizontal', 'modave-core' ),
					'vertical'		=> esc_html__( 'Vertical', 'modave-core' ),
				],
				'default' 	=> 'horizontal',				
            ]
        );
		$repeater = new Repeater();
		$repeater->add_control(
			'title',
			[
				'label' 		=> esc_html__( 'Store Title', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter Store Title.', 'modave-core' ),
				'dynamic' 		=> [
					'active' 	=> true,
				],
			]
		);
		$repeater->add_control(
			'email',
			[
				'label' 		=> esc_html__( 'Email', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter store email.', 'modave-core' ),
			]
		);
		$repeater->add_control(
			'phone',
			[
				'label' 		=> esc_html__( 'Phone', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter store phone number.', 'modave-core' ),
			]
		);
		$repeater->add_control(
			'address',
			[
				'label' 		=> esc_html__( 'Store Address', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXTAREA,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter Store Address.', 'modave-core' ),			
				'dynamic' => [
					'active' => true,
					'categories' => [
						TagsModule::POST_META_CATEGORY,
					],
				],
				'ai' => [
					'active' => false,
				],
			]
		);
		$this->add_control(
            'store_lists',
            [
                'label' 	=> esc_html__( 'Store Location List', 'modave-core' ),
                'type' 		=> Controls_Manager::REPEATER,
				'fields' 	=> $repeater->get_controls(),
				'default' 	=> [
					[
						'title' 	=> 'New York Office',
						'address' 	=> '432 Park Avenue, New York, New York',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 666 234 8888',
					],
					[
						'title' 	=> 'Houston Office',
						'address' 	=> '789 Main Street, Houston, Texas',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 713 432 8765',
					],
					[
						'title' 	=> 'San Francisco Office',
						'address' 	=> '321 Market Street, San Francisco, California',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 415 987 6543',
					],
					[
						'title' 	=> 'Miami Office',
						'address' 	=> '654 Ocean Drive, Miami, Florida',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 305 543 2109',
					],
				],
				'title_field' => '{{{ title }}}',
            ]
        );		
		
		$this->add_control(
			'map_zoom',
			[
				'label' 	=> esc_html__( 'Map Zoom', 'modave-core' ),
				'type' 		=> Controls_Manager::SLIDER,
				'range' 	=> [
					'px' => [
						'min' 	=> 1,
						'max' 	=> 20,
					],
				],
				'default' 	=> [
					'size' 	=> 10,
				],
				'separator' => 'before',
			]
		);

		$this->add_responsive_control(
			'map_height',
			[
				'label' 	=> esc_html__( 'Map Height', 'modave-core' ),
				'type' 		=> Controls_Manager::SLIDER,
				'range' 	=> [
					'px' 	=> [
						'min' => 40,
						'max' => 1260,
					],
				],
				'size_units' 	=> [ 'px', 'em', 'rem', 'vh', 'custom' ],
				'default' 		=> [ 'unit' => 'px', 'size' => 450 ],
				'selectors' 	=> [
					'{{WRAPPER}} .pls-location-map iframe' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);
		
		$this->end_controls_section();		
		
		$this->start_controls_section(
			'style_section',
			[
				'label' => esc_html__( 'Style', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);		
		$this->add_responsive_control(
			'section_gap',
			[
				'label'			=> esc_html__( 'Gap', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ 'px', 'em', 'rem', 'vh', '%' ],
				'selectors'		=> [
					'{{WRAPPER}} .pls-store-location-map .section-content' => 'gap: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->end_controls_section();		
	}
	
	protected function render() {
		
		$settings = $this->get_settings();
		
		extract( $settings );
		
		$settings['id'] 	= pls_uniqid( 'pls-store-location-map-' );
		$class				= array( 'pls-element', 'pls-store-location-map' );		
		$class[]			= 'pls-location-map-'.$location_view_mode;
		$settings['class']	= implode( ' ', $class );
		$id_int 			= substr( $this->get_id_int(), 0, 3 );
		$settings['id_int'] 	= $id_int;
		if ( 0 === absint( $settings['map_zoom']['size'] ) ) {
			$settings['map_zoom']['size'] = 10;
		}
		$settings['zoom_map'] = $settings['map_zoom']['size'];
		pls_core_get_templates( 'elements-widgets/store-location-map', $settings );
	}
}

$widgets_manager->register( new PLS_Elementor_Store_Location_Map() );