<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class categoryfourkaveh extends Widget_Base{

  public function get_name(){
    return 'categoryfourkaveh';
  }

  public function get_title(){
    return esc_html__( 'Category Four Style', 'kavehTheme' );
  }

  public function get_icon(){
    return 'eicon-archive-posts';
  }

  public function get_categories(){
    return ['kavehelements'];
  }

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentcategoryfourkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $repeater = new \Elementor\Repeater();
      $repeater->add_control(
        'title_categoryfourkaveh',
        [
          'label'   => esc_html__('Category Title', 'kavehTheme'),
          'type'    => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__('Mattress', 'kavehTheme'),
        ]
      );

    $repeater->add_control(
      'tagheadingcategoryfourkaveh',
      [
        'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'span',
        'options' => [
          'H1'  => esc_html__( 'H1', 'kavehTheme' ),
          'H2' => esc_html__( 'H2', 'kavehTheme' ),
          'H3' => esc_html__( 'H3', 'kavehTheme' ),
          'H4' => esc_html__( 'H4', 'kavehTheme' ),
          'H5' => esc_html__( 'H5', 'kavehTheme' ),
          'H6' => esc_html__( 'H6', 'kavehTheme' ),
          'p' => esc_html__( 'p', 'kavehTheme' ),
          'div' => esc_html__( 'div', 'kavehTheme' ),
          'span' => esc_html__( 'span', 'kavehTheme' ),
        ],
      ]
    );

    $repeater->add_control(
      'icon_type_categoryfourkaveh',
      [
        'label' => esc_html__('Icon Type', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::CHOOSE,
        'options' => [
          'icon' => [
            'title' => esc_html__('Icon', 'kavehTheme'),
            'icon' => 'eicon-star',
          ],
          'image' => [
            'title' => esc_html__('Image', 'kavehTheme'),
            'icon' => 'eicon-image',
          ],
        ],
        'default' => 'icon',
        'toggle' => true,
      ]
    );
    
    $repeater->add_control(
      'icon_categoryfourkaveh',
      [
        'label' => esc_html__('Select Icon', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::ICONS,
        'skin' => 'inline',
        'exclude_inline_options' => [ 'svg' ],
        'default' => [
          'library' => 'solid',
          'value' => 'isax-moon',
        ],
        'condition' => [
          'icon_type_categoryfourkaveh' => 'icon',
        ],
      ]
    );
    
    $repeater->add_control(
      'image_categoryfourkaveh',
      [
        'label' => esc_html__('Upload Image', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::MEDIA,
        'default' => [
          'url' => \Elementor\Utils::get_placeholder_image_src(),
        ],
        'condition' => [
          'icon_type_categoryfourkaveh' => 'image',
        ],
      ]
    );    

    $repeater->add_control(
      'linkcategoryfourkaveh',
      [
        'label' => esc_html__( 'Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => '#',
      ]
    );  

    $this->add_control(
      'listcategoryfourkaveh',
      [
        'label' => esc_html__( 'Categories', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::REPEATER,
        'fields' => $repeater->get_controls(),
      ]
    
    ); 


    $this->add_control(
      'colcategoryfourkaveh',
      [
        'label' => esc_html__( 'Number of Columns', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => '2',
        'options' => [
          '1'  => esc_html__( '1', 'kavehTheme' ),
          '2' => esc_html__( '2', 'kavehTheme' ),
          '3' => esc_html__( '3', 'kavehTheme' ),
          '4' => esc_html__( '4', 'kavehTheme' ),
          '6' => esc_html__( '6', 'kavehTheme' ),

        ],
      ]
    );
       $this->end_controls_section();







    ///////////////////////////// style /////////////////////////
    
    $this->start_controls_section(
      'section_title_style_categoryfourkaveh',
      [
        'label' => esc_html__('Title Style', 'kavehTheme'),
        'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
      ]
    );
    
    $this->add_control(
      'title_color_categoryfourkaveh',
      [
        'label' => esc_html__('Title Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
          '{{WRAPPER}} .category-bed .title' => 'color: {{VALUE}};',
        ],
      ]
    );
    
    $this->add_group_control(
      \Elementor\Group_Control_Typography::get_type(),
      [
        'name' => 'title_typography_categoryfourkaveh',
        'selector' => '{{WRAPPER}} .category-bed .title',
      ]
    );
    
    $this->end_controls_section();

    $this->start_controls_section(
      'section_icon_style_categoryfourkaveh',
      [
        'label' => esc_html__('Icon Style', 'kavehTheme'),
        'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
      ]
    );

    $this->add_control(
      'icon_color_categoryfourkaveh',
      [
        'label' => esc_html__('Icon Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
          '{{WRAPPER}} .categoryfourkaveh-icon' => 'color: {{VALUE}};',
          '{{WRAPPER}} .categoryfourkaveh-icon svg' => 'fill: {{VALUE}};',
        ],
      ]
    );
    
    $this->add_responsive_control(
      'icon_size_categoryfourkaveh',
      [
        'label' => esc_html__('Icon Size', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => 10,
            'max' => 200,
          ],
        ],
        'selectors' => [
          '{{WRAPPER}} .categoryfourkaveh-icon' => 'font-size: {{SIZE}}{{UNIT}};',
          '{{WRAPPER}} .categoryfourkaveh-icon svg' => 'width: {{SIZE}}{{UNIT}}; height: auto;',
        ],
      ]
    );

    $this->add_responsive_control(
      'icon_box2_positionx_categoryfourkaveh',
      [
          'label' => esc_html__('Horizontal Position', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => ['px'],
          'range' => [
              'px' => [
                  'min' => -200,
                  'max' => 200,
              ],
          ],
          'selectors' => [
              '{{WRAPPER}} .categoryfourkaveh-icon' => '--custom-translateX: {{SIZE}}{{UNIT}};',
          ],
      ]
  );

  $this->add_responsive_control(
    'icon_box2_positiony_categoryfourkaveh',
    [
        'label' => esc_html__('Vertical Position', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => -200,
                'max' => 200,
            ],
        ],
        'selectors' => [
            '{{WRAPPER}} .categoryfourkaveh-icon' => '--custom-translateY: {{SIZE}}{{UNIT}};',
        ],
    ]
);
    
    $this->end_controls_section();
    $this->start_controls_section(
      'section_image_style_categoryfourkaveh',
      [
        'label' => esc_html__('Image Style', 'kavehTheme'),
        'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
      ]
    );
    
    $this->add_responsive_control(
      'image_width_categoryfourkaveh',
      [
        'label' => esc_html__('Image Width', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => 10,
            'max' => 500,
          ],
        ],
        'selectors' => [
          '{{WRAPPER}} .categoryfourkaveh-image' => 'width: {{SIZE}}{{UNIT}};',
        ],
      ]
    );

    $this->add_responsive_control(
      'image_height_categoryfourkaveh',
      [
        'label' => esc_html__('Image Width', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => 10,
            'max' => 500,
          ],
        ],
        'selectors' => [
          '{{WRAPPER}} .categoryfourkaveh-image' => 'height: {{SIZE}}{{UNIT}};',
        ],
      ]
    );
    
    $this->add_responsive_control(
      'image_border_radius_categoryfourkaveh',
      [
        'label' => esc_html__('Image Corner Roundness', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => 0,
            'max' => 100,
          ],
        ],
        'selectors' => [
          '{{WRAPPER}} .categoryfourkaveh-image' => 'border-radius: {{SIZE}}{{UNIT}};',
        ],
      ]
    );
    
    $this->end_controls_section();
    $this->start_controls_section(
      'section_icon_box_style_categoryfourkaveh',
      [
        'label' => esc_html__('Box Style Behind Icon / Image', 'kavehTheme'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
      ]
    );
    
    $this->add_control(
      'icon_box_background_color_categoryfourkaveh',
      [
        'label' => esc_html__('Box Background Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
          '{{WRAPPER}} .category-bed .icon::after' => 'background-color: {{VALUE}} !important;',
        ],
      ]
    );
    
    $this->add_responsive_control(
      'icon_box_size_categoryfourkaveh',
      [
        'label' => esc_html__('Box Width', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => ['min' => 10, 'max' => 300],
        ],
        'selectors' => [
          '{{WRAPPER}} .category-bed .icon::after' => 'width: {{SIZE}}{{UNIT}};',
        ],
      ]
    );

    $this->add_responsive_control(
      'icon_box_height_categoryfourkaveh',
      [
        'label' => esc_html__('Box Height', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => ['min' => 10, 'max' => 300],
        ],
        'selectors' => [
          '{{WRAPPER}} .category-bed .icon::after' => 'height: {{SIZE}}{{UNIT}};',
        ],
      ]
    );

    $this->add_responsive_control(
      'icon_box_border_radius_categoryfourkaveh',
      [
        'label' => esc_html__('Corner Roundness', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px'],
        'selectors' => [
          '{{WRAPPER}} .category-bed .icon::after' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
      ]
    );
    
    $this->add_group_control(
      \Elementor\Group_Control_Box_Shadow::get_type(),
      [
        'name' => 'icon_box_shadow_categoryfourkaveh',
        'selector' => '{{WRAPPER}} .category-bed .icon::after',
      ]
    );

    $this->add_responsive_control(
      'icon_box_positionx_categoryfourkaveh',
      [
          'label' => esc_html__('Horizontal Position', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => ['px'],
          'range' => [
              'px' => [
                  'min' => -200,
                  'max' => 200,
              ],
          ],
          'selectors' => [
              '{{WRAPPER}} .category-bed .icon::after' => '--custom-translateX: {{SIZE}}{{UNIT}};',
          ],
      ]
  );

  $this->add_responsive_control(
    'icon_box_positiony_categoryfourkaveh',
    [
        'label' => esc_html__('Vertical Position', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => -200,
                'max' => 200,
            ],
        ],
        'selectors' => [
            '{{WRAPPER}} .category-bed .icon::after' => '--custom-translateY: {{SIZE}}{{UNIT}};',
        ],
    ]
);
    
    $this->end_controls_section();
    $this->start_controls_section(
      'section_box_style_categoryfourkaveh',
      [
        'label' => esc_html__('Box Style', 'kavehTheme'),
        'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
      ]
    );
    
    $this->start_controls_tabs('tabs_box_style_categoryfourkaveh');
    $this->start_controls_tab(
      'tab_box_normal_categoryfourkaveh',
      [
        'label' => esc_html__('Normal', 'kavehTheme'),
      ]
    );
    
    $this->add_control(
      'box_background_normal_categoryfourkaveh',
      [
        'label' => esc_html__('Background Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
          '{{WRAPPER}} .category-bed' => 'background-color: {{VALUE}};',
        ],
      ]
    );
    
    $this->add_group_control(
      \Elementor\Group_Control_Border::get_type(),
      [
        'name' => 'box_border_normal_categoryfourkaveh',
        'selector' => '{{WRAPPER}} .category-bed',
      ]
    );
    
    $this->end_controls_tab();
    $this->start_controls_tab(
      'tab_box_hover_categoryfourkaveh',
      [
        'label' => esc_html__('Hover', 'kavehTheme'),
      ]
    );
    
    $this->add_control(
      'box_background_hover_categoryfourkaveh',
      [
        'label' => esc_html__('Hover Background Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
          '{{WRAPPER}} .category-bed:hover' => 'background-color: {{VALUE}};',
        ],
      ]
    );
    
    $this->add_group_control(
      \Elementor\Group_Control_Border::get_type(),
      [
        'name' => 'box_border_hover_categoryfourkaveh',
        'selector' => '{{WRAPPER}} .category-bed:hover',
      ]
    );

    $this->add_control(
      'bghoverborder_color_categoryfourkaveh',
      [
        'label' => esc_html__('Hover Box Border Color', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::COLOR,
      ]
    );
    
    $this->end_controls_tab();
    $this->end_controls_tabs();

    $this->add_responsive_control(
      'box_padding_categoryfourkaveh',
      [
        'label' => esc_html__('Box Padding', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px'],
        'selectors' => [
          '{{WRAPPER}} .category-bed' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
      ]
    );

    $this->add_responsive_control(
      'box_border_radius_categoryfourkaveh',
      [
        'label' => esc_html__('Box Corner Roundness', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px'],
        'selectors' => [
          '{{WRAPPER}} .category-bed' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
      ]
    );
    
    $this->add_group_control(
      \Elementor\Group_Control_Box_Shadow::get_type(),
      [
        'name' => 'box_shadow_categoryfourkaveh',
        'selector' => '{{WRAPPER}} .category-bed',
      ]
    );
    
    $this->end_controls_section();
    
    
    
    


        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
    <div class="categoryfour">
      <div class="categories-bed row">
        <!-- Start Category -->
        <?php if (!empty($settings['listcategoryfourkaveh'])) : ?>
          <?php foreach ($settings['listcategoryfourkaveh'] as $item) : ?>
      <div class="<?php if('1'===$settings['colcategoryfourkaveh']){ ?>col-lg-12<?php }elseif('2'===$settings['colcategoryfourkaveh']){?>col-lg-6<?php }elseif('3'===$settings['colcategoryfourkaveh']){?>col-lg-4<?php }elseif('4'===$settings['colcategoryfourkaveh']){?>col-lg-3<?php }elseif('6'===$settings['colcategoryfourkaveh']){?>col-lg-2<?php } ?> col-6">
          <a href="<?php echo  esc_url($item['linkcategoryfourkaveh']); ?>" class="category-bed d-flex align-items-center justify-content-center flex-column position-relative h-100">
          <span class="icon position-relative">
            <?php if ($item['icon_type_categoryfourkaveh'] === 'icon' && !empty($item['icon_categoryfourkaveh']['value'])) : ?>
              <?php \Elementor\Icons_Manager::render_icon($item['icon_categoryfourkaveh'], ['class' => 'categoryfourkaveh-icon', 'aria-hidden' => 'true']); ?>
            <?php elseif ($item['icon_type_categoryfourkaveh'] === 'image' && !empty($item['image_categoryfourkaveh']['url'])) : ?>
              <img class="categoryfourkaveh-image" src="<?php echo esc_url($item['image_categoryfourkaveh']['url']); ?>" alt="<?php echo esc_attr($item['title_categoryfourkaveh']); ?>">
            <?php endif; ?>
          </span>
            <<?php echo  esc_attr($item['tagheadingcategoryfourkaveh']); ?> class="title mt-auto text-center">
            <?php echo  esc_html($item['title_categoryfourkaveh']); ?>
            </<?php echo  esc_attr($item['tagheadingcategoryfourkaveh']); ?>>
          </a>
      </div>
        <!-- End Category -->
        <?php endforeach; ?>
        <?php endif; ?>
      </div>
    </div>
    <style>
    .category-bed .icon::after {
    margin-right: -32px;
    opacity: 1;
    }
    .categoryfourkaveh-image {
      width: 60px;
      height: auto;
      object-fit: contain;
    }
    .category-bed::before {
    background-image: linear-gradient(145.65deg, <?php echo  esc_html($settings['bghoverborder_color_categoryfourkaveh']); ?> 20.3%, rgba(252, 149, 39, 0) 119%);
    }
    .category-bed .icon::after {
    transform: translate(var(--custom-translateX, 0), var(--custom-translateY, 0)) rotate(var(--custom-rotate, 0));
    }
    .categoryfourkaveh-icon {
    transform: translate(var(--custom-translateX, 0), var(--custom-translateY, 0)) rotate(var(--custom-rotate, 0));
    }
    </style>
    <?php
  }


}
