<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRaidableBasesStore } from '@/stores/raidablebases'
import {
  Save,
  Play,
  Download,
  Plus,
  Trash2,
  Swords,
  Settings as SettingsIcon,
  Shield,
  Users,
  Gift,
} from 'lucide-vue-next'

const store = useRaidableBasesStore()

const activeTab = ref<'general' | 'difficulty' | 'npc' | 'loot'>('general')
const activeDifficulty = ref<string>('Easy')
const showCreateModal = ref(false)
const showImportModal = ref(false)
const newConfigName = ref('')
const newConfigDesc = ref('')
const importConfigName = ref('')

const tabs = [
  { key: 'general', label: 'General', icon: SettingsIcon },
  { key: 'difficulty', label: 'Difficulty', icon: Shield },
  { key: 'npc', label: 'NPC Settings', icon: Users },
  { key: 'loot', label: 'Loot & Rewards', icon: Gift },
]

const difficulties = ['Easy', 'Medium', 'Hard', 'Expert', 'Nightmare']

onMounted(async () => {
  await store.fetchConfigs()
  if (store.configs.length > 0 && store.configs[0]) {
    await store.loadConfig(store.configs[0].id)
  }
})

// --- Config data helpers ---

function getConfigValue(path: string, defaultValue: any = false): any {
  if (!store.currentConfig?.config_data) return defaultValue
  const parts = path.split('.')
  let current: any = store.currentConfig.config_data
  for (const part of parts) {
    if (current == null || typeof current !== 'object') return defaultValue
    current = current[part]
  }
  return current ?? defaultValue
}

function setConfigValue(path: string, value: any) {
  if (!store.currentConfig) return
  if (!store.currentConfig.config_data) store.currentConfig.config_data = {}
  const parts = path.split('.')
  let current: any = store.currentConfig.config_data
  for (let i = 0; i < parts.length - 1; i++) {
    const part = parts[i]!
    if (current[part] == null || typeof current[part] !== 'object') {
      current[part] = {}
    }
    current = current[part]
  }
  current[parts[parts.length - 1]!] = value
  store.markDirty()
}

// --- Action handlers ---

async function handleConfigChange(id: string) {
  if (store.isDirty) {
    if (!confirm('Unsaved changes will be lost. Continue?')) return
  }
  await store.loadConfig(id)
}

async function handleCreateConfig() {
  if (!newConfigName.value.trim()) return
  const config = await store.createConfig(
    newConfigName.value.trim(),
    newConfigDesc.value.trim() || undefined,
  )
  if (config) {
    showCreateModal.value = false
    newConfigName.value = ''
    newConfigDesc.value = ''
  }
}

async function handleDeleteConfig() {
  if (!store.currentConfig) return
  if (!confirm(`Delete "${store.currentConfig.config_name}"? This cannot be undone.`)) return
  await store.deleteConfig(store.currentConfig.id)
}

async function handleApply() {
  if (!store.currentConfig) return
  if (!confirm('Apply this RaidableBases config to the server? This will overwrite the current config.')) return
  if (store.isDirty) {
    await store.saveCurrentConfig()
  }
  await store.applyToServer(store.currentConfig.id)
}

async function handleImport() {
  if (!importConfigName.value.trim()) return
  const config = await store.importFromServer(importConfigName.value.trim())
  if (config) {
    showImportModal.value = false
    importConfigName.value = ''
  }
}
</script>

