<?php
/**
 * Quick maintenance mode toggle (all admin tabs).
 *
 * @package MacaHold
 *
 * @var array<string, mixed> $settings
 * @var bool                $is_active
 */

defined( 'ABSPATH' ) || exit;

$maca_hold_schedule_controls = ! empty( $settings['schedule_enabled'] );
$maca_hold_manual_enabled    = ! empty( $settings['enabled'] );
$maca_hold_switch_checked    = $maca_hold_schedule_controls ? $is_active : $maca_hold_manual_enabled;
$maca_hold_maintenance_visible = Maca_Hold_Maintenance_Scope::is_maintenance_visible();
$maca_hold_status_text       = Maca_Hold_Maintenance_Scope::get_status_text();
?>
<div
	class="maca-hold-status-card maca-hold-maintenance-toggle-card <?php echo $maca_hold_maintenance_visible ? 'is-active' : 'is-inactive'; ?>"
	id="maca_hold_maintenance_toggle_card"
	data-schedule-controlled="<?php echo $maca_hold_schedule_controls ? '1' : '0'; ?>"
>
	<div class="maca-hold-maintenance-toggle-row">
		<label class="maca-hold-switch" for="maca_hold_maintenance_switch">
			<input
				type="checkbox"
				id="maca_hold_maintenance_switch"
				<?php checked( $maca_hold_switch_checked ); ?>
				<?php disabled( $maca_hold_schedule_controls ); ?>
				aria-describedby="maca_hold_maintenance_toggle_status"
			/>
			<span class="maca-hold-switch-slider" aria-hidden="true"></span>
			<span class="screen-reader-text"><?php echo esc_html__( 'Maintenance mode', 'maca-hold' ); ?></span>
		</label>

		<div class="maca-hold-maintenance-toggle-copy">
			<strong class="maca-hold-maintenance-toggle-title"><?php echo esc_html__( 'Maintenance mode', 'maca-hold' ); ?></strong>
			<p class="maca-hold-maintenance-toggle-status" id="maca_hold_maintenance_toggle_status">
				<?php echo esc_html( $maca_hold_status_text ); ?>
			</p>
			<?php if ( $maca_hold_schedule_controls ) : ?>
				<p class="description maca-hold-maintenance-toggle-schedule-note">
					<?php echo esc_html__( 'Scheduled maintenance is enabled. Turn off the schedule in settings to use this switch.', 'maca-hold' ); ?>
				</p>
			<?php endif; ?>
			<p class="description maca-hold-maintenance-toggle-feedback" id="maca_hold_maintenance_toggle_feedback" hidden></p>
		</div>
	</div>
</div>
