<script setup>
import { ref } from 'vue';
import BitcoinLogo from './components/BitcoinLogo.vue'

// Modes: 'auto', 'interactive', 'controlled'
const activeMode = ref('interactive');
const activeEasing = ref('linear');
const activeDuration = ref(4);
const activeFriction = ref(0.98);
const activeSymbolColor = ref('#ffffff');
const activeSize = ref(250);
const activeStrokeWidth = ref(5);
const externalRotation = ref(0);

const easingOptions = [
  'linear',
  'ease',
  'ease-in',
  'ease-out',
  'ease-in-out',
  'cubic-bezier(0.68, -0.55, 0.265, 1.55)' // bouncy
];

const handleRotationUpdate = (val) => {
  if (activeMode.value !== 'controlled') {
    externalRotation.value = val;
  }
};
</script>

<template>
  <div class="app-container">
    <div class="glass-card">
      <header>
        <h1>Bitcoin 3D</h1>
        <p>Premium 3D Bitcoin logo with multiple rotation modes.</p>
      </header>

      <main>
        <BitcoinLogo
          :mode="activeMode"
          :easing="activeEasing"
          :duration="activeDuration"
          :friction="activeFriction"
          :symbolColor="activeSymbolColor"
          :size="activeSize"
          :strokeWidth="activeStrokeWidth"
          v-model:rotation="externalRotation"
          @update:rotation="handleRotationUpdate"
        />
      </main>

      <footer>
        <div class="global-controls">
          <div class="color-control">
            <span class="label">SYMBOL COLOR</span>
            <input type="color" v-model="activeSymbolColor">
          </div>
          <div class="size-control">
            <span class="label">SIZE</span>
            <input type="range" v-model.number="activeSize" min="50" max="400" step="1">
            <span class="value">{{ activeSize }}px</span>
          </div>
          <div class="size-control">
            <span class="label">STROKE</span>
            <input type="range" v-model.number="activeStrokeWidth" min="0" max="20" step="0.5">
            <span class="value">{{ activeStrokeWidth }}px</span>
          </div>
        </div>
        <div class="mode-selector">
          <label
            v-for="mode in ['auto', 'interactive', 'controlled']"
            :key="mode"
            :class="{ active: activeMode === mode }"
          >
            <input type="radio" :value="mode" v-model="activeMode">
            {{ mode.toUpperCase() }}
          </label>
        </div>

        <div v-if="activeMode === 'auto'" class="control-panel">
          <div class="duration-control">
            <span class="label">SPEED</span>
            <input type="range" v-model.number="activeDuration" min="0.5" max="10" step="0.1">
            <span class="value">{{ activeDuration }}s</span>
          </div>
          <select v-model="activeEasing" class="easing-select">
            <option v-for="option in easingOptions" :key="option" :value="option">
              {{ option === 'cubic-bezier(0.68, -0.55, 0.265, 1.55)' ? 'BOUNCY' : option.toUpperCase() }}
            </option>
          </select>
        </div>

        <div v-if="activeMode === 'interactive'" class="control-panel">
          <div class="duration-control">
            <span class="label">INERTIA</span>
            <input type="range" v-model.number="activeFriction" min="0.8" max="0.999" step="0.001">
            <span class="value">{{ (activeFriction * 100).toFixed(1) }}%</span>
          </div>
        </div>

        <div v-if="activeMode === 'controlled'" class="control-panel">
          <input type="range" v-model.number="externalRotation" min="0" max="360" step="1">
          <span class="value">{{ externalRotation }}°</span>
        </div>

        <div class="badges">
          <div class="badge">Vue 3</div>
          <div class="badge">SVG 3D</div>
        </div>
      </footer>
    </div>
  </div>
</template>

<style scoped>
.app-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

main {
  margin: 2rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  position: relative;
}

header h1 {
  margin-top: 0;
}

footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  margin-top: 2rem;
}

.global-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 1rem 2rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 0.5rem;
}

.color-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-control .label {
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.05em;
}

.color-control input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.color-control input[type="color"]::-webkit-color-swatch {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.size-control {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 200px;
}

.size-control .label {
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.05em;
}

.size-control input[type="range"] {
  flex: 1;
  accent-color: #f7931a;
  height: 4px;
}

.size-control .value {
  font-family: monospace;
  min-width: 45px;
  font-size: 0.85rem;
  color: #f7931a;
}

.mode-selector {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-selector label {
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.3s ease;
  color: rgba(255, 255, 255, 0.6);
}

.mode-selector label.active {
  background: #f7931a;
  color: white;
  box-shadow: 0 4px 12px rgba(247, 147, 26, 0.3);
}

.mode-selector input {
  display: none;
}

.control-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 300px;
}

.duration-control {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.duration-control .label {
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.4);
  min-width: 50px;
}

.control-panel input[type="range"] {
  flex: 1;
  accent-color: #f7931a;
  height: 4px;
  border-radius: 2px;
}

.control-panel .value {
  font-family: monospace;
  min-width: 45px;
  font-size: 0.85rem;
  color: #f7931a;
}

.easing-select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  font-weight: 600;
  appearance: none;
  text-align: center;
}

.easing-select:focus {
  outline: none;
  border-color: #f7931a;
}

.badges {
  display: flex;
  gap: 1rem;
}

.badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.5rem 1rem;
  border-radius: 99px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.2);
}

@media (max-width: 640px) {
  h1 { font-size: 2.5rem; }
  .glass-card { padding: 2rem; margin: 1rem; }
}
</style>
