---
import Layout from '../../layouts/Layout.astro';
import Header from '../../components/layout/Header';
import AdminSidebar from '../../components/admin/AdminSidebar';
import StoreSettingsForm from '../../components/vendor/StoreSettingsForm';

const token = Astro.cookies.get('session')?.value;
if (!token) return Astro.redirect('/login');

// Fetch vendor data
const vendorRes = await fetch(new URL('/api/vendors/dashboard', Astro.url).toString(), {
  headers: { 'Authorization': `Bearer ${token}` }
});
const { vendor } = await vendorRes.json();
---

<Layout title="ตั้งค่าร้านค้า">
  <div class="min-h-screen bg-gray-100">
    <Header />
    <div class="flex">
      <AdminSidebar client:load role="vendor" />
      <main class="flex-1 p-8">
        <div class="flex items-center gap-4 mb-8">
          <a href="/vendor/dashboard" class="text-gray-500 hover:text-gray-700">
            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
            </svg>
          </a>
          <h1 class="text-2xl font-bold">ตั้งค่าร้านค้า</h1>
        </div>
        
        <div class="max-w-2xl">
          <StoreSettingsForm client:load vendor={vendor} />
        </div>
      </main>
    </div>
  </div>
</Layout>
