<?php 

namespace XIMSAPLUGIN\Element;

use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Plugin;

/**
 * Elementor button widget.
 * Elementor widget that displays a button with the ability to control every
 * aspect of the button design.
 *
 * @since 1.0.0
 */
class Project_Details extends Widget_Base {

    /**
     * Get widget name.
     * Retrieve button widget name.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget name.
     */
    public function get_name() {
        return 'ximsa_project_details';
    }

    /**
     * Get widget title.
     * Retrieve button widget title.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Project Details', 'ximsa' );
    }

    /**
     * Get widget icon.
     * Retrieve button widget icon.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'eicon-library-open';
    }

    /**
     * Get widget categories.
     * Retrieve the list of categories the button widget belongs to.
     * Used to determine where to display the widget in the editor.
     *
     * @since  2.0.0
     * @access public
     * @return array Widget categories.
     */
    public function get_categories() {
        return [ 'ximsa' ];
    }

    /**
     * Register button 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(
            'project_details',
            [
                'label' => esc_html__( 'Project Details', 'ximsa' ),
            ]
        );
		$this->add_control(
			'project_img',
			[
				'label' => __( 'Project Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Title', 'ximsa' ),
			]
		);
		$this->add_control(
        	'client_info', 
			  	[
					'type' => Controls_Manager::REPEATER,
					'separator' => 'before',
					'default' => 
				[
					['block_title' => esc_html__('Clients', 'ximsa')],
					['block_title' => esc_html__('Category', 'ximsa')],
					['block_title' => esc_html__('Location', 'ximsa')],
					['block_title' => esc_html__('Date', 'ximsa')],
				],
			'fields' => 
				[
					[
						'name' => 'block_title',
						'label' => esc_html__('Title', 'ximsa'),
						'type' => Controls_Manager::TEXTAREA,
						'default' => esc_html__('', 'ximsa')
					],
					[
						'name' => 'block_text',
						'label' => esc_html__('Text', 'ximsa'),
						'type' => Controls_Manager::TEXTAREA,
						'default' => esc_html__('', 'ximsa')
					],
				],
				'title_field' => '{{block_title}}',
			]
        );
		$this->add_control(
			'text',
			[
				'label'       => __( 'Text', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Text', 'ximsa' ),
			]
		);
		$this->add_control(
			'project_title',
			[
				'label'       => __( 'Project Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Project Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'Project_text',
			[
				'label'       => __( 'Project Text', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Project Text', 'ximsa' ),
			]
		);
		$this->add_control(
			'our_project', 
				[
					'type' => Controls_Manager::REPEATER,
					'separator' => 'before',
					'default' => 
				[
					['item#1' => esc_html__('Our Project', 'ximsa')],
				],
			'fields' => 
				[
					[
						'name' => 'project_img',
						'label' => esc_html__('Project Image', 'ximsa'),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					],
				],
			 ]
        );
		$this->add_control(
			'project_title_1',
			[
				'label'       => __( 'Project Title 1', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Project Title 1', 'ximsa' ),
			]
		);
		$this->add_control(
			'Project_text_1',
			[
				'label'       => __( 'Project Text 1', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Project Text 1', 'ximsa' ),
			]
		);
		$this->add_control(
			'Project_text_2',
			[
				'label'       => __( 'Project Text 2', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Project Text 2', 'ximsa' ),
			]
		);
		$this->add_control(
			'form_title',
			[
				'label'       => __( 'Form Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Form Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'contact_form_url',
			[
				'label'       => __( 'Contact Form 7 Url', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
						'active' => true,
					],
				'placeholder' => __( 'Enter your Contact Form 7 Url', 'ximsa' )
			]
		);
		$this->end_controls_section();
    }

    /**
     * Render button widget output on the frontend.
     * Written in PHP and used to generate the final HTML.
     *
     * @since  1.0.0
     * @access protected
     */
    protected function render() {
        $settings = $this->get_settings_for_display();
        $allowed_tags = wp_kses_allowed_html('post');
    ?>
		
    <!-- Project Detail Section -->
	<section class="project-detail-section">
		<div class="auto-container">
			<?php if($settings['project_img']['id']){ ?>
            <div class="main-image">
				<img src="<?php echo esc_url(wp_get_attachment_url($settings['project_img']['id']));?>" alt="<?php esc_attr_e('Awesome Image', 'ximsa'); ?>" />
			</div>
            <?php } ?>
			<?php if($settings['title']){ ?>
            <!-- Title Box -->
			<div class="title-box">
				<h2><?php echo wp_kses($settings['title'], true);?></h2>
			</div>
			<?php } ?>
			<!-- Project Info Box -->
			<div class="project-info-box">
				<ul>
                	<?php foreach($settings['client_info'] as $key => $item): ?>
					<li>
						<strong><?php echo wp_kses($item['block_title'], true);?></strong>
						<?php echo wp_kses($item['block_text'], true);?>
					</li>
					<?php endforeach; ?>
				</ul>
			</div>
			
			<?php if($settings['text']){ ?><p><?php echo wp_kses($settings['text'], true);?></p><?php } ?>
            
			<?php if($settings['project_title'] || $settings['Project_text']){ ?>
            <!-- Challenge Boxed -->
			<div class="challenge-boxed">
				<div class="box-inner">
					<?php if($settings['project_title']){ ?><h3><?php echo wp_kses($settings['project_title'], true);?></h3><?php } ?>
					<?php if($settings['Project_text']){ ?><p><?php echo wp_kses($settings['Project_text'], true);?></p><?php } ?>
				</div>
			</div>
			<?php } ?>
			<!-- Gallery Box -->
			<div class="gallery-box">
				<div class="row clearfix">
					<?php foreach($settings['our_project'] as $key => $item): ?>
                    <div class="column col-lg-6 col-md-6 col-sm-12">
						<img src="<?php echo esc_url(wp_get_attachment_url($item['project_img']['id']));?>" alt="<?php esc_attr_e('Awesome Image', 'ximsa'); ?>" />
					</div>
					<?php endforeach; ?>
				</div>
			</div>
			<?php if($settings['project_title_1'] || $settings['Project_text_1'] || $settings['Project_text_2']){ ?>
			<!-- Goal Boxed -->
			<div class="goal-boxed">
				<div class="box-inner">
					<?php if($settings['project_title_1']){ ?><h3><?php echo wp_kses($settings['project_title_1'], true);?></h3><?php } ?>
					<?php if($settings['Project_text_1']){ ?><p><?php echo wp_kses($settings['Project_text_1'], true);?></p><?php } ?>
					<?php if($settings['Project_text_2']){ ?><div class="styled-text"><?php echo wp_kses($settings['Project_text_2'], true);?></div><?php } ?>
				</div>
			</div>
			<?php } ?>
			<!-- Form Box -->
			<div class="form-box">
				<?php if($settings['form_title']){ ?><h3><?php echo wp_kses($settings['form_title'], true);?></h3><?php } ?>
				<?php if($settings['contact_form_url']){ ?>
				<!-- Faq Form -->
				<div class="faq-form">
					<?php echo do_shortcode($settings['contact_form_url']);?>
				</div>
				<!-- End Faq Form -->
				<?php } ?>
			</div>
			
		</div>
	</section>
	<!-- End Project Detail Section -->
	
	<?php
    }
}
