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

	/**
     * Get widget title.
     *
     * Retrieve Store Location widget title.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Store Location', '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-map-pin';
    }
	
	/**
     * 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() {
		
		$image_sizes 		= pls_core_get_all_image_sizes(true);
		$this->start_controls_section(
            'content_section',
            [
                'label' => esc_html__( 'General', 'modave-core' ),
            ]
        );
		$this->add_control(
            'img_size',
            [
                'label' 		=> esc_html__( 'Store Image size', 'modave-core' ),
                'type' 			=> Controls_Manager::SELECT,
                'options' 		=> $image_sizes,
                'default'		=> 'full',
				'description'	=> esc_html__( 'Select image size.', 'modave-core' ),
            ]
        );
		$this->end_controls_section();
		
		$this->start_controls_section(
			'section_content_tab',
			array(
				'label'     => esc_html__( 'Store List', 'modave-core' ),
				'tab'       => Controls_Manager::TAB_CONTENT,
			)
		);		
		$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' ),
			]
		);
		$repeater->add_control(
			'image',
			[
				'label' 		=> esc_html__( 'Store Image', 'modave-core' ),
				'type' 			=> Controls_Manager::MEDIA,
				'default' 		=> [
					'url'	=> Utils::get_placeholder_image_src(),
				],
				'description'	=> esc_html__( 'Select image from media library.', 'modave-core' ),
			]
		);
		$repeater->add_control(
			'opentime',
			[
				'label' 		=> esc_html__( 'Opentime', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXTAREA,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter store open time.', 'modave-core' ),
			]
		);
		$repeater->add_control(
			'facebook',
			[
				'label' 		=> esc_html__( 'Facebook link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);
		$repeater->add_control(
			'twitter',
			[
				'label' 		=> esc_html__( 'Twitter link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);
		$repeater->add_control(
			'linkedin',
			[
				'label' 		=> esc_html__( 'Linkedin link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);
		$repeater->add_control(
			'skype',
			[
				'label' 		=> esc_html__( 'Skype link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);
		$repeater->add_control(
			'instagram',
			[
				'label' 		=> esc_html__( 'Instagram link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);
		$repeater->add_control(
			'youtube',
			[
				'label' 		=> esc_html__( 'Youtube Link', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXT,
			]
		);		
		$this->add_control(
            'store_lists',
            [
                'label' 	=> esc_html__( 'Store 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',
						'opentime' 	=> 'Monday - Friday:<br><b>08:00 - 20:00</b><br>Saturday - Sunday:<br><b>10:00 - 18:00</b><br>',
						'facebook' 	=> '#',
						'twitter' 	=> '#',
						'linkedin' 	=> '#',
					],
					[
						'title' 	=> 'Houston Office',
						'address' 	=> '789 Main Street, Houston, Texas',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 713 432 8765',
						'opentime' 	=> 'Monday - Friday:<br><b>08:00 - 20:00</b><br>Saturday - Sunday:<br><b>10:00 - 18:00</b><br>',
						'facebook' 	=> '#',
						'twitter' 	=> '#',
						'linkedin' 	=> '#',
					],
					[
						'title' 	=> 'San Francisco Office',
						'address' 	=> '321 Market Street, San Francisco, California',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 415 987 6543',
						'opentime' 	=> 'Monday - Friday:<br><b>08:00 - 20:00</b><br>Saturday - Sunday:<br><b>10:00 - 18:00</b><br>',
						'facebook' 	=> '#',
						'twitter' 	=> '#',
						'linkedin' 	=> '#',
					],
					[
						'title' 	=> 'Miami Office',
						'address' 	=> '654 Ocean Drive, Miami, Florida',
						'email' 	=> 'modave@domain.com',
						'phone' 	=> '+1 305 543 2109',
						'opentime' 	=> 'Monday - Friday:<br><b>08:00 - 20:00</b><br>Saturday - Sunday:<br><b>10:00 - 18:00</b><br>',
						'facebook' 	=> '#',
						'twitter' 	=> '#',
						'linkedin' 	=> '#',
					],
				],
				'title_field' => '{{{ title }}}',
            ]
        );		
		$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 .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-' );
		$class				= array( 'pls-element', 'pls-store-location' );
		$settings['class']	= implode( ' ', $class );
		$id_int 			= substr( $this->get_id_int(), 0, 3 );
		$settings['id_int'] 	= $id_int;
		pls_core_get_templates( 'elements-widgets/store-location', $settings );
	}
}

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