import { useState } from 'react'; import { Bug, MessageCircle, Send } from 'lucide-react'; import { api, type TicketSummary } from '@/api'; import { useAsync } from '@/lib/useAsync'; import { useToast } from '@/components/Toast'; import { InlineError, PrimaryButton, Screen, ScreenBody, ScreenHeader, Sep } from '@/components/ui'; import { friendlyError } from '@/lib/errors'; import { toFa } from '@/lib/format'; import { MathText } from '@/lib/MathText'; const CATEGORIES = [ { id: 'learning', label: 'درس و سوال‌ها' }, { id: 'payment', label: 'پرداخت و اشتراک' }, { id: 'account', label: 'حساب و ورود' }, { id: 'other', label: 'چیزِ دیگه' }, ]; const STATUS_LABEL: Record = { open: 'باز', in_progress: 'در حالِ بررسی', answered: 'پاسخ داده شد', closed: 'بسته', }; export function SupportScreen() { const toast = useToast(); const [mode, setMode] = useState<'ticket' | 'bug'>('ticket'); const [category, setCategory] = useState('learning'); const [subject, setSubject] = useState(''); const [text, setText] = useState(''); const [sending, setSending] = useState(false); const [error, setError] = useState(''); // فهرست از سرور می‌آید، پس تیکت و پاسخش با عوض شدنِ گوشی هم دیده می‌شود. const tickets = useAsync(() => api.support.tickets(), []); async function submit() { if (!subject.trim() || !text.trim()) return; setSending(true); setError(''); try { if (mode === 'bug') { await api.support.bugReport(subject.trim(), text.trim()); toast('گزارشت رسید؛ ممنون!', 'success'); } else { const t = await api.support.createTicket(subject.trim(), category); await api.support.reply(t.ticketId, text.trim()); tickets.reload(); toast('پیامت رسید؛ جواب همین‌جا و در اعلان‌ها میاد.', 'success'); } setSubject(''); setText(''); } catch (err) { setError(friendlyError(err, 'ارسال نشد، دوباره امتحان کن')); } finally { setSending(false); } } return (
{([['ticket', 'پیام به پشتیبانی', MessageCircle], ['bug', 'گزارشِ خطای اپ', Bug]] as const).map(([id, label, Icon]) => ( ))}
{mode === 'ticket' && (
{CATEGORIES.map((c) => ( ))}
)} setSubject(e.target.value.slice(0, 120))} placeholder={mode === 'bug' ? 'چی خراب شد؟ (خلاصه)' : 'موضوع'} className="w-full rounded-2xl border-2 border-line bg-white px-4 py-3.5 text-sm outline-none focus:border-indigo" />