import prisma from '@/lib/prisma'
import SettingsForm from './SettingsForm'

export const metadata = {
  title: 'Genel Ayarlar - Admin',
}

export default async function SettingsPage() {
  const settingsData = await prisma.settings.findMany()
  const settings = settingsData.reduce((acc, curr) => {
    acc[curr.key] = curr.value
    return acc
  }, {} as Record<string, string>)

  const restaurantName = settings['restaurant_name'] || 'Kite Beach'
  const location = settings['location'] || 'Akyaka · Muğla'
  const logoUrl = settings['logo_url'] || ''

  return (
    <div className="space-y-6">
      <h1 className="text-2xl font-bold text-gray-900">Genel Ayarlar</h1>

      <div className="bg-white p-6 rounded-xl shadow-sm border border-gray-100 max-w-2xl">
        <SettingsForm
          defaultRestaurantName={restaurantName}
          defaultLocation={location}
          defaultLogoUrl={logoUrl}
        />
      </div>
    </div>
  )
}
