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

namespace Tangibledesign\MyHome\Widgets\General;

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

class PhoneWidget extends BaseGeneralWidget
{
    use TextAlignControl;
    use HasPhone;
    use HasIconWithContainer;
    use LinkStyleControls;

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

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

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

        $this->addGeneralStyleSection();

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

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

        $this->addPhoneStyleSection();
    }

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

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

        $this->endControlsSection();
    }

    public function getPhone(): string
    {
        $phone = (string)$this->get_settings_for_display('custom_phone');
        if (empty($phone)) {
            return tdf_settings()->getPhone();
        }

        return $phone;
    }

    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-phone-wrapper');

        $this->endControlsSection();
    }

    private function addPhoneStyleSection(): void
    {
        $this->startStyleControlsSection('phone', esc_html__('Phone', 'myhome-core'));

        $this->addLinkStyleControls('.myhome-phone');

        $this->endControlsSection();
    }
}