<template>
  <div class="p-6 space-y-6">
    <!-- Header -->
    <div class="flex items-center justify-between">
      <h1 class="text-2xl font-bold text-white">Raidable Bases</h1>
      <div class="flex items-center gap-3">
        <button
          @click="showCreateModal = true"
          class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
        >
          <Plus class="w-4 h-4" />
          New Config
        </button>
      </div>
    </div>

    <!-- Config Selector + Action Bar -->
    <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-4">
      <div class="flex items-center gap-3 flex-wrap">
        <!-- Config Selector -->
        <select
          v-if="store.configs.length > 0"
          :value="store.currentConfig?.id || ''"
          @change="handleConfigChange(($event.target as HTMLSelectElement).value)"
          class="bg-neutral-800 border border-neutral-700 text-neutral-200 rounded-lg px-3 py-2 text-sm min-w-[200px]"
        >
          <option v-for="c in store.configs" :key="c.id" :value="c.id">
            {{ c.config_name }}
            <template v-if="c.is_active"> (Active)</template>
          </option>
        </select>
        <span v-else class="text-neutral-500 text-sm">No configs yet</span>

        <!-- Save -->
        <button
          @click="store.saveCurrentConfig()"
          :disabled="!store.currentConfig || !store.isDirty || store.isSaving"
          class="flex items-center gap-2 px-3 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
        >
          <Save class="w-4 h-4" />
          {{ store.isSaving ? 'Saving...' : 'Save' }}
        </button>

        <!-- Apply to Server -->
        <button
          @click="handleApply"
          :disabled="!store.currentConfig || store.isApplying"
          class="flex items-center gap-2 px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
        >
          <Play class="w-4 h-4" />
          {{ store.isApplying ? 'Applying...' : 'Apply to Server' }}
        </button>

        <!-- Import from Server -->
        <button
          @click="showImportModal = true"
          class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
        >
          <Download class="w-4 h-4" />
          Import from Server
        </button>

        <!-- Delete -->
        <button
          @click="handleDeleteConfig"
          :disabled="!store.currentConfig"
          class="flex items-center gap-2 px-3 py-2 bg-red-500/10 text-red-400 rounded-lg hover:bg-red-500/20 disabled:opacity-50 text-sm ml-auto"
        >
          <Trash2 class="w-4 h-4" />
          Delete
        </button>
      </div>
    </div>

    <!-- Loading State -->
    <div v-if="store.isLoading" class="flex items-center justify-center py-20">
      <div class="animate-spin w-8 h-8 border-2 border-oxide-500 border-t-transparent rounded-full" />
    </div>

    <!-- No Config Selected -->
    <div v-else-if="!store.currentConfig" class="bg-neutral-900 border border-neutral-800 rounded-xl p-12 text-center">
      <Swords class="w-12 h-12 text-neutral-600 mx-auto mb-4" />
      <h2 class="text-lg font-semibold text-neutral-300 mb-2">No Raidable Bases Config Selected</h2>
      <p class="text-neutral-500 mb-4">Create a new config, import from server, or select one from the dropdown above.</p>
      <button
        @click="showCreateModal = true"
        class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600"
      >
        Create First Config
      </button>
    </div>

    <!-- Config Editor -->
    <div v-else class="space-y-6">
      <!-- Tab Bar -->
      <div class="flex border-b border-neutral-800">
        <button
          v-for="tab in tabs"
          :key="tab.key"
          @click="activeTab = tab.key as typeof activeTab"
          class="flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors"
          :class="activeTab === tab.key
            ? 'border-oxide-500 text-oxide-400'
            : 'border-transparent text-neutral-500 hover:text-neutral-300'"
        >
          <component :is="tab.icon" class="w-4 h-4" />
          {{ tab.label }}
        </button>
      </div>

      <!-- ======================= GENERAL TAB ======================= -->
      <div v-if="activeTab === 'general'" class="space-y-6">
        <!-- Maintained Events Section -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Maintained Events</h3>
          <p class="text-xs text-neutral-500 -mt-4">Maintained events keep a set number of raid bases on the map at all times. When one is cleared, a new one spawns.</p>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Always Maintain Max Events -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Always Maintain Max Events</label>
                <p class="text-xs text-neutral-500">Keep spawning bases to maintain the max count</p>
              </div>
              <button
                @click="setConfigValue('Settings.Maintained Events.Always Maintain Max Events', !getConfigValue('Settings.Maintained Events.Always Maintain Max Events', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Maintained Events.Always Maintain Max Events', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Maintained Events.Always Maintain Max Events', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Maintained Include PVE Day -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Include PVE Day</label>
                <p class="text-xs text-neutral-500">Spawn PVE bases during daytime</p>
              </div>
              <button
                @click="setConfigValue('Settings.Maintained Events.Include PVE Day', !getConfigValue('Settings.Maintained Events.Include PVE Day', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Maintained Events.Include PVE Day', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Maintained Events.Include PVE Day', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Maintained Include PVP Day -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Include PVP Day</label>
                <p class="text-xs text-neutral-500">Spawn PVP bases during daytime</p>
              </div>
              <button
                @click="setConfigValue('Settings.Maintained Events.Include PVP Day', !getConfigValue('Settings.Maintained Events.Include PVP Day', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Maintained Events.Include PVP Day', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Maintained Events.Include PVP Day', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Maintained Include PVE Night -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Include PVE Night</label>
                <p class="text-xs text-neutral-500">Spawn PVE bases during nighttime</p>
              </div>
              <button
                @click="setConfigValue('Settings.Maintained Events.Include PVE Night', !getConfigValue('Settings.Maintained Events.Include PVE Night', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Maintained Events.Include PVE Night', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Maintained Events.Include PVE Night', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Max Maintained Events</label>
              <p class="text-xs text-neutral-500 mb-2">Maximum number of raid bases on map at once</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Maintained Events.Max Maintained Events', 1)"
                @input="setConfigValue('Settings.Maintained Events.Max Maintained Events', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Min Players Online</label>
              <p class="text-xs text-neutral-500 mb-2">Minimum players required before bases spawn</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Maintained Events.Minimum Required Players Online', 0)"
                @input="setConfigValue('Settings.Maintained Events.Minimum Required Players Online', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Chance PVP (%)</label>
              <p class="text-xs text-neutral-500 mb-2">Chance to randomly spawn PVP bases (0-100)</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Maintained Events.Chance To Randomly Spawn PVP Bases', 0)"
                @input="setConfigValue('Settings.Maintained Events.Chance To Randomly Spawn PVP Bases', Number(($event.target as HTMLInputElement).value))"
                min="0"
                max="100"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- Scheduled Events Section -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Scheduled Events</h3>
          <p class="text-xs text-neutral-500 -mt-4">Scheduled events spawn raid bases at random intervals. Configure timing and limits below.</p>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Enabled -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Enabled</label>
                <p class="text-xs text-neutral-500">Enable scheduled event spawns</p>
              </div>
              <button
                @click="setConfigValue('Settings.Scheduled Events.Enabled', !getConfigValue('Settings.Scheduled Events.Enabled', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Scheduled Events.Enabled', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Scheduled Events.Enabled', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Include PVP Day -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Include PVP Day</label>
                <p class="text-xs text-neutral-500">Spawn PVP scheduled bases during day</p>
              </div>
              <button
                @click="setConfigValue('Settings.Scheduled Events.Include PVP Day', !getConfigValue('Settings.Scheduled Events.Include PVP Day', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Scheduled Events.Include PVP Day', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Scheduled Events.Include PVP Day', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Every Min Seconds</label>
              <p class="text-xs text-neutral-500 mb-2">Minimum time between spawns</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Scheduled Events.Every Min Seconds', 3600)"
                @input="setConfigValue('Settings.Scheduled Events.Every Min Seconds', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Every Max Seconds</label>
              <p class="text-xs text-neutral-500 mb-2">Maximum time between spawns</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Scheduled Events.Every Max Seconds', 7200)"
                @input="setConfigValue('Settings.Scheduled Events.Every Max Seconds', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Max Scheduled Events</label>
              <p class="text-xs text-neutral-500 mb-2">Maximum concurrent scheduled bases</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Scheduled Events.Max Scheduled Events', 1)"
                @input="setConfigValue('Settings.Scheduled Events.Max Scheduled Events', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Min Players Online</label>
              <p class="text-xs text-neutral-500 mb-2">Required players for scheduled events</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Scheduled Events.Minimum Required Players Online', 0)"
                @input="setConfigValue('Settings.Scheduled Events.Minimum Required Players Online', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- General Settings -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">General Settings</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Expansion Mode -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Expansion Mode</label>
                <p class="text-xs text-neutral-500">Use Expansion Mode for spawning calculations</p>
              </div>
              <button
                @click="setConfigValue('Settings.Expansion Mode', !getConfigValue('Settings.Expansion Mode', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Expansion Mode', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Expansion Mode', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Show XZ Coordinates -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Show X Z Coordinates</label>
                <p class="text-xs text-neutral-500">Show base coordinates in chat announcements</p>
              </div>
              <button
                @click="setConfigValue('Settings.Show X Z Coordinates', !getConfigValue('Settings.Show X Z Coordinates', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Show X Z Coordinates', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Show X Z Coordinates', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Remove Admins From Raiders List -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Remove Admins From Raiders List</label>
                <p class="text-xs text-neutral-500">Exclude admins from the raiders tracking list</p>
              </div>
              <button
                @click="setConfigValue('Settings.Remove Admins From Raiders List', !getConfigValue('Settings.Remove Admins From Raiders List', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Remove Admins From Raiders List', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Remove Admins From Raiders List', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Block Wizardry Plugin -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Block Wizardry Plugin At Events</label>
                <p class="text-xs text-neutral-500">Prevent Wizardry plugin use during raid events</p>
              </div>
              <button
                @click="setConfigValue('Settings.Block Wizardry Plugin At Events', !getConfigValue('Settings.Block Wizardry Plugin At Events', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Block Wizardry Plugin At Events', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Block Wizardry Plugin At Events', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Amount Of Entities To Undo Per Batch</label>
              <p class="text-xs text-neutral-500 mb-2">Entities cleaned per batch during despawn</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Amount Of Entities To Undo Per Batch', 5)"
                @input="setConfigValue('Settings.Amount Of Entities To Undo Per Batch', Number(($event.target as HTMLInputElement).value))"
                min="1"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- GUI Announcements -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">GUI Announcements</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Enabled</label>
                <p class="text-xs text-neutral-500">Show GUI announcement banners for events</p>
              </div>
              <button
                @click="setConfigValue('GUIAnnouncements.Enabled', !getConfigValue('GUIAnnouncements.Enabled', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('GUIAnnouncements.Enabled', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('GUIAnnouncements.Enabled', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Banner Tint Color</label>
              <p class="text-xs text-neutral-500 mb-2">Color of the announcement banner</p>
              <input
                type="text"
                :value="getConfigValue('GUIAnnouncements.Banner Tint Color', 'Grey')"
                @input="setConfigValue('GUIAnnouncements.Banner Tint Color', ($event.target as HTMLInputElement).value)"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Text Color</label>
              <p class="text-xs text-neutral-500 mb-2">Color of the announcement text</p>
              <input
                type="text"
                :value="getConfigValue('GUIAnnouncements.Text Color', 'White')"
                @input="setConfigValue('GUIAnnouncements.Text Color', ($event.target as HTMLInputElement).value)"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Maximum Distance</label>
              <p class="text-xs text-neutral-500 mb-2">Max distance to show announcements</p>
              <input
                type="number"
                :value="getConfigValue('GUIAnnouncements.Maximum Distance', 300)"
                @input="setConfigValue('GUIAnnouncements.Maximum Distance', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>
      </div>

      <!-- ======================= DIFFICULTY TAB ======================= -->
      <div v-else-if="activeTab === 'difficulty'" class="space-y-6">
        <!-- Difficulty Sub-tabs -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-4">
          <div class="flex gap-2 flex-wrap">
            <button
              v-for="diff in difficulties"
              :key="diff"
              @click="activeDifficulty = diff"
              class="px-4 py-2 text-sm rounded-lg transition-colors"
              :class="activeDifficulty === diff
                ? 'bg-oxide-500 text-white'
                : 'bg-neutral-800 text-neutral-400 hover:text-neutral-200 hover:bg-neutral-700'"
            >
              {{ diff }}
            </button>
          </div>
        </div>

        <!-- Difficulty Settings -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">{{ activeDifficulty }} Difficulty Settings</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Enabled -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Enabled</label>
                <p class="text-xs text-neutral-500">Allow {{ activeDifficulty.toLowerCase() }} difficulty bases to spawn</p>
              </div>
              <button
                @click="setConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.Enabled`, !getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.Enabled`, true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.Enabled`, true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.Enabled`, true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <!-- Spawn Day Toggles -->
          <div>
            <h4 class="text-xs font-medium text-neutral-400 uppercase mb-3">Spawn Days</h4>
            <div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3">
              <div
                v-for="day in ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']"
                :key="day"
                class="flex items-center gap-2"
              >
                <button
                  @click="setConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.${day}`, !getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.${day}`, true))"
                  class="relative w-9 h-5 rounded-full transition-colors flex-shrink-0"
                  :class="getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.${day}`, true) ? 'bg-oxide-500' : 'bg-neutral-700'"
                >
                  <span
                    class="absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform"
                    :class="getConfigValue(`Settings.Raid Management.${activeDifficulty} Raids Can Spawn On.${day}`, true) ? 'translate-x-4' : 'translate-x-0'"
                  />
                </button>
                <span class="text-xs text-neutral-300">{{ day.slice(0, 3) }}</span>
              </div>
            </div>
          </div>

          <!-- Difficulty Colors -->
          <div>
            <h4 class="text-xs font-medium text-neutral-400 uppercase mb-3">Map Marker Colors</h4>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
              <div>
                <label class="block text-sm text-neutral-200 mb-1">Border Color</label>
                <p class="text-xs text-neutral-500 mb-2">Map marker border color for {{ activeDifficulty.toLowerCase() }} bases</p>
                <input
                  type="text"
                  :value="getConfigValue(`Settings.Raid Management.${activeDifficulty} Difficulty Colors.Border`, '')"
                  @input="setConfigValue(`Settings.Raid Management.${activeDifficulty} Difficulty Colors.Border`, ($event.target as HTMLInputElement).value)"
                  placeholder="e.g. 00FF00"
                  class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
                />
              </div>
              <div>
                <label class="block text-sm text-neutral-200 mb-1">Inner Color</label>
                <p class="text-xs text-neutral-500 mb-2">Map marker fill color for {{ activeDifficulty.toLowerCase() }} bases</p>
                <input
                  type="text"
                  :value="getConfigValue(`Settings.Raid Management.${activeDifficulty} Difficulty Colors.Inner`, '')"
                  @input="setConfigValue(`Settings.Raid Management.${activeDifficulty} Difficulty Colors.Inner`, ($event.target as HTMLInputElement).value)"
                  placeholder="e.g. 00CC00"
                  class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
                />
              </div>
            </div>
          </div>
        </div>

        <!-- Ranked Ladder -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Ranked Ladder</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Enabled</label>
                <p class="text-xs text-neutral-500">Track and display a ranked leaderboard</p>
              </div>
              <button
                @click="setConfigValue('Ranked Ladder.Enabled', !getConfigValue('Ranked Ladder.Enabled', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Ranked Ladder.Enabled', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Ranked Ladder.Enabled', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="max-w-sm">
            <label class="block text-sm text-neutral-200 mb-1">Award Top X Players On Wipe</label>
            <p class="text-xs text-neutral-500 mb-2">Number of top players to award on server wipe</p>
            <input
              type="number"
              :value="getConfigValue('Ranked Ladder.Award Top X Players On Wipe', 3)"
              @input="setConfigValue('Ranked Ladder.Award Top X Players On Wipe', Number(($event.target as HTMLInputElement).value))"
              min="0"
              class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
            />
          </div>
        </div>
      </div>

      <!-- ======================= NPC SETTINGS TAB ======================= -->
      <div v-else-if="activeTab === 'npc'" class="space-y-6">
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">NPC Configuration</h3>
          <p class="text-xs text-neutral-500 -mt-4">Configure NPC guardians for raid bases. Per-profile NPC settings override these globals when set in profile files.</p>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Eject Mounts -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Eject Mounts</label>
                <p class="text-xs text-neutral-500">Eject players from mounts when entering raid zone</p>
              </div>
              <button
                @click="setConfigValue('Settings.Raid Management.Eject Mounts', !getConfigValue('Settings.Raid Management.Eject Mounts', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Raid Management.Eject Mounts', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Raid Management.Eject Mounts', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <!-- Despawn Minutes Inactive Reset -->
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Reset Despawn Timer on Damage</label>
                <p class="text-xs text-neutral-500">Reset inactive despawn timer when base takes damage</p>
              </div>
              <button
                @click="setConfigValue('Settings.Raid Management.Despawn Minutes Inactive Reset', !getConfigValue('Settings.Raid Management.Despawn Minutes Inactive Reset', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Settings.Raid Management.Despawn Minutes Inactive Reset', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Settings.Raid Management.Despawn Minutes Inactive Reset', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Despawn Minutes Inactive</label>
              <p class="text-xs text-neutral-500 mb-2">Minutes before an untouched base despawns</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Raid Management.Despawn Minutes Inactive', 45)"
                @input="setConfigValue('Settings.Raid Management.Despawn Minutes Inactive', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Max Amount Allowed To Enter</label>
              <p class="text-xs text-neutral-500 mb-2">Max players allowed inside a raid base at once</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Raid Management.Max Amount Allowed To Enter', 0)"
                @input="setConfigValue('Settings.Raid Management.Max Amount Allowed To Enter', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Max Amount Allowed To Enter Maintained</label>
              <p class="text-xs text-neutral-500 mb-2">Max players for maintained event bases (0 = unlimited)</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Raid Management.Max Amount Allowed To Enter Maintained', 0)"
                @input="setConfigValue('Settings.Raid Management.Max Amount Allowed To Enter Maintained', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- Weapons Section -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Weapons & Defenses</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Turret Health</label>
              <p class="text-xs text-neutral-500 mb-2">Health of auto turrets in bases</p>
              <input
                type="number"
                :value="getConfigValue('Weapons.Turret Health', 1000)"
                @input="setConfigValue('Weapons.Turret Health', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">SamSite Range</label>
              <p class="text-xs text-neutral-500 mb-2">Range of SAM site defenses (meters)</p>
              <input
                type="number"
                :value="getConfigValue('Weapons.SamSite Range', 150)"
                @input="setConfigValue('Weapons.SamSite Range', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Turret Starting Ammo</label>
              <p class="text-xs text-neutral-500 mb-2">Ammo loaded in auto turrets at spawn</p>
              <input
                type="number"
                :value="getConfigValue('Weapons.Starting Ammo', 256)"
                @input="setConfigValue('Weapons.Starting Ammo', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- TruePVE Section -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">TruePVE Integration</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Server Wide PVP</label>
                <p class="text-xs text-neutral-500">Enable server-wide PVP during raid events</p>
              </div>
              <button
                @click="setConfigValue('TruePVE.Server Wide PVP', !getConfigValue('TruePVE.Server Wide PVP', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('TruePVE.Server Wide PVP', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('TruePVE.Server Wide PVP', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Allow PVP At Events</label>
                <p class="text-xs text-neutral-500">Allow PVP in the raid base area</p>
              </div>
              <button
                @click="setConfigValue('TruePVE.Allow PVP At Events', !getConfigValue('TruePVE.Allow PVP At Events', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('TruePVE.Allow PVP At Events', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('TruePVE.Allow PVP At Events', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>
        </div>
      </div>

      <!-- ======================= LOOT & REWARDS TAB ======================= -->
      <div v-else-if="activeTab === 'loot'" class="space-y-6">
        <!-- Treasure / Loot Settings -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Loot Settings</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Use Random Skins</label>
                <p class="text-xs text-neutral-500">Randomize skins on loot items</p>
              </div>
              <button
                @click="setConfigValue('Treasure.Use Random Skins', !getConfigValue('Treasure.Use Random Skins', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Treasure.Use Random Skins', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Treasure.Use Random Skins', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Include Workshop Skins</label>
                <p class="text-xs text-neutral-500">Include workshop skins in randomization</p>
              </div>
              <button
                @click="setConfigValue('Skins.Include Workshop Skins', !getConfigValue('Skins.Include Workshop Skins', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Skins.Include Workshop Skins', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Skins.Include Workshop Skins', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Randomize NPC Item Skins</label>
                <p class="text-xs text-neutral-500">Randomize skins on NPC equipment</p>
              </div>
              <button
                @click="setConfigValue('Skins.Randomize Npc Item Skins', !getConfigValue('Skins.Randomize Npc Item Skins', true))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Skins.Randomize Npc Item Skins', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Skins.Randomize Npc Item Skins', true) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Use Day Of Week Loot</label>
                <p class="text-xs text-neutral-500">Vary loot tables based on day of week</p>
              </div>
              <button
                @click="setConfigValue('Treasure.Use Day Of Week Loot', !getConfigValue('Treasure.Use Day Of Week Loot', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('Treasure.Use Day Of Week Loot', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('Treasure.Use Day Of Week Loot', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Amount Of Items To Spawn</label>
              <p class="text-xs text-neutral-500 mb-2">Number of loot items per container</p>
              <input
                type="number"
                :value="getConfigValue('Treasure.Amount Of Items To Spawn', 6)"
                @input="setConfigValue('Treasure.Amount Of Items To Spawn', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>
        </div>

        <!-- Buyable Events -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Buyable Events</h3>
          <p class="text-xs text-neutral-500 -mt-4">Allow players to purchase raid events using Economics or ServerRewards currency.</p>

          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            <div>
              <label class="block text-sm text-neutral-200 mb-1">Max Buyable Events</label>
              <p class="text-xs text-neutral-500 mb-2">Maximum concurrent purchased events (0 = disabled)</p>
              <input
                type="number"
                :value="getConfigValue('Settings.Buyable Events.Max Buyable Events', 0)"
                @input="setConfigValue('Settings.Buyable Events.Max Buyable Events', Number(($event.target as HTMLInputElement).value))"
                min="0"
                class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              />
            </div>
          </div>

          <div>
            <h4 class="text-xs font-medium text-neutral-400 uppercase mb-3">Economics Buy Costs</h4>
            <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
              <div v-for="diff in difficulties" :key="diff">
                <label class="block text-sm text-neutral-200 mb-1">{{ diff }}</label>
                <input
                  type="number"
                  :value="getConfigValue(`Economics Buy Raid Costs.${diff}`, 0)"
                  @input="setConfigValue(`Economics Buy Raid Costs.${diff}`, Number(($event.target as HTMLInputElement).value))"
                  min="0"
                  class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
                />
              </div>
            </div>
          </div>

          <div>
            <h4 class="text-xs font-medium text-neutral-400 uppercase mb-3">ServerRewards Buy Costs</h4>
            <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
              <div v-for="diff in difficulties" :key="diff">
                <label class="block text-sm text-neutral-200 mb-1">{{ diff }}</label>
                <input
                  type="number"
                  :value="getConfigValue(`ServerRewards Buy Raid Costs.${diff}`, 0)"
                  @input="setConfigValue(`ServerRewards Buy Raid Costs.${diff}`, Number(($event.target as HTMLInputElement).value))"
                  min="0"
                  class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
                />
              </div>
            </div>
          </div>
        </div>

        <!-- UI Settings -->
        <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
          <h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">UI Settings</h3>

          <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Buyable UI Enabled</label>
                <p class="text-xs text-neutral-500">Show in-game UI for purchasing raid events</p>
              </div>
              <button
                @click="setConfigValue('UI.Buyable UI.Enabled', !getConfigValue('UI.Buyable UI.Enabled', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('UI.Buyable UI.Enabled', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('UI.Buyable UI.Enabled', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>

            <div class="flex items-center justify-between">
              <div>
                <label class="text-sm text-neutral-200">Lockouts UI Enabled</label>
                <p class="text-xs text-neutral-500">Show lockout timer UI for players</p>
              </div>
              <button
                @click="setConfigValue('UI.Lockouts.Enabled', !getConfigValue('UI.Lockouts.Enabled', false))"
                class="relative w-11 h-6 rounded-full transition-colors"
                :class="getConfigValue('UI.Lockouts.Enabled', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
              >
                <span
                  class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
                  :class="getConfigValue('UI.Lockouts.Enabled', false) ? 'translate-x-5' : 'translate-x-0'"
                />
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Create Config Modal -->
    <div v-if="showCreateModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showCreateModal = false">
      <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
        <h2 class="text-lg font-semibold text-neutral-100 mb-4">New Raidable Bases Config</h2>
        <div class="space-y-4">
          <div>
            <label class="block text-sm text-neutral-400 mb-1">Config Name</label>
            <input
              v-model="newConfigName"
              placeholder="e.g. Default RaidableBases Settings"
              class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              @keydown.enter="handleCreateConfig"
            />
          </div>
          <div>
            <label class="block text-sm text-neutral-400 mb-1">Description (optional)</label>
            <textarea
              v-model="newConfigDesc"
              rows="2"
              placeholder="What is this config for?"
              class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm resize-none"
            />
          </div>
          <div class="flex justify-end gap-2">
            <button @click="showCreateModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
            <button
              @click="handleCreateConfig"
              :disabled="!newConfigName.trim()"
              class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
            >
              Create
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- Import from Server Modal -->
    <div v-if="showImportModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showImportModal = false">
      <div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
        <h2 class="text-lg font-semibold text-neutral-100 mb-4">Import from Server</h2>
        <p class="text-sm text-neutral-400 mb-4">
          Import the current RaidableBases config from your live server. This will create a new config profile.
        </p>
        <div class="space-y-4">
          <div>
            <label class="block text-sm text-neutral-400 mb-1">Config Name</label>
            <input
              v-model="importConfigName"
              placeholder="e.g. Imported Server Config"
              class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
              @keydown.enter="handleImport"
            />
          </div>
          <div class="flex justify-end gap-2">
            <button @click="showImportModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
            <button
              @click="handleImport"
              :disabled="!importConfigName.trim()"
              class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
            >
              Import
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
