<script lang="ts">
  let {
    label,
    checked = $bindable(),
  }: {
    label: string;
    checked: boolean;
  } = $props();
</script>

<div class="switch-container">
  <span class="switch-label">{label}</span>
  <label class="switch">
    <input type="checkbox" bind:checked />
    <div class="track">
      <div class="knob" />
    </div>
  </label>
</div>

<style>
  .switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-family: "Press Start 2P", monospace;
  }

  .switch-label {
    font-size: 0.8rem;
  }

  .switch {
    position: relative;
    display: inline-block;
    width: 90px;
    height: 40px;
    cursor: pointer;
    user-select: none;
    transform: translateY(-50%);
  }

  .switch input {
    opacity: 0;
    width: 0;
    height: 0;
  }

  .track {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(
      145deg,
      var(--surface-alt-color) 0%,
      #1a1a1a 100%
    );
    border: 3px solid var(--accent-color);
    border-radius: 4px;
    box-shadow: 2px 2px 0 #000;
  }

  .switch:active .track {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 #000;
  }

  .knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 40px;
    height: 30px;
    background: linear-gradient(145deg, var(--primary-color) 0%, #d4af00 100%);
    border: 2px solid #000;
    border-radius: 2px;
    transition: transform 0.2s ease-in-out;
    z-index: 1;
    box-shadow:
      inset 0 0 2px rgba(255, 255, 255, 0.3),
      inset 0 0 5px rgba(0, 0, 0, 0.5);
  }

  input:checked ~ .track .knob {
    transform: translateX(41px);
  }
</style>
