import { useEffect, useState } from "react"; import { ActivityIndicator, Alert, Linking, Modal, Platform, Pressable, ScrollView, Share, Text, View, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import * as Haptics from "expo-haptics"; import * as Clipboard from "expo-clipboard"; import { api } from "@/lib/api"; import { getPublicMenuUrl } from "@/lib/urls"; export interface ThemeOption { key: string; name: string; category: string; color: string; badgeBg: string; badgeText: string; bgPreview: string; desc: string; suitableFor: string; accent: string; } export const THEME_OPTIONS: ThemeOption[] = [ { key: "artisan", name: "Amber Artisan", category: "Gurme & Organik / Koyu", color: "#E5A855", badgeBg: "#282B34", badgeText: "#E5A855", bgPreview: "#121316", accent: "Amber Bal & Mat Oniks", desc: "Koyu antrasit mat zemin, kehribar vurgular, modern bento ızgarası ve yuvarlak ürün kartları.", suitableFor: "Gurme şarküteri, kuruyemiş & organik market, fıçı bira evleri, artisan kahveciler", }, { key: "elegant", name: "Elegant Gold", category: "Fine Dining & Lüks", color: "#C8A96B", badgeBg: "#FDF8F0", badgeText: "#926E27", bgPreview: "#FAF8F5", accent: "Altın & Fildişi", desc: "Zarif altın ve ipeksi krem tonlarında, yüksek prestijli serif tipografi.", suitableFor: "Fine dining, şarap evleri, gurme steakhouse", }, { key: "modern", name: "Modern Sapphire", category: "Kafe & Fast Casual", color: "#2563EB", badgeBg: "#EFF6FF", badgeText: "#1D4ED8", bgPreview: "#F8FAFC", accent: "Kraliyet Safiri & Beyaz", desc: "Canlı mavi safir ve beyaz tonlarında, hızlı gezinti odaklı modern ızgara mizanpajı.", suitableFor: "Kafeler, burgerciler, yeni nesil bistrolar", }, { key: "dark", name: "Luxury Dark", category: "Gece Kulübü & Bar", color: "#F59E0B", badgeBg: "#27272A", badgeText: "#FBBF24", bgPreview: "#0F0F12", accent: "Obsidian & Kehribar", desc: "Koyu obsidian siyahı ve kehribar parıltılı, loş ortamlara özel şık gece modu.", suitableFor: "Kokteyl barlar, lounge, gece kulüpleri", }, { key: "minimal", name: "Nordic Minimal", category: "Butik Fırın & Kahveci", color: "#18181B", badgeBg: "#F4F4F5", badgeText: "#27272A", bgPreview: "#FAFAFA", accent: "Monokrom & Grafit", desc: "Ferah negatif alanlar, sakin monokrom renkler ve sade liste düzeni.", suitableFor: "3. nesil kahveciler, butik fırınlar, tatlıcılar", }, { key: "classic", name: "Classic Bistro", category: "Geleneksel & Rustik", color: "#8B1E1E", badgeBg: "#FEF2F2", badgeText: "#991B1B", bgPreview: "#FFF9F2", accent: "Toskana Bordo & Sıcak Ahşap", desc: "Toskana bordo ve sıcak rustik dokularla geleneksel menü panosu hissi.", suitableFor: "Meyhaneler, geleneksel lokantalar, trattoria'lar", }, ]; interface ThemeSelectorSheetProps { visible: boolean; restaurantId: string; restaurantSlug?: string; onClose: () => void; onThemeChanged?: (themeKey: string) => void; } export function ThemeSelectorSheet({ visible, restaurantId, restaurantSlug, onClose, onThemeChanged, }: ThemeSelectorSheetProps) { const [selectedKey, setSelectedKey] = useState("elegant"); const [loading, setLoading] = useState(true); const [savingKey, setSavingKey] = useState(null); const WEB_BASE_URL = process.env.EXPO_PUBLIC_WEB_URL || "http://localhost:3000"; useEffect(() => { if (!visible || !restaurantId) return; (async () => { setLoading(true); try { const res = await api.get<{ themeKey: string }>(`/restaurants/${restaurantId}/theme`); if (res?.themeKey) { setSelectedKey(res.themeKey); } } catch { setSelectedKey("elegant"); } finally { setLoading(false); } })(); }, [visible, restaurantId]); async function handleApplyTheme(key: string) { setSelectedKey(key); setSavingKey(key); Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium).catch(() => {}); try { await api.put(`/restaurants/${restaurantId}/theme`, { themeKey: key }); onThemeChanged?.(key); Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success).catch(() => {}); Alert.alert("Başarılı 🎉", "Menü şablonunuz güncellendi! Müşterileriniz artık bu temayı görecek."); } catch (err) { Alert.alert("Hata", err instanceof Error ? err.message : "Şablon uygulanamadı."); } finally { setSavingKey(null); } } function handleOpenDemo(key: string) { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {}); const demoUrl = `${WEB_BASE_URL}/demo?theme=${key}`; Linking.openURL(demoUrl).catch(() => { Alert.alert("Demo Linki", demoUrl); }); } async function handleShareDemo(theme: ThemeOption) { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {}); const demoUrl = `${WEB_BASE_URL}/demo?theme=${theme.key}`; try { await Share.share({ title: `${theme.name} — menul.io Canlı Demo`, message: `menul.io "${theme.name}" restoran menü şablonunu canlı olarak inceleyin:\n${demoUrl}`, }); } catch { await Clipboard.setStringAsync(demoUrl); Alert.alert("Kopyalandı", "Demo linki panoya kopyalandı."); } } function handleOpenMyMenuPreview(key: string) { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {}); if (restaurantSlug) { const myMenuUrl = `${getPublicMenuUrl(restaurantSlug)}?theme=${key}`; Linking.openURL(myMenuUrl).catch(() => { Alert.alert("Önizleme Linki", myMenuUrl); }); } else { handleOpenDemo(key); } } return ( {/* Grab Bar */} {/* Header */} Menü Şablonları & Canlı Önizleme 5 lüks şablonu inceleyin, demolarını paylaşın veya menünüze uygulayın {loading ? ( Şablonlar yükleniyor... ) : ( {THEME_OPTIONS.map((theme) => { const isSelected = selectedKey === theme.key; const isApplying = savingKey === theme.key; return ( {/* Top Row: Color Pip, Name, Category Badge & Active Check */} {theme.name} {theme.category} {/* Description */} {theme.desc} {/* Meta details */} Renk: {theme.accent} • {theme.suitableFor} {/* Action Bar: Canlı Demo, Paylaş, Uygula */} {/* Canlı Demo Aç */} handleOpenDemo(theme.key)} style={({ pressed }) => ({ flex: 1, flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 4, backgroundColor: "#F5F5F4", paddingVertical: 10, borderRadius: 10, opacity: pressed ? 0.8 : 1, })} > Demo Menü {/* Demo Linkini Gönder / Paylaş */} handleShareDemo(theme)} style={({ pressed }) => ({ width: 40, alignItems: "center", justifyContent: "center", backgroundColor: "#FAF8F5", borderWidth: 1, borderColor: "#E7E5E4", paddingVertical: 10, borderRadius: 10, opacity: pressed ? 0.8 : 1, })} > {/* Bu Şablonu Uygula / Aktif Rozeti */} handleApplyTheme(theme.key)} disabled={isSelected || isApplying} style={({ pressed }) => ({ flex: 1.3, flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 6, backgroundColor: isSelected ? "#ECFDF5" : theme.color, borderWidth: isSelected ? 1 : 0, borderColor: "#A7F3D0", paddingVertical: 10, borderRadius: 10, opacity: pressed ? 0.85 : 1, })} > {isApplying ? ( ) : isSelected ? ( <> Aktif Şablon ) : ( <> Şablonu Seç )} ); })} )} {/* Footer Close */} Kapat ); }