<?php

/**
 * Elementor Widget
 * @package Meditest
 * @since 1.0.0
 */

namespace Elementor;

if (!defined('ABSPATH')) exit; // Exit if accessed directly.

class meditest_stylish_shape extends Widget_Base
{

	/**
	 * Get widget name.
	 *
	 * Retrieve Elementor widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name()
	{
		return 'stylish-shape';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return esc_html__('Stylish Shape', 'meditest-extra');
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Elementor widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'fas fa-th-large';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Elementor widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories()
	{
		return ['meditest_widgets'];
	}

	/**
	 * Register Elementor 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(
			'home_banner_section',
			[
				'label' => esc_html__('Content', 'meditest-extra'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'shape_style',
			[
				'label' => esc_html__('Select Shape Style', 'meditest-extra'),
				'type' => Controls_Manager::SELECT,
				'label_block' => true,
				'default' => 'st_icon',
				'options' => [
					'st_icon'  => esc_html__('Stylish SVG Shape Only', 'meditest-extra'),
					'st_one'  => esc_html__('Icon with Background color', 'meditest-extra'),
					'st_two'  => esc_html__('Icon with Text', 'meditest-extra'),
				],
			]
		);
		$this->add_control(
			'shape_title',
			[
				'label' => esc_html__('Title', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'placeholder' => esc_html__('Regular Checkup', 'meditest-extra'),
				'condition' => [
					'shape_style' => 'st_two',
				],
			]
		);

		$this->add_control(
			'shape_title_alt',
			[
				'label' => esc_html__('Alter Title', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'placeholder' => esc_html__('', 'meditest-extra'),
				'condition' => [
					'shape_style' => 'st_two',
				],
			]
		);



		$this->add_control(
			'shape_icon',
			[
				'label' => esc_html__('Icon', 'meditest-extra'),
				'type' => Controls_Manager::ICONS,
				'default' => [
					'value' => 'fas fa-stethoscope',
					'library' => 'solid',
				],
			]
		);

		$this->add_control(
			'shape_animation',
			[
				'label' => esc_html__('Select Shape Animation Type', 'meditest-extra'),
				'type' => Controls_Manager::SELECT,
				'label_block' => true,
				'default' => 'none',
				'options' => [
					'none'  => esc_html__('None', 'meditest-extra'),
					'anim_one'  => esc_html__('Animation One', 'meditest-extra'),
					'anim_two'  => esc_html__('Animation Two', 'meditest-extra'),
					'anim_three'  => esc_html__('Animation Three', 'meditest-extra'),
					'anim_four'  => esc_html__('Animation Four', 'meditest-extra'),
					'anim_five'  => esc_html__('Animation Five', 'meditest-extra'),
					'anim_six'  => esc_html__('Animation Six', 'meditest-extra'),
					'anim_seven'  => esc_html__('Animation Seven', 'meditest-extra'),
					'anim_eight'  => esc_html__('Animation Eight', 'meditest-extra'),
				],
			]
		);

		$this->end_controls_section();

		// Style Tab
		$this->start_controls_section(
			'shape_style_tab',
			[
				'label' => esc_html__('Icon', 'meditest-extra'),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'shape_bg',
				'label' => esc_html__('Background', 'meditest-extra'),
				'types' => ['classic', 'gradient', 'video'],
				'selector' => '{{WRAPPER}} .stylish-shape-icon, 
                {{WRAPPER}} .stylish-shape-icon-text',
				'condition' => [
					'shape_style' => ['st_one', 'st_two'],
				],
			]
		);

		$this->add_control(
			'shape_bg_width',
			[
				'label' => esc_html__('Background Width', 'meditest-extra'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 500,
						'step' => 1,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 80,
				],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon' => 'width: {{SIZE}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_one'],
				],
			]
		);
		$this->add_control(
			'shape_bg_height',
			[
				'label' => esc_html__('Background Height', 'meditest-extra'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 500,
						'step' => 1,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 80,
				],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon' => 'height: {{SIZE}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_one'],
				],
			]
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'shape_box_shadow',
				'label' => esc_html__('Box Shadow', 'meditest-extra'),
				'selector' => '{{WRAPPER}} .stylish-shape-icon, 
                {{WRAPPER}} .stylish-shape-icon-text',
				'condition' => [
					'shape_style' => ['st_one', 'st_two'],
				],
			]
		);

		// Icon Size for Font Icon
		$this->add_control(
			'shape_font_icon_size',
			[
				'label' => esc_html__('Icon Size for Fonts Icon', 'meditest-extra'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 200,
						'step' => 1,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 40,
				],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon i, 
                    {{WRAPPER}} .stylish-shape-icon-text i' => 'font-size: {{SIZE}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_one', 'st_two'],
				],
			]
		);
		$this->add_control(
			'shape_icon_color',
			[
				'label' => esc_html__('Icon Color', 'meditest-extra'),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text i, {{WRAPPER}} .stylish-shape-icon i' => 'color: {{VALUE}}',
				],
				'condition' => [
					'shape_style' => ['st_one', 'st_two'],
				],
			]
		);
		$this->add_control(
			'shape_icon_bg_color',
			[
				'label' => esc_html__('Icon Background Color', 'meditest-extra'),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text i' => 'background: {{VALUE}}',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		// Icon Size for SVG Icon
		$this->add_responsive_control(
			'shape_svg_icon_size',
			[
				'label' => esc_html__('Icon Size for SVG', 'meditest-extra'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 500,
						'step' => 1,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 50,
				],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon svg, 
                    {{WRAPPER}} .stylish-svg-shape-icon svg,
                    {{WRAPPER}} .stylish-shape-icon-text svg' => 'width: {{SIZE}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_icon', 'st_one', 'st_two'],
				],
			]
		);
		$this->add_control(
			'txt-font-color',
			[
				'label' => __('Text Color', 'meditest'),
				'type' => Controls_Manager::COLOR,
				'scheme' => [
					'type' => Core\Schemes\Color::get_type(),
					'value' => Core\Schemes\Color::COLOR_1,
				],
				'default' => '#fff',
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text span.stylist-shape-text' => 'color: {{VALUE}}',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		$this->add_control(
			'txt-font-color_alt',
			[
				'label' => __('Text Alternative Color', 'meditest'),
				'type' => Controls_Manager::COLOR,
				'scheme' => [
					'type' => Core\Schemes\Color::get_type(),
					'value' => Core\Schemes\Color::COLOR_1,
				],
				'default' => '#fff',
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text p.stylist-shape-alt' => 'color: {{VALUE}}',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'text_typography',
				'label' => __('Text Typography', 'plugin-domain'),
				'selector' => '{{WRAPPER}} .stylish-shape-icon-text span.stylist-shape-text',
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'alt_text_typography',
				'label' => __('Alt Text Typography', 'plugin-domain'),
				'selector' => '{{WRAPPER}} .stylish-shape-icon-text p.stylist-shape-alt',
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);
		$this->add_control(
			'icon_box_padding',
			[
				'label' => esc_html__('Padding', 'plugin-name'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text,
					{{WRAPPER}} .stylish-shape-icon' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		$this->add_control(
			'icon_box_border_radius',
			[
				'label' => esc_html__('Border Radius', 'plugin-name'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text,
					{{WRAPPER}} .stylish-shape-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		$this->add_responsive_control(
			'align_text_ment',
			[
				'label'        => __('Text Alignment', 'mayosis'),
				'type'         => Controls_Manager::CHOOSE,
				'options'      => [
					'left'   => [
						'title' => __('Left', 'mayosis'),
						'icon'  => 'eicon-h-align-left',
					],
					'center' => [
						'title' => __('Center', 'mayosis'),
						'icon'  => 'eicon-h-align-center',
					],
					'right'  => [
						'title' => __('Right', 'mayosis'),
						'icon'  => 'eicon-h-align-right',
					],
				],
				'prefix_class' => 'elementor-align-%s',
				'default'      => 'left',
				'selectors' => [
					'{{WRAPPER}} .stylish-shape-icon-text' => 'text-align: {{VALUE}} !important',
				],
				'condition' => [
					'shape_style' => ['st_two'],
				],
			]
		);

		$this->end_controls_section();
	}

	protected function render()
	{
		$settings = $this->get_settings_for_display();
		$shape_style = $settings['shape_style'];
		$shape_animation = $settings['shape_animation'];



		switch ($shape_style) {
			case "st_icon": ?>
				<div class="stylish-svg-shape-icon medi-<?php echo esc_html($shape_animation); ?>">
					<?php Icons_Manager::render_icon($settings['shape_icon'], ['aria-hidden' => 'true']); ?>
				</div>
			<?php

				break;
			case "st_one": ?>
				<div class="stylish-shape-icon  medi-<?php echo esc_html($shape_animation); ?>">
					<?php Icons_Manager::render_icon($settings['shape_icon'], ['aria-hidden' => 'true']); ?>
				</div>
			<?php

				break;
			case "st_two": ?>
				<div class="stylish-shape-icon-text  medi-<?php echo esc_html($shape_animation); ?>">
					<?php Icons_Manager::render_icon($settings['shape_icon'], ['aria-hidden' => 'true']); ?>
					<span class="stylist-shape-text"><?php echo $settings['shape_title']; ?></span>
					<?php if ($settings['shape_title_alt']) { ?>
						<p class="stylist-shape-alt"><?php echo $settings['shape_title_alt']; ?></p>
					<?php } ?>
				</div>

<?php

				break;
		}
	}
}

Plugin::instance()->widgets_manager->register_widget_type(new meditest_stylish_shape());
