'use client'; import * as React from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { type FlagReason, listingsApi } from '@/lib/listings-api'; const FLAG_REASONS: { value: FlagReason; label: string }[] = [ { value: 'SCAM', label: 'Lừa đảo / Scam' }, { value: 'DUPLICATE', label: 'Tin trùng lặp' }, { value: 'WRONG_INFO', label: 'Thông tin sai lệch' }, { value: 'ALREADY_SOLD', label: 'Đã bán / Cho thuê rồi' }, { value: 'INAPPROPRIATE', label: 'Nội dung không phù hợp' }, ]; interface ReportListingModalProps { listingId: string; open: boolean; onOpenChange: (open: boolean) => void; } export function ReportListingModal({ listingId, open, onOpenChange }: ReportListingModalProps) { const [reason, setReason] = React.useState(''); const [description, setDescription] = React.useState(''); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState(null); const [success, setSuccess] = React.useState(false); const handleSubmit = async () => { if (!reason) return; setLoading(true); setError(null); try { await listingsApi.reportListing(listingId, reason, description || undefined); setSuccess(true); setTimeout(() => { onOpenChange(false); setSuccess(false); setReason(''); setDescription(''); }, 2000); } catch (err) { setError(err instanceof Error ? err.message : 'Không thể gửi báo cáo'); } finally { setLoading(false); } }; return ( Báo cáo tin đăng Chọn lý do báo cáo. Chúng tôi sẽ xem xét và xử lý trong thời gian sớm nhất. {success ? (

Báo cáo thành công!

Cảm ơn bạn đã giúp cộng đồng.

) : ( <>
{FLAG_REASONS.map((opt) => ( ))}