import prisma from '@/lib/prisma'
import SettingsForm from './SettingsForm'
import { Settings as SettingsIcon } from 'lucide-react'

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'] || 'Moy Beach'
  const location = settings['location'] || 'Akyaka · Muğla'
  const logoUrl = settings['logo_url'] || ''
  const googleReviewUrl = settings['google_review_url'] || ''

  return (
    <div className="space-y-8">
      <div className="flex items-center gap-4">
        <div className="w-12 h-12 bg-blue-600 rounded-xl flex items-center justify-center text-white shadow-lg shadow-blue-600/20">
          <SettingsIcon size={24} />
        </div>
        <div>
          <h1 className="text-2xl font-extrabold text-slate-900 tracking-tight">Genel Ayarlar</h1>
          <p className="text-sm text-slate-500 mt-1">Sitenizin temel bilgilerini, logo ve bağlantılarını yapılandırın.</p>
        </div>
      </div>
      
      <div className="bg-white p-6 md:p-8 rounded-2xl shadow-[0_2px_10px_-3px_rgba(6,81,237,0.1)] border border-slate-100 max-w-3xl">
        <SettingsForm 
          defaultRestaurantName={restaurantName}
          defaultLocation={location}
          defaultLogoUrl={logoUrl}
          defaultGoogleReviewUrl={googleReviewUrl}
        />
      </div>
    </div>
  )
}
