<?php
namespace dexen\Widget;

use Elementor\Controls_Manager;
use Elementor\Plugin;
use Elementor\Utils;
use Elementor\Group_Control_Image_Size;
use Elementor\Widget_Base;

/**
 * Elementor Faq area one
 *
 * @since 1.0.0
 */
class Faq extends \Elementor\Widget_Base {
	public function get_name() {
		return 'dexen_faq';
	}
	public function get_title() {
		return esc_html__( 'Dexen Faq', 'plugin-name' );
	}
	public function get_icon() {
		return 'fa fa-object-ungroup';
	}
	public function get_categories() {
		return array( 'dexencore' );
	}

	protected function _register_controls() {
		$this->start_controls_section(
			'faq_area_left',
			array(
				'label' => esc_html__( 'Faq area Left', 'plugin-name' ),
				'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'title_1',
			array(
				'label'   => esc_html__( 'Title 1', 'bebio-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'We Can Help you with all Printing Needs', 'bebio-core' ),
			)
		);

		$this->add_control(
			'content_1',
			array(
				'label'   => esc_html__( 'Content', 'bebio-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'There are many people variation of pass of lorem sum available inthe majority have suffer freedom text some.',
			)
		);

		$this->add_control(
			'image',
			array(
				'label'   => __( 'Image', 'bebio-core' ),
				'type'    => Controls_Manager::MEDIA,
				'dynamic' => array(
					'active' => true,
				),
				'default' => array(
					'url' => Utils::get_placeholder_image_src(),
				),
			)
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'title_settings',
			array(
				'label' => __( 'Faq area Right', 'dexen-core' ),
			)
		);

		$this->add_control(
			'title_2',
			array(
				'label'   => __( 'Titile', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Dexen Faqs', 'dexen-core' ),

			)
		);

		$this->add_control(
			'title_3',
			array(
				'label'   => __( 'Titile 2', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Frequently Asked Questions', 'dexen-core' ),

			)
		);

		$this->add_control(
			'faq_item',
			array(
				'type'        => Controls_Manager::REPEATER,
				'label'       => esc_html__( 'Taqs Item', 'dexen-core' ),
				'seperator'   => 'before',
				'default'     => array(
					array( 'tab_title' => esc_html__( 'Item #1', 'dexen-core' ) ),
					array( 'tab_title' => esc_html__( 'Item #2', 'dexen-core' ) ),
					array( 'tab_title' => esc_html__( 'Item #3', 'dexen-core' ) ),
					array( 'tab_title' => esc_html__( 'Item #4', 'dexen-core' ) ),
					array( 'tab_title' => esc_html__( 'Item #5', 'dexen-core' ) ),
				),
				'fields'      => array(
					array(
						'name'    => 'tab_title',
						'label'   => esc_html__( 'Tab Title', 'dexen-core' ),
						'type'    => Controls_Manager::TEXT,
						'default' => esc_html__( 'Tab Title', 'dexen-core' ),
					),
					array(
						'name'    => 'question',
						'label'   => esc_html__( 'Question', 'dexen-core' ),
						'type'    => Controls_Manager::TEXT,
						'default' => 'How much do color business card cost?',
					),
					array(
						'name'    => 'answer',
						'label'   => esc_html__( 'Answer ', 'dexen-core' ),
						'type'    => Controls_Manager::TEXTAREA,
						'default' => '
                                            <p>Color Business Cards start at <span>$19.99</span> for <span>50 cards.</span></p>
                                            <p>The final cost depends on which turnaround time and paper/finish options you\'ve selected at checkout - you can get an accurate quote in seconds using our online cost calculator.</p>',
					),
					array(
						'name'         => 'state',
						'label'        => __( 'Is Active', 'dexen-core' ),
						'type'         => \Elementor\Controls_Manager::SWITCHER,
						'label_on'     => __( 'Show', 'dexen-core' ),
						'label_off'    => __( 'Hide', 'dexen-core' ),
						'return_value' => 'no',
					),
				),
				'title_field' => '{{tab_title}}',
			)
		);
		$this->end_controls_section();
	}
	protected function render() {
		$settings = $this->get_settings_for_display();

		$image_url = ( $settings['image']['id'] != '' ) ? wp_get_attachment_url( $settings['image']['id'], 'full' ) : $settings['image']['url'];
		$image_id  = $settings['image']['id'];
		$alt       = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
		?>

		<section class="faq-one sec-pad sec-pad-content-margin-50">
			<div class="container">
				<div class="row">
					<div class="col-lg-6">
						<div class="faq-one__content thm-gray-bg content-margin-50">
							<h3 class="faq-one__title">
							<?php
							echo wp_kses_post( $settings['title_1'] );
							?>
							</h3><!-- /.faq-one__title -->
							<p class="faq-one__text">
							<?php
							echo wp_kses_post( $settings['content_1'] );
							?>
							</p><!-- /.faq-one__text -->
							<div class="faq-one__image">
								<img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $alt ); ?>" />
								
							</div><!-- /.faq-one__image -->
						</div><!-- /.faq-one__content -->
					</div><!-- /.col-lg-6 -->
					<div class="col-lg-6">
						<div class="content-margin-50 faq-one__accordion-wrap">
							<div class="block-title">
								<p class="block-title__tag-line">
								<?php
								echo wp_kses_post( $settings['title_2'] );
								?>
								</p>
								<h2 class="block-title__title">
								<?php
								echo wp_kses_post( $settings['title_3'] );
								?>
								</h2>
							</div><!-- /.block-title -->
							<div class="accrodion-grp" data-grp-name="faq-accrodion">
							  <?php
								foreach ( $settings['faq_item'] as $tab ) {
									$active  = '';
									$button  = '';
									$current = '';
									if ( $tab['state'] ) {
										$active = 'active';
									}
									?>
								<div class="accrodion <?php echo esc_attr( $active ); ?>">
									<div class="accrodion-title">
										<h4><?php echo wp_kses_post( $tab['question'] ); ?></h4>
									</div>
									<div class="accrodion-content">
										<div class="inner">
										   <?php echo wp_kses_post( $tab['answer'] ); ?>
									   </div><!-- /.inner -->
								   </div>
							   </div>
									<?php
								}
								?>
					   </div>
				   </div><!-- /.content-margin-50 -->
			   </div><!-- /.col-lg-6 -->
		   </div><!-- /.row -->
	   </div><!-- /.container -->
   </section><!-- /.faq-one -->
		<?php
	}
}

\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Faq() );
