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

namespace Tangibledesign\MyHome\Widgets\General;

use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Tangibledesign\Framework\Widgets\Helpers\BaseGeneralWidget;
use Tangibledesign\Framework\Widgets\Helpers\Controls\TextAlignControl;
use Tangibledesign\MyHome\Widgets\Helpers\Controls\HasIconWithContainer;

class AddressWidget extends BaseGeneralWidget
{
    use HasIconWithContainer;
    use TextAlignControl;

    public function getKey(): string
    {
        return 'address';
    }

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

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

        $this->addGeneralStyleSection();

        $this->addIconContainerStyleSection('.myhome-small-icon');

        $this->addIconStyleSection('.myhome-small-icon');

        $this->addAddressStyleSection();
    }

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

        $this->add_control(
            'custom_address',
            [
                'label' => esc_html__('Address', 'myhome-core'),
                'type' => Controls_Manager::TEXT,
            ]
        );

        $this->endControlsSection();
    }

    public function getAddress(): string
    {
        $address = (string)$this->get_settings_for_display('custom_address');
        if (empty($address)) {
            return tdf_settings()->getAddress();
        }

        return $address;
    }

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

        $this->add_responsive_control(
            'show_icon',
            [
                'label' => esc_html__('Display Icon', 'myhome-core'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'block' => esc_html__('Show', 'myhome-core'),
                    'none' => esc_html__('Hide', 'myhome-core')
                ],
                'default' => 'block',
                'selectors' => [
                    '{{WRAPPER}} .myhome-small-data__icon' => 'display: {{VALUE}};'
                ]
            ]
        );

        $this->addTextAlignControl('.myhome-address');

        $this->endControlsSection();
    }

    private function addAddressStyleSection(): void
    {
        $this->startStyleControlsSection('address', esc_html__('Address', 'myhome-core'));

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

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

        $this->endControlsSection();
    }
}