<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Categorymapkaveh extends Widget_Base{

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

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

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

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentcategorymapkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );

      $this->add_control(
        'mainimage_categorymapkaveh',
        [
          'label' => esc_html__('Image', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::MEDIA,
          'default' => [
            'url' => KAVEH_TEMPLATE_URI . '/assets/images/new-elements/benz.png',
          ],
        ]
      );
      
      $repeater = new \Elementor\Repeater();
      $repeater->add_control(
        'text_categorymapkaveh',
        [
          'label' => esc_html__('Point Text', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__('Types of Sport Lights', 'kavehTheme'),
        ]
      );

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

    $repeater->add_control(
      'hovered_categorymapkaveh',
      [
        'label' => esc_html__('Show Open or Closed State', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_off' => esc_html__('Yes', 'kavehTheme'),
'label_on' => esc_html__('No', 'kavehTheme'),
        'return_value' => 'hovered',
        'default' => '',
      ]
    );

    $repeater->add_responsive_control(
      'horizontal_position_categorymapkaveh',
      [
        'label' => esc_html__('Horizontal Position', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'center',
        'options' => [
          'start' => esc_html__('Left', 'kavehTheme'),
          'center' => esc_html__('Center', 'kavehTheme'),
          'end' => esc_html__('Right', 'kavehTheme'),
        ],
      ]
    );

    $repeater->add_responsive_control(
      'horizontal_offset_categorymapkaveh',
      [
        'label' => esc_html__('Horizontal Offset', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => -2000,
            'max' => 2000,
            'step' => 1,
          ],
        ],
        'default' => [
          'unit' => 'px',
          'size' => 0,
        ],
      ]
    );  
    
    $repeater->add_responsive_control(
      'vertical_position_categorymapkaveh',
      [
        'label' => esc_html__('Vertical Position', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'middle',
        'options' => [
          'top' => esc_html__('Top', 'kavehTheme'),
          'middle' => esc_html__('Middle', 'kavehTheme'),
          'bottom' => esc_html__('Bottom', 'kavehTheme'),
        ],
      ]
    );  
    
    $repeater->add_responsive_control(
      'vertical_offset_categorymapkaveh',
      [
        'label' => esc_html__('Vertical Offset', 'kavehTheme'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
          'px' => [
            'min' => -2000,
            'max' => 2000,
            'step' => 1,
          ],
        ],
        'default' => [
          'unit' => 'px',
          'size' => 0,
        ],
      ]
    );
      
      $this->add_control(
        'items_categorymapkaveh',
        [
          'label' => esc_html__('Points List', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::REPEATER,
          'fields' => $repeater->get_controls(),
        ]
      );
      
      $this->end_controls_section();
      



/////////////////////////////// style //////////////////////////////


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

$this->add_control(
  'dot_color_categorymapkaveh',
  [
    'label' => esc_html__('Circle Background Color', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::COLOR,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car-item .image .info_dot::before' => 'background-color: {{VALUE}} !important;',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Border::get_type(),
  [
    'name' => 'dot_border_categorymapkaveh',
    'selector' => '{{WRAPPER}} .hero-landing-car-item .image .info_dot::after',
  ]
);

$this->add_responsive_control(
  'dot_width_categorymapkaveh',
  [
    'label' => esc_html__('Circle Width', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 10, 'max' => 100],
    ],
    'selectors' => [
      '{{WRAPPER}} .info_dot' => 'width: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_responsive_control(
  'dot_height_categorymapkaveh',
  [
    'label' => esc_html__('Circle Height', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 10, 'max' => 100],
    ],
    'selectors' => [
      '{{WRAPPER}} .info_dot' => 'height: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_control(
  'dot_border_radius_categorymapkaveh',
  [
    'label' => esc_html__('Circle Border Radius', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .info_dot' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Box_Shadow::get_type(),
  [
    'name' => 'dot_shadow_categorymapkaveh',
    'selector' => '{{WRAPPER}} .hero-landing-car-item .image .info_dot::before',
  ]
);

$this->add_control(
  'info_text_color_categorymapkaveh',
  [
    'label' => esc_html__('Text Color', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::COLOR,
    'selectors' => [
      '{{WRAPPER}} .info_dot .info' => 'color: {{VALUE}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Typography::get_type(),
  [
    'name' => 'info_typography_categorymapkaveh',
    'selector' => '{{WRAPPER}} .info_dot .info',
  ]
);

$this->add_control(
  'info_bg_categorymapkaveh',
  [
    'label' => esc_html__('Text Background Color', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::COLOR,
    'selectors' => [
      '{{WRAPPER}} .info_dot .info' => 'background-color: {{VALUE}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Border::get_type(),
  [
    'name' => 'title_border_categorymapkaveh',
    'label' => esc_html__('Title Box Border Group', 'kavehTheme'),
    'selector' => '{{WRAPPER}} .info_dot .info',
  ]
);

$this->add_control(
  'info_padding_categorymapkaveh',
  [
    'label' => esc_html__('Text Padding', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .info_dot .info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_control(
  'info_border_radius_categorymapkaveh',
  [
    'label' => esc_html__('Text Border Radius', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .info_dot .info' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Box_Shadow::get_type(),
  [
    'name' => 'info_shadow_categorymapkaveh',
    'selector' => '{{WRAPPER}} .info_dot .info',
  ]
);

$this->add_control(
  'bottom_line_color_categorymapkaveh',
  [
    'label' => esc_html__('Bottom Line Color', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::COLOR,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car-item .image .info_dot .info::after' => 'background-color: {{VALUE}};',
    ],
  ]
);

$this->add_responsive_control(
  'bottom_line_width_categorymapkaveh',
  [
    'label' => esc_html__('Bottom Line Width', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 1, 'max' => 50],
    ],
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car-item .image .info_dot .info::after' => 'width: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_responsive_control(
  'bottom_line_height_categorymapkaveh',
  [
    'label' => esc_html__('Bottom Line Height', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 1, 'max' => 50],
    ],
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car-item .image .info_dot .info::after' => 'height: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_responsive_control(
  'bottom_line_margin_categorymapkaveh',
  [
    'label' => esc_html__('Distance from Bottom', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 0, 'max' => 50],
    ],
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car-item .image .info_dot .info::after' => 'margin-bottom: {{SIZE}}{{UNIT}};',
      '{{WRAPPER}} .info_dot .info' => 'margin-bottom: {{SIZE}}{{UNIT}};',
    ],
  ]
);

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

$this->add_responsive_control(
  'image_width_categorymapkaveh',
  [
    'label' => esc_html__('Image Width', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 0, 'max' => 1200],
    ],
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car .image img' => 'width: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_responsive_control(
  'image_height_categorymapkaveh',
  [
    'label' => esc_html__('Image Height', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::SLIDER,
    'range' => [
      'px' => ['min' => 0, 'max' => 800],
    ],
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car .image img' => 'height: {{SIZE}}{{UNIT}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_CSS_Filter::get_type(),
  [
    'name' => 'image_css_filter_categorymapkaveh',
    'label' => esc_html__('CSS Effects', 'kavehTheme'),
    'selector' => '{{WRAPPER}} .hero-landing-car .image img',
  ]
);

$this->add_control(
  'image_border_radius_categorymapkaveh',
  [
    'label' => esc_html__('Image Corners', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car .image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Box_Shadow::get_type(),
  [
    'name' => 'image_shadow_categorymapkaveh',
    'label' => esc_html__('Image Shadow', 'kavehTheme'),
    'selector' => '{{WRAPPER}} .hero-landing-car .image img',
  ]
);

$this->end_controls_section();
$this->start_controls_section(
  'style_categorymapkaveh_box',
  [
    'label' => esc_html__('General Box Style', 'kavehTheme'),
    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Background::get_type(),
  [
    'name' => 'box_background_categorymapkaveh',
    'label' => esc_html__('Box Background', 'kavehTheme'),
    'types' => ['classic', 'gradient'],
    'selector' => '{{WRAPPER}} .hero-landing-car',
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Border::get_type(),
  [
    'name' => 'group_border_categorymapkaveh',
    'label' => esc_html__('Box Border Group', 'kavehTheme'),
    'selector' => '{{WRAPPER}} .hero-landing-car',
  ]
);

$this->add_control(
  'box_padding_categorymapkaveh',
  [
    'label' => esc_html__('Box Inner Spacing', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_control(
  'box_margin_categorymapkaveh',
  [
    'label' => esc_html__('Box Outer Spacing', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_control(
  'box_border_radius_categorymapkaveh',
  [
    'label' => esc_html__('Box Corners', 'kavehTheme'),
    'type' => \Elementor\Controls_Manager::DIMENSIONS,
    'selectors' => [
      '{{WRAPPER}} .hero-landing-car' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
    ],
  ]
);

$this->add_group_control(
  \Elementor\Group_Control_Box_Shadow::get_type(),
  [
    'name' => 'box_shadow_categorymapkaveh',
    'label' => esc_html__('Box Shadow', 'kavehTheme'),
    'selector' => '{{WRAPPER}} .hero-landing-car',
  ]
);

$this->end_controls_section();






 
        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
    <div class="hero-landing-car">
      <div class="container">
        <div class="hero-landing-car-item position-relative">
          <div class="image position-relative mx-auto">
            <img src="<?php echo esc_url($settings['mainimage_categorymapkaveh']['url']); ?>" alt="benz" width="1257" height="423" class="d-block mx-auto">
            <div>

              <?php if (!empty($settings['items_categorymapkaveh'])) : ?>
              <?php 
              foreach ($settings['items_categorymapkaveh'] as $item) : ?>
              <?php
              $rightValue = '50%';
              switch ($item['horizontal_position_categorymapkaveh']) {
                case 'end':
                  $rightValue = '15.5%';
                  break;
                case 'start':
                  $rightValue = '85%';
                  break;
                case 'center':
                default:
                  $rightValue = '50%';
                  break;
              }

              $topValue = '50%';
              switch ($item['vertical_position_categorymapkaveh']) {
                case 'top':
                  $topValue = '20%';
                  break;
                case 'bottom':
                  $topValue = '80%';
                  break;
                case 'middle':
                default:
                  $topValue = '50%';
                  break;
              }

              // Offsets
              $horizontalOffset = isset($item['horizontal_offset_categorymapkaveh']['size']) ? $item['horizontal_offset_categorymapkaveh']['size'] : 0;
              $horizontalUnit = isset($item['horizontal_offset_categorymapkaveh']['unit']) ? $item['horizontal_offset_categorymapkaveh']['unit'] : 'px';

              $verticalOffset = isset($item['vertical_offset_categorymapkaveh']['size']) ? $item['vertical_offset_categorymapkaveh']['size'] : 0;
              $verticalUnit = isset($item['vertical_offset_categorymapkaveh']['unit']) ? $item['vertical_offset_categorymapkaveh']['unit'] : 'px';

              // Final calculation
              $finalRight = "calc($rightValue + {$horizontalOffset}{$horizontalUnit})";
              $finalTop = "calc($topValue + {$verticalOffset}{$verticalUnit})";
              ?>

              <div class="info_dot position-absolute rounded-circle <?php echo esc_attr($item['hovered_categorymapkaveh']); ?>" style="top: <?php echo esc_attr($finalTop); ?>; right: <?php echo esc_attr($finalRight); ?>;">
                <a href="<?php echo esc_url($item['link_categorymapkaveh']); ?>" class="info position-absolute"><?php echo esc_html($item['text_categorymapkaveh']); ?></a>
              </div>
              <?php endforeach; ?>
              <?php endif; ?>

            </div>
          </div>
        </div>
      </div>
    </div>
    <style>
    .hero-landing-car {
    padding: 100px 0;
    }
    </style>
    <?php
  }


}
