<script setup lang="ts">
import { computed } from 'vue'
import { useSettingsStore } from '../stores/settings'

const settingsStore = useSettingsStore()

const dockItems = [
  {
    id: 'openlist',
    name: 'OpenList',
    url: 'https://openlist.wufangzhen.com',
    icon: 'M4 6h16M4 12h16M4 18h16'
  },
  {
    id: 'gitea',
    name: 'Gitea',
    url: 'https://gitea.wufangzhen.com',
    icon: 'M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5'
  },
  {
    id: 'baota',
    name: '宝塔',
    url: 'https://baota.wufangzhen.com',
    icon: 'M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z'
  },
  {
    id: 'jrebel',
    name: 'JRebel',
    url: 'https://jrebel.wufangzhen.com',
    icon: 'M13 10V3L4 14h7v7l9-11h-7z'
  }
]

const isMobile = computed(() => settingsStore.isMobile)

function openSettings() {
  settingsStore.openWindow('settings')
}
</script>

<template>
  <div class="dock" :class="{ 'dock-mobile': isMobile }">
    <div class="dock-container">
      <a
        v-for="item in dockItems"
        :key="item.id"
        :href="item.url"
        target="_blank"
        rel="noopener noreferrer"
        class="dock-item"
      >
        <div class="dock-icon">
          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
            <path :d="item.icon" />
          </svg>
        </div>
        <div class="dock-tooltip">{{ item.name }}</div>
      </a>
      <button class="dock-item settings-btn" @click="openSettings">
        <div class="dock-icon">
          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
            <path d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
            <circle cx="12" cy="12" r="3" />
          </svg>
        </div>
        <div class="dock-tooltip">设置</div>
      </button>
    </div>
  </div>
</template>

<style scoped>
.dock {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
}

.dock-container {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(40, 40, 40, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  background: transparent;
  border: none;
  color: white;
  position: relative;
}

.dock-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.15);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.dock-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.dock-tooltip {
  position: absolute;
  bottom: 100%;
  margin-bottom: 8px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
  color: white;
}

.dock-item:hover .dock-tooltip {
  opacity: 1;
  visibility: visible;
}

.dock-mobile {
  bottom: 10px;
  left: 10px;
  right: 10px;
  transform: none;
}

.dock-mobile .dock-container {
  width: 100%;
  justify-content: space-around;
  border-radius: 16px;
}

.dock-mobile .dock-item {
  padding: 10px;
}

.dock-mobile .dock-tooltip {
  display: none;
}

.settings-btn {
  cursor: pointer;
}

@media (max-width: 768px) {
  .dock {
    bottom: 10px;
    left: 10px;
    right: 10px;
    transform: none;
  }

  .dock-container {
    width: 100%;
    justify-content: space-around;
    border-radius: 16px;
  }

  .dock-item {
    padding: 10px;
  }

  .dock-tooltip {
    display: none;
  }
}
</style>
