"use client"; import { useState, useEffect, useTransition } from "react"; import { Globe, ChevronDown, Save, Loader2, CheckCircle2, Plus, X } from "lucide-react"; interface Localization { id: string; attributes: { locale: string; description: string; keywords: string; whatsNew: string; promotionalText: string; marketingUrl: string; supportUrl: string; }; } const LOCALE_LABELS: Record = { "en-US": "English (US)", "tr-TR": "Türkçe", "de-DE": "Deutsch", "fr-FR": "Français", "es-ES": "Español", "it-IT": "Italiano", "pt-PT": "Português (PT)", "pt-BR": "Português (BR)", "ja": "日本語", "ko": "한국어", "zh-Hans": "简体中文", "zh-Hant": "繁體中文", "ar-SA": "العربية", "ru": "Русский", "nl-NL": "Nederlands", "sv-SE": "Svenska", "pl-PL": "Polski", "da": "Dansk", "fi": "Suomi", "nb": "Norsk", "el": "Ελληνικά", "cs": "Čeština", "hu": "Magyar", "ro": "Română", "sk": "Slovenčina", "uk": "Українська", "hr": "Hrvatski", "id": "Bahasa Indonesia", "ms": "Bahasa Malaysia", "th": "ภาษาไทย", "vi": "Tiếng Việt", "hi": "हिन्दी", }; const FIELDS: { key: keyof Localization["attributes"]; label: string; multiline?: boolean; maxLen?: number; }[] = [ { key: "description", label: "Açıklama", multiline: true, maxLen: 4000 }, { key: "keywords", label: "Anahtar Kelimeler", maxLen: 100 }, { key: "whatsNew", label: "Bu Sürümdeki Yenilikler", multiline: true, maxLen: 4000 }, { key: "promotionalText", label: "Tanıtım Metni", multiline: true, maxLen: 170 }, { key: "marketingUrl", label: "Pazarlama URL" }, { key: "supportUrl", label: "Destek URL" }, ]; export default function LocalizationEditor({ versionId, versionString, }: { versionId: string; versionString: string; }) { const [localizations, setLocalizations] = useState([]); const [selectedLocale, setSelectedLocale] = useState(""); const [form, setForm] = useState>({}); const [loading, setLoading] = useState(true); const [saving, startSaveTransition] = useTransition(); const [adding, startAddTransition] = useTransition(); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); const [showAddLocale, setShowAddLocale] = useState(false); function fetchLocalizations(selectId?: string) { setLoading(true); fetch(`/api/asc/localizations?versionId=${versionId}`) .then((r) => r.json()) .then((d) => { const locs: Localization[] = d.data ?? []; setLocalizations(locs); if (locs.length > 0) { const target = selectId ? locs.find((l) => l.id === selectId) ?? locs[0] : locs[0]; setSelectedLocale(target.id); setForm(target.attributes); } }) .finally(() => setLoading(false)); } // eslint-disable-next-line react-hooks/exhaustive-deps useEffect(() => { fetchLocalizations(); }, [versionId]); function selectLocale(id: string) { const loc = localizations.find((l) => l.id === id); if (!loc) return; setSelectedLocale(id); setForm(loc.attributes); setSaved(false); setError(null); } function handleChange(key: keyof Localization["attributes"], value: string) { setForm((prev) => ({ ...prev, [key]: value })); setSaved(false); } function handleSave() { setError(null); startSaveTransition(async () => { const res = await fetch(`/api/asc/localizations`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ localizationId: selectedLocale, payload: form }), }); if (res.ok) { setSaved(true); setTimeout(() => setSaved(false), 3000); } else { const d = await res.json(); setError(d.error ?? "Kaydedilemedi"); } }); } function handleAddLocale(localeCode: string) { setShowAddLocale(false); setError(null); startAddTransition(async () => { const res = await fetch(`/api/asc/localizations`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ versionId, locale: localeCode }), }); const d = await res.json(); if (res.ok) { fetchLocalizations(d.data?.id); } else { setError(d.error ?? "Dil eklenemedi"); } }); } const existingCodes = new Set(localizations.map((l) => l.attributes.locale)); const availableToAdd = Object.entries(LOCALE_LABELS).filter(([code]) => !existingCodes.has(code)); return (
{/* Header */}

Metadata Düzenle v{versionString}

{/* Locale selector */} {localizations.length > 0 && (
)} {/* Add locale */}
{showAddLocale && (
Dil Seç
{availableToAdd.length === 0 ? (

Tüm diller eklenmiş.

) : ( availableToAdd.map(([code, label]) => ( )) )}
)}
{/* Body */} {loading ? (
) : localizations.length === 0 ? (
Bu sürüm için lokalizasyon verisi bulunamadı.
) : (
{FIELDS.map((f) => (
{f.maxLen && ( f.maxLen ? "text-red-400" : "text-slate-600" }`} > {(form[f.key] as string)?.length ?? 0}/{f.maxLen} )}
{f.multiline ? (