<template>
  <div>
    <div class="mb-8">
      <div class="flex items-center justify-between mb-2">
        <div>
          <h1 class="text-3xl font-bold text-white mb-2">Cloud</h1>
          <p class="text-white/70">Cloud services and storage</p>
        </div>
        <button
          @click="openNextcloud"
          class="glass-button px-6 py-3 rounded-lg font-medium flex items-center gap-2"
        >
          <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
          </svg>
          Open Nextcloud
        </button>
      </div>
    </div>

    <!-- Folders Grid -->
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
      <div
        v-for="folder in folders"
        :key="folder.id"
        class="glass-card p-6 cursor-pointer transition-all hover:-translate-y-1 hover:bg-white/10"
        @click="openFolder(folder.id)"
      >
        <div class="flex items-center gap-4 mb-4">
          <div class="flex-shrink-0">
            <svg class="w-12 h-12 text-white/80" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path 
                v-for="(path, index) in getFolderIcon(folder.type)" 
                :key="index"
                stroke-linecap="round" 
                stroke-linejoin="round" 
                stroke-width="2" 
                :d="path" 
              />
            </svg>
          </div>
          <div class="flex-1 min-w-0">
            <h3 class="text-lg font-semibold text-white mb-1 truncate">
              {{ folder.name }}
            </h3>
            <p class="text-sm text-white/60">
              {{ folder.itemCount }} {{ folder.itemCount === 1 ? 'item' : 'items' }}
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

interface Folder {
  id: string
  name: string
  type: 'pictures' | 'videos' | 'music' | 'documents' | 'downloads'
  itemCount: number
}

const folders = ref<Folder[]>([
  {
    id: 'pictures',
    name: 'Pictures',
    type: 'pictures',
    itemCount: 0,
  },
  {
    id: 'videos',
    name: 'Videos',
    type: 'videos',
    itemCount: 0,
  },
  {
    id: 'music',
    name: 'Music',
    type: 'music',
    itemCount: 0,
  },
  {
    id: 'documents',
    name: 'Documents',
    type: 'documents',
    itemCount: 0,
  },
  {
    id: 'downloads',
    name: 'Downloads',
    type: 'downloads',
    itemCount: 0,
  },
])

function getFolderIcon(type: string): string[] {
  const icons: Record<string, string[]> = {
    pictures: ['M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z'],
    videos: ['M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z'],
    music: ['M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3'],
    documents: ['M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z'],
    downloads: ['M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4'],
  }
  return icons[type] || ['M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z']
}

function openFolder(folderId: string) {
  router.push({
    name: 'cloud-folder',
    params: { folderId }
  })
}

function openNextcloud() {
  window.open('http://localhost:8086', '_blank', 'noopener,noreferrer')
}
</script>
