<?php

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

class Reactify_Switcher extends Reactify_Field {
    private $checked;
    private $unchecked;

    public function setChecked($checked) {
        $this->checked = $checked;
        return $this;
    }

    public function setUnchecked($unchecked) {
        $this->unchecked = $unchecked;
        return $this;
    }

    public function build() {
        // Determine if the switch should be checked
        $isChecked = ($this->value == $this->checked) ? 'checked' : '';

        // Determine the name of the input
        $name = empty($this->name) ? $this->id : $this->name;

        // Determine if disabled
        $disabled = $this->disabled ? 'disabled' : '';

        echo "<div class='reactify-switch-wrap " . esc_attr($this->classes) . "'>";

        // Render label with HTML allowed for icons
        if ($this->label != '') {
            echo "<h3 class='reactify-switch-title'>" . wp_kses_post($this->label) . "</h3>";
        }

        echo '<label class="reactify-switch">';
        echo "<input 
                id='" . esc_attr($this->id) . "' 
                name='" . esc_attr($name) . "' 
                type='checkbox' 
                class='reactify-switch-input' 
                " . esc_attr($isChecked) . " 
                " . esc_attr($disabled) . " 
                value='" . esc_attr($this->checked) . "'>";
        echo '<span class="reactify-slider"></span>'; // Optional: slider for styling
        echo '</label>';
        echo '</div>';
    }
}