'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { createOrUpdateCollectionAction } from '@/app/actions' import { ArrowLeft, Save } from 'lucide-react' import { Link } from '@/i18n/routing' interface Option { value: string label: string } interface FormProps { collection: any | null listingOptions: Option[] } export default function CollectionForm({ collection, listingOptions }: FormProps) { const router = useRouter() const [activeTab, setActiveTab] = useState<'tr' | 'en' | 'ru'>('tr') const [loading, setLoading] = useState(false) const [error, setError] = useState('') const [success, setSuccess] = useState(false) // Selected Listings const [selectedListings, setSelectedListings] = useState(collection?.listingIds || []) const [listingSearch, setListingSearch] = useState('') const handleListingToggle = (id: string) => { setSelectedListings(prev => prev.includes(id) ? prev.filter(i => i !== id) : [...prev, id] ) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError('') setSuccess(false) const formData = new FormData(e.currentTarget) if (collection) { formData.append('id', collection.id) } formData.append('listingIds', selectedListings.join(',')) try { const res = await createOrUpdateCollectionAction(formData) if (res.error) { setError(res.error) } else { setSuccess(true) setTimeout(() => { router.push('/admin/collections') router.refresh() }, 1500) } } catch (err) { setError('İşlem sırasında bir hata oluştu.') } finally { setLoading(false) } } const filteredListings = listingOptions.filter(opt => opt.label.toLowerCase().includes(listingSearch.toLowerCase()) ) return (
{error && (
{error}
)} {success && (
Seçki başarıyla kaydedildi! Yönlendiriliyorsunuz...
)} {/* Language tabs */}
{(['tr', 'en', 'ru'] as const).map((lang) => { const label = lang === 'tr' ? '🇹🇷 Türkçe' : lang === 'en' ? '🇬🇧 English' : '🇷🇺 Русский' const isTabActive = activeTab === lang return ( ) })}
{/* Localized inputs */}
{activeTab === 'tr' && (