<?php
namespace Storzen\Fields;
use Storzen\Contracts\Field;
defined('ABSPATH') || exit;

class Toggle extends Field {
    public function sanitize( $raw ) { return (bool) $raw; }
    public function render( $value ) {
    $id = $this->field_id();
    $checked = checked( (bool)$value, true, false );
    $dis     = $this->dis();
    $is_pro_active = defined('STORZEN_IS_PRO') && STORZEN_IS_PRO === 'yes';
    $show_pro = $this->pro && ! $is_pro_active;
    echo '<label class="sz-toggle' . ( $show_pro ? ' sz-toggle--disabled' : '' ) . '" for="' . esc_attr($id) . '">';
    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $checked and $dis return escaped HTML attributes
    echo '<input type="checkbox" id="' . esc_attr($id) . '" name="' . esc_attr($this->field_name()) . '" value="1" ' . $checked . ( $show_pro ? ' disabled' : '' ) . '>';
    echo '<span class="sz-toggle__track"></span>';
    echo '</label>';
    if ( $show_pro ) echo '<span class="sz-pro-badge">PRO</span>';
    }
}
