Current File : /home/n742ef5/royalanteam.com/wp-content/plugins/myhome-core/src/Widgets/General/StatsV2Widget.php
<?php

namespace Tangibledesign\MyHome\Widgets\General;

use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Repeater;
use Tangibledesign\Framework\Core\Collection;
use Tangibledesign\Framework\Widgets\Helpers\BaseGeneralWidget;

class StatsV2Widget extends BaseGeneralWidget
{
    public function getKey(): string
    {
        return 'stats_v2';
    }

    public function getName(): string
    {
        return esc_html__('Stats', 'myhome-core');
    }

    protected function register_controls(): void
    {
        $this->addGeneralContentSection();

        $this->addGeneralStyleSection();
    }

    private function addGeneralContentSection(): void
    {
        $this->startContentControlsSection();

        $this->addAttributesControl();

        $this->endControlsSection();
    }

    private function addAttributesControl(): void
    {
        $attributes = new Repeater();

        $attributes->add_control(
            'value',
            [
                'label' => esc_html__('Value', 'myhome-core'),
                'type' => Controls_Manager::TEXT,
            ]
        );

        $attributes->add_control(
            'label',
            [
                'label' => esc_html__('Label', 'myhome-core'),
                'type' => Controls_Manager::TEXTAREA,
            ]
        );

        $this->add_control(
            'attributes',
            [
                'label' => esc_html__('Attributes', 'myhome-core'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $attributes->get_controls(),
                'prevent_empty' => false,
            ]
        );
    }

    public function getAttributes(): Collection
    {
        $attributes = $this->get_settings_for_display('attributes');

        if (empty($attributes) || !is_array($attributes)) {
            return tdf_collect();
        }

        return tdf_collect($attributes);
    }

    private function addGeneralStyleSection(): void
    {
        $this->startStyleControlsSection();

        $this->add_control(
            'stats_heading',
            [
                'label' => esc_html__('Stats', 'myhome-core'),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $this->add_responsive_control(
            'stats_per_row',
            [
                'label' => esc_html__('Per row', 'myhome-core'),
                'type' => Controls_Manager::SELECT,
                'default' => '3',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '5' => '5',
                    '6' => '6',
                ],
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2' => 'grid-template-columns: repeat({{VALUE}}, minmax(0, 1fr));',
                ]
            ]
        );

        $this->add_responsive_control(
            'columns_gap',
            [
                'label' => esc_html__('Columns Gap', 'myhome-core'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2' => 'grid-column-gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'rows_gap',
            [
                'label' => esc_html__('Rows Gap', 'myhome-core'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2' => 'grid-row-gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'value_heading',
            [
                'label' => esc_html__('Value', 'myhome-core'),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $this->add_control(
            'value_color',
            [
                'label' => esc_html__('Color', 'myhome-core'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2__value' => 'color: {{VALUE}};',
                ]
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'value_typography',
                'label' => esc_html__('Typography', 'myhome-core'),
                'selector' => '{{WRAPPER}} .myhome-stats-v2__value',
            ]
        );

        $this->add_control(
            'label_heading',
            [
                'label' => esc_html__('Label', 'myhome-core'),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $this->add_control(
            'label_color',
            [
                'label' => esc_html__('Color', 'myhome-core'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2__label' => 'color: {{VALUE}};',
                ]
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'label_typography',
                'label' => esc_html__('Typography', 'myhome-core'),
                'selector' => '{{WRAPPER}} .myhome-stats-v2__label',
            ]
        );

        $this->add_control(
            'separator_heading',
            [
                'label' => esc_html__('Separator', 'myhome-core'),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $this->add_control(
            'separator_color',
            [
                'label' => esc_html__('Color', 'myhome-core'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2__label:before' => 'background-color: {{VALUE}};',
                ]
            ]
        );

        $this->add_responsive_control(
            'separator_width',
            [
                'label' => esc_html__('Width', 'myhome-core'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 30,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2__label:before' => 'width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'separator_spacing',
            [
                'label' => esc_html__('Spacing', 'myhome-core'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .myhome-stats-v2__label:before' => 'margin: 0 {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->endControlsSection();
    }
}