275 lines
12 KiB
TypeScript
275 lines
12 KiB
TypeScript
'use client';
|
||
|
||
import React, { useState } from 'react';
|
||
import {
|
||
Check, Edit3, Trash2, Send, ExternalLink,
|
||
Eye, Calendar, Sparkles, MessageSquare, AlertCircle
|
||
} from 'lucide-react';
|
||
import { InfoTooltip } from './InfoTooltip';
|
||
|
||
export interface RawPostData {
|
||
id: string;
|
||
message_id: number;
|
||
original_text: string | null;
|
||
post_url: string;
|
||
media_type: string;
|
||
media_url: string | null;
|
||
views: number;
|
||
reactions: number;
|
||
posted_at: string;
|
||
}
|
||
|
||
export interface DraftItem {
|
||
id: string;
|
||
raw_post_id: string;
|
||
ai_generated_text: string;
|
||
current_text: string;
|
||
status: string;
|
||
brand_target: string;
|
||
created_at: string;
|
||
raw_post?: RawPostData;
|
||
}
|
||
|
||
interface DraftCardProps {
|
||
draft: DraftItem;
|
||
onApprove: (id: string) => void;
|
||
onEditApprove: (id: string, text: string) => void;
|
||
onReject: (id: string, reason?: string) => void;
|
||
}
|
||
|
||
export const DraftCard: React.FC<DraftCardProps> = ({
|
||
draft,
|
||
onApprove,
|
||
onEditApprove,
|
||
onReject,
|
||
}) => {
|
||
const [isEditing, setIsEditing] = useState(false);
|
||
const [editedText, setEditedText] = useState(draft.current_text);
|
||
const [rejectReason, setRejectReason] = useState('');
|
||
const [showRejectModal, setShowRejectModal] = useState(false);
|
||
|
||
const rawPost = draft.raw_post;
|
||
|
||
const handleSaveEdit = () => {
|
||
onEditApprove(draft.id, editedText);
|
||
setIsEditing(false);
|
||
};
|
||
|
||
const handleConfirmReject = () => {
|
||
onReject(draft.id, rejectReason || 'نامناسب برای کانال برند');
|
||
setShowRejectModal(false);
|
||
};
|
||
|
||
return (
|
||
<div className="bg-slate-900/90 border border-slate-800 rounded-2xl p-6 shadow-xl transition-all hover:border-slate-700/80">
|
||
{/* Top Bar */}
|
||
<div className="flex flex-wrap items-center justify-between gap-4 pb-4 border-b border-slate-800/80">
|
||
<div className="flex items-center gap-3">
|
||
<span className="flex items-center gap-1.5 px-3 py-1 bg-indigo-500/10 text-indigo-400 border border-indigo-500/20 rounded-lg text-xs font-mono font-medium">
|
||
<Sparkles className="w-3.5 h-3.5" />
|
||
Agent B Draft
|
||
</span>
|
||
<InfoTooltip
|
||
title="تولید هوشمند Agent B"
|
||
text="این پیشنویس بر اساس متون کانالهای ترند و با تزریق آخرین بازخوردهای سردبیر انسانی تولید شده است."
|
||
/>
|
||
<span className="text-xs text-slate-400">
|
||
برند مقصد: <strong className="text-slate-200">{draft.brand_target}</strong>
|
||
</span>
|
||
</div>
|
||
|
||
<div className="flex items-center gap-4 text-xs text-slate-400">
|
||
{rawPost && (
|
||
<>
|
||
<div className="flex items-center gap-1 bg-slate-800/80 px-2.5 py-1 rounded-md">
|
||
<Eye className="w-3.5 h-3.5 text-slate-300" />
|
||
<span>{rawPost.views.toLocaleString()}</span>
|
||
<InfoTooltip text="تعداد بازدید ثبتشده در پست تلگرامی مبدا." />
|
||
</div>
|
||
|
||
<div className="flex items-center gap-1 bg-slate-800/80 px-2.5 py-1 rounded-md">
|
||
<Calendar className="w-3.5 h-3.5 text-slate-300" />
|
||
<span>{new Date(rawPost.posted_at).toLocaleDateString('fa-IR')}</span>
|
||
<InfoTooltip text="تاریخ انتشار اولیه در کانال منبع." />
|
||
</div>
|
||
|
||
<a
|
||
href={rawPost.post_url}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className="flex items-center gap-1 text-indigo-400 hover:text-indigo-300 transition"
|
||
>
|
||
<span>مشاهده پست منبع</span>
|
||
<ExternalLink className="w-3 h-3" />
|
||
</a>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{/* Main Grid: Source Post vs Rewritten Copy */}
|
||
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6 mt-5">
|
||
{/* Source Content Preview (4 cols) */}
|
||
<div className="lg:col-span-5 bg-slate-950/60 border border-slate-800/60 rounded-xl p-4 flex flex-col justify-between">
|
||
<div>
|
||
<div className="flex items-center justify-between mb-2">
|
||
<span className="text-xs font-semibold text-slate-400 flex items-center gap-1">
|
||
<MessageSquare className="w-3.5 h-3.5" />
|
||
محتوای منبع (کانال اصلی)
|
||
</span>
|
||
<InfoTooltip text="متن و رسانه خام استخراجشده بدون دخالت و ادیت هوش مصنوعی." />
|
||
</div>
|
||
|
||
{/* Media Preview */}
|
||
{rawPost?.media_url && (
|
||
<div className="mb-3 rounded-lg overflow-hidden border border-slate-800 bg-slate-900 max-h-48 flex items-center justify-center">
|
||
{rawPost.media_type === 'photo' ? (
|
||
<img src={rawPost.media_url} alt="Media preview" className="w-full object-cover max-h-48" />
|
||
) : (
|
||
<video src={rawPost.media_url} controls className="w-full max-h-48" />
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
<div className="text-xs leading-relaxed text-slate-300 whitespace-pre-wrap max-h-44 overflow-y-auto pr-1">
|
||
{rawPost?.original_text || '(بدون متن - فقط مدیا)'}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="mt-3 pt-2 border-t border-slate-800/60 flex items-center justify-between text-[11px] text-slate-500">
|
||
<span>شناسه پیام: {rawPost?.message_id}</span>
|
||
<span>مدیا: {rawPost?.media_type}</span>
|
||
</div>
|
||
</div>
|
||
|
||
{/* AI Persian Copy / Inline Editor (7 cols) */}
|
||
<div className="lg:col-span-7 flex flex-col justify-between">
|
||
<div>
|
||
<div className="flex items-center justify-between mb-2">
|
||
<span className="text-xs font-semibold text-indigo-300 flex items-center gap-1">
|
||
<Sparkles className="w-3.5 h-3.5 text-indigo-400" />
|
||
کپی فارسی اختصاصی تلگرام (عامیانه و جذاب)
|
||
</span>
|
||
<InfoTooltip text="متن تولیدشده توسط هوش مصنوعی با لحن خودمانی، تفکیک نکات، ایموجیها و منشن @NetVibe_VPN." />
|
||
</div>
|
||
|
||
{isEditing ? (
|
||
<div className="space-y-2">
|
||
<textarea
|
||
value={editedText}
|
||
onChange={(e) => setEditedText(e.target.value)}
|
||
className="w-full h-64 bg-slate-950 border border-indigo-500/80 rounded-xl p-4 text-sm text-slate-100 focus:outline-none focus:ring-2 focus:ring-indigo-500/30 leading-relaxed font-sans"
|
||
placeholder="متن پست را ویرایش کنید..."
|
||
dir="rtl"
|
||
/>
|
||
<div className="flex items-center justify-between text-xs text-slate-400 px-1">
|
||
<span>تعداد کاراکتر: {editedText.length}</span>
|
||
<span className="text-indigo-400">تغییرات شما به عنوان دیتای یادگیری ذخیره خواهد شد.</span>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="bg-slate-950/40 border border-slate-800/80 rounded-xl p-5 text-sm leading-relaxed whitespace-pre-wrap text-slate-100 min-h-[220px]">
|
||
{draft.current_text}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{/* Action Bar */}
|
||
<div className="flex flex-wrap items-center justify-between gap-3 mt-5 pt-4 border-t border-slate-800">
|
||
<div className="flex items-center gap-2">
|
||
{isEditing ? (
|
||
<>
|
||
<button
|
||
onClick={handleSaveEdit}
|
||
className="flex items-center gap-1.5 px-4 py-2 bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl text-xs font-semibold shadow-md shadow-emerald-600/20 transition"
|
||
>
|
||
<Check className="w-4 h-4" />
|
||
ثبت ویرایش و تایید
|
||
</button>
|
||
<InfoTooltip text="متن جدید ذخیره شده، دیف متنی ثبت و پست به صف انتشار اضافه میشود." />
|
||
|
||
<button
|
||
onClick={() => {
|
||
setIsEditing(false);
|
||
setEditedText(draft.current_text);
|
||
}}
|
||
className="px-3.5 py-2 bg-slate-800 hover:bg-slate-700 text-slate-300 rounded-xl text-xs transition"
|
||
>
|
||
انصراف
|
||
</button>
|
||
</>
|
||
) : (
|
||
<>
|
||
<button
|
||
onClick={() => onApprove(draft.id)}
|
||
className="flex items-center gap-1.5 px-4 py-2 bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl text-xs font-semibold shadow-md shadow-emerald-600/20 transition"
|
||
>
|
||
<Send className="w-4 h-4" />
|
||
تایید و انتقال به صف انتشار
|
||
</button>
|
||
<InfoTooltip text="پست بدون تغییر به صف زمانبندی انتشار اضافه میشود." />
|
||
|
||
<button
|
||
onClick={() => setIsEditing(true)}
|
||
className="flex items-center gap-1.5 px-3.5 py-2 bg-indigo-600 hover:bg-indigo-500 text-white rounded-xl text-xs font-medium shadow-md shadow-indigo-600/20 transition"
|
||
>
|
||
<Edit3 className="w-4 h-4" />
|
||
ویرایش لحن یا متن
|
||
</button>
|
||
<InfoTooltip text="فعالسازی ادیتور برای اصلاح کلمات، رفع باگ فنی یا تنظیم تگها." />
|
||
</>
|
||
)}
|
||
</div>
|
||
|
||
<div>
|
||
<button
|
||
onClick={() => setShowRejectModal(true)}
|
||
className="flex items-center gap-1.5 px-3 py-2 text-rose-400 hover:text-rose-300 hover:bg-rose-500/10 rounded-xl text-xs transition"
|
||
>
|
||
<Trash2 className="w-4 h-4" />
|
||
رد پیشنویس
|
||
</button>
|
||
<InfoTooltip text="رد کردن پست و ثبت بازخورد منفی جهت جلوگیری از تولید محتواهای مشابه." />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{/* Reject Modal */}
|
||
{showRejectModal && (
|
||
<div className="fixed inset-0 z-50 bg-black/70 backdrop-blur-sm flex items-center justify-center p-4">
|
||
<div className="bg-slate-900 border border-slate-800 rounded-2xl p-6 max-w-md w-full shadow-2xl text-right">
|
||
<div className="flex items-center gap-2 text-rose-400 mb-2 font-bold text-sm">
|
||
<AlertCircle className="w-5 h-5" />
|
||
<span>رد پیشنویس و ثبت دلیل</span>
|
||
</div>
|
||
<p className="text-xs text-slate-400 mb-4 leading-relaxed">
|
||
لطفاً علت رد این پست را مشخص کنید تا در پرامپتهای بعدی به عنوان خط قرمز اعمال شود:
|
||
</p>
|
||
<input
|
||
type="text"
|
||
value={rejectReason}
|
||
onChange={(e) => setRejectReason(e.target.value)}
|
||
placeholder="مثال: منبع نامعتبر، کانفیگ منسوخشده، لحن نامناسب..."
|
||
className="w-full bg-slate-950 border border-slate-700 rounded-xl px-4 py-2.5 text-xs text-slate-100 focus:outline-none focus:border-rose-500 mb-5"
|
||
/>
|
||
<div className="flex items-center justify-end gap-2">
|
||
<button
|
||
onClick={() => setShowRejectModal(false)}
|
||
className="px-4 py-2 bg-slate-800 hover:bg-slate-700 text-slate-300 rounded-xl text-xs"
|
||
>
|
||
انصراف
|
||
</button>
|
||
<button
|
||
onClick={handleConfirmReject}
|
||
className="px-4 py-2 bg-rose-600 hover:bg-rose-500 text-white rounded-xl text-xs font-semibold"
|
||
>
|
||
تایید رد پست
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
};
|