<?php

namespace Elementor\Core\Kits\Documents\Tabs;
use Elementor\Core\Base\Document;
use Elementor\Controls_Manager;

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

class Settings_Color_Mode extends Tab_Base {

    public function get_id() {
        return 'settings-color-mode';
    }

    public function get_title() {
        return esc_html__( 'Color Mode', 'pakrco' );
    }

    public function get_group() {
        return 'settings';
    }

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

    protected function register_tab_controls() {
        $this->start_controls_section(
            'section_' . $this->get_id(),
            [
                'label' => $this->get_title(),
                'tab' => $this->get_id(),
            ]
        );

        $this->add_control(
            $this->get_id() . '_refresh_notice',
            [
                'type' => Controls_Manager::RAW_HTML,
                'raw' => esc_html__( 'Changes will be reflected in the preview only after the page reloads.', 'pakrco' ),
                'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
            ]
        );

        $this->add_control(
            'lb_color_mode',
            [
                'label' => esc_html__( 'Dark Mode', 'pakrco' ),
                'type' => Controls_Manager::SWITCHER,
                'default'     => pakrco_get_theme_option('lb_color_mode','no'),
            ]
        );

        $this->end_controls_section();
    }

    public function on_save( $data ) {
        if (
            ! isset( $data['settings']['post_status'] ) ||
            Document::STATUS_PUBLISH !== $data['settings']['post_status'] ||
            // Should check for the current action to avoid infinite loop
            strpos( current_action(), 'update_option_' ) === 0
        ) {
            return;
        }

        if ( isset( $data['settings']['lb_color_mode'] ) ) {
            update_option( 'pakrco_options_lb_color_mode', $data['settings']['lb_color_mode'] );
        }
    }
}
