Files
project-social-media-manage/src/components/PublishStudio.tsx
2026-11-02 14:37:14 +06:00

1457 lines
73 KiB
TypeScript

import React, { useState, useEffect, useRef } from 'react';
import {
Send, Film, Upload, CheckCircle2, AlertCircle, RefreshCw,
ExternalLink, Check, Heart, MessageCircle, Share2,
Eye, X, Image as ImageIcon, MessageSquare, Palette, FileVideo,
Plus, Hash, Layers, Video
} from 'lucide-react';
import { SupportedLang, TRANSLATIONS } from '../data/translations';
import { OmniSDKConfig, PlatformType, PublishResult } from '../sdk/types';
import { PLATFORM_SPECS } from '../sdk/mediaValidator';
import { SocialAccountState } from './ConnectAccounts';
import { FacebookPageItem, INITIAL_FACEBOOK_PAGES } from '../types/facebookPages';
import { SocialAccountsBannerList } from './SocialAccountsBannerList';
import { AuthUser } from '../types/auth';
export type PublishFormatType = 'reel' | 'post' | 'status';
export type StatusBgTheme = 'emerald' | 'sunset' | 'cosmic' | 'ocean' | 'crimson' | 'clean';
const STATUS_THEMES: { id: StatusBgTheme; name: string; bgClass: string; textClass: string }[] = [
{ id: 'emerald', name: 'Emerald', bgClass: 'bg-gradient-to-br from-emerald-600 via-teal-700 to-slate-900', textClass: 'text-white' },
{ id: 'sunset', name: 'Sunset', bgClass: 'bg-gradient-to-br from-amber-500 via-rose-600 to-purple-800', textClass: 'text-white' },
{ id: 'cosmic', name: 'Cosmic', bgClass: 'bg-gradient-to-br from-indigo-600 via-purple-700 to-pink-800', textClass: 'text-white' },
{ id: 'ocean', name: 'Ocean', bgClass: 'bg-gradient-to-br from-cyan-600 via-blue-700 to-indigo-950', textClass: 'text-white' },
{ id: 'crimson', name: 'Crimson', bgClass: 'bg-gradient-to-br from-rose-700 via-red-800 to-slate-950', textClass: 'text-white' },
{ id: 'clean', name: 'Slate Post', bgClass: 'bg-slate-900 border border-slate-800', textClass: 'text-slate-100' }
];
interface PublishRecord {
id: string;
platform: PlatformType;
postId: string;
postUrl: string;
title: string;
timestamp: string;
thumbnail: string;
}
interface PublishStudioProps {
lang: SupportedLang;
config: OmniSDKConfig;
accounts: Record<PlatformType, SocialAccountState>;
onPublishSuccess: (records: PublishRecord[]) => void;
onSyncRealData?: () => void;
isSyncingRealData?: boolean;
facebookPages?: FacebookPageItem[];
onUpdateFacebookPages?: (pages: FacebookPageItem[]) => void;
onNavigateToConnect?: () => void;
currentUser?: AuthUser | null;
}
export const PublishStudio: React.FC<PublishStudioProps> = ({
lang,
config,
accounts,
onPublishSuccess,
onSyncRealData,
isSyncingRealData = false,
facebookPages = INITIAL_FACEBOOK_PAGES,
onUpdateFacebookPages,
onNavigateToConnect,
currentUser
}) => {
const t = TRANSLATIONS[lang];
// Publish Format: 'reel' | 'post' | 'status'
const [publishFormat, setPublishFormat] = useState<PublishFormatType>('reel');
const [statusTheme, setStatusTheme] = useState<StatusBgTheme>('emerald');
// Selected platforms - default to connected accounts
const [selectedPlatforms, setSelectedPlatforms] = useState<PlatformType[]>(() => {
return accounts.facebook?.connected ? ['facebook'] : [];
});
// Multi-page Facebook selection
const [selectedPageIds, setSelectedPageIds] = useState<string[]>(() => {
if (accounts.facebook?.connected && facebookPages && facebookPages.length > 0) {
return [facebookPages[0].id];
}
return [];
});
const [multiPagePublishResults, setMultiPagePublishResults] = useState<any[]>([]);
// Update selected pages if list changes
useEffect(() => {
if (facebookPages && facebookPages.length > 0) {
setSelectedPageIds(prev => {
const valid = prev.filter(id => facebookPages.some(p => p.id === id));
return valid.length > 0 ? valid : [facebookPages[0].id];
});
}
}, [facebookPages]);
// Uploaded real media state (supports BOTH photo and video)
const [customFile, setCustomFile] = useState<{ name: string; size: number; url: string; file: File } | null>(null);
const [customPhotoFile, setCustomPhotoFile] = useState<{ name: string; url: string; file: File } | null>(null);
// Hidden input refs for dual media upload in feed posts
const postPhotoInputRef = useRef<HTMLInputElement>(null);
const postVideoInputRef = useRef<HTMLInputElement>(null);
// Caption / Status Text
const [caption, setCaption] = useState<string>('');
const [inputError, setInputError] = useState<string | null>(null);
// Preview tab on the smartphone mockup
const [previewPlatform, setPreviewPlatform] = useState<PlatformType>('facebook');
// Publishing progress
const [isPublishing, setIsPublishing] = useState<boolean>(false);
const [currentPublishPhase, setCurrentPublishPhase] = useState<string>('');
const [publishProgress, setPublishProgress] = useState<number>(0);
const [latestResults, setLatestResults] = useState<Record<PlatformType, PublishResult> | null>(null);
// User's custom hashtags (no default presets, user creates & sets them)
const [userHashtags, setUserHashtags] = useState<string[]>(() => {
try {
const saved = localStorage.getItem('ecohub_custom_hashtags');
return saved ? JSON.parse(saved) : [];
} catch {
return [];
}
});
const [newTagInput, setNewTagInput] = useState<string>('');
const handleCreateTag = (e?: React.FormEvent) => {
if (e) e.preventDefault();
let cleaned = newTagInput.trim().replace(/\s+/g, '');
if (!cleaned) return;
if (!cleaned.startsWith('#')) {
cleaned = `#${cleaned}`;
}
if (!userHashtags.includes(cleaned)) {
const updated = [...userHashtags, cleaned];
setUserHashtags(updated);
try {
localStorage.setItem('ecohub_custom_hashtags', JSON.stringify(updated));
} catch (err) {
console.warn(err);
}
}
// Also append immediately to caption if not already present
if (!caption.includes(cleaned)) {
setCaption(prev => (prev.trim() ? `${prev.trim()} ${cleaned}` : cleaned));
}
setNewTagInput('');
};
const handleRemoveTag = (tagToRemove: string, e: React.MouseEvent) => {
e.stopPropagation();
const updated = userHashtags.filter(t => t !== tagToRemove);
setUserHashtags(updated);
try {
localStorage.setItem('ecohub_custom_hashtags', JSON.stringify(updated));
} catch (err) {
console.warn(err);
}
};
const handleToggleTagInCaption = (tag: string) => {
if (caption.includes(tag)) {
const regex = new RegExp(`\\s*${tag}`, 'g');
setCaption(prev => prev.replace(regex, '').trim());
} else {
setCaption(prev => (prev.trim() ? `${prev.trim()} ${tag}` : tag));
}
};
const togglePlatform = (p: PlatformType) => {
setSelectedPlatforms(prev =>
prev.includes(p) ? prev.filter(item => item !== p) : [...prev, p]
);
};
const handleCustomUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputError(null);
const file = e.target.files?.[0];
if (file) {
const url = URL.createObjectURL(file);
setCustomFile({ name: file.name, size: file.size, url, file });
}
};
const handlePhotoUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputError(null);
const file = e.target.files?.[0];
if (file) {
const url = URL.createObjectURL(file);
setCustomPhotoFile({ name: file.name, url, file });
setCustomFile(null);
}
};
// Feed Post Dual Media Upload: Supports both photos and videos
const handlePostMediaUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputError(null);
const file = e.target.files?.[0];
if (file) {
const url = URL.createObjectURL(file);
if (file.type.startsWith('video/')) {
setCustomFile({ name: file.name, size: file.size, url, file });
setCustomPhotoFile(null);
} else {
setCustomPhotoFile({ name: file.name, url, file });
setCustomFile(null);
}
}
};
const removeVideo = () => {
if (customFile?.url) {
URL.revokeObjectURL(customFile.url);
}
setCustomFile(null);
};
const removePhoto = () => {
if (customPhotoFile?.url) {
URL.revokeObjectURL(customPhotoFile.url);
}
setCustomPhotoFile(null);
};
// Execute Real Meta Publishing
const handlePublish = async () => {
setInputError(null);
if (selectedPlatforms.length === 0) {
setInputError(lang === 'bn' ? 'কমপক্ষে একটি সোশ্যাল প্ল্যাটফর্ম নির্বাচন করুন।' : 'Please select at least one platform.');
return;
}
if (publishFormat === 'reel' && !customFile) {
setInputError(lang === 'bn' ? 'অনুগ্রহ করে প্রকাশের জন্য একটি MP4 ভিডিও ফাইল আপলোড করুন।' : 'Please upload an MP4 video file before publishing your Reel.');
return;
}
if (publishFormat === 'status' && !caption.trim()) {
setInputError(lang === 'bn' ? 'অনুগ্রহ করে আপনার স্ট্যাটাস বার্তাটি লিখুন।' : 'Please write your status text before publishing.');
return;
}
if (selectedPlatforms.includes('youtube') && publishFormat === 'status') {
setInputError(
lang === 'bn'
? 'ইউটিউব শুধুমাত্র ভিডিও বা শর্টস (Shorts) সাপোর্ট করে। টেক্সট স্ট্যাটাস পোস্ট ইউটিউবে প্রকাশ করা সম্ভব নয়।'
: 'YouTube only supports Video or Shorts. Text status updates cannot be published to YouTube.'
);
return;
}
setIsPublishing(true);
setLatestResults(null);
setMultiPagePublishResults([]);
setPublishProgress(25);
setCurrentPublishPhase(
lang === 'bn'
? `মেটা ও সোশ্যাল মিডিয়া সার্ভারে [${publishFormat.toUpperCase()}] প্রেরণের প্রস্তুতি চলছে...`
: `Preparing [${publishFormat.toUpperCase()}] for remote dispatch...`
);
try {
setPublishProgress(55);
setCurrentPublishPhase(
lang === 'bn'
? 'সার্ভারে আসল এপিআই (Meta & YouTube API) এর মাধ্যমে ডেটা আপলোড হচ্ছে...'
: 'Transmitting payload directly to live APIs...'
);
const formData = new FormData();
formData.append('publishType', publishFormat);
formData.append('platforms', JSON.stringify(selectedPlatforms));
formData.append('caption', caption);
if (config.facebook?.pageId) formData.append('pageId', config.facebook.pageId);
if (config.facebook?.accessToken) formData.append('fbAccessToken', config.facebook.accessToken);
// YouTube support
if (selectedPlatforms.includes('youtube')) {
if (config.youtube?.accessToken) {
formData.append('youtubeAccessToken', config.youtube.accessToken);
}
formData.append('youtubeTitle', caption.slice(0, 70) || 'Ecohub BD Video');
formData.append('youtubePrivacy', 'public');
}
// Multiple Facebook Pages support
const targetFbPages = (facebookPages || []).filter(p => selectedPageIds.includes(p.id));
if (targetFbPages.length > 0) {
formData.append('targetPages', JSON.stringify(targetFbPages.map(p => ({
id: p.id,
name: p.name,
accessToken: p.accessToken
}))));
}
if (publishFormat === 'reel' && customFile?.file) {
formData.append('videoFile', customFile.file);
} else if (publishFormat === 'post') {
if (customPhotoFile?.file) {
formData.append('mediaFile', customPhotoFile.file);
} else if (customFile?.file) {
formData.append('mediaFile', customFile.file);
}
}
const resp = await fetch('/api/social/publish-real', {
method: 'POST',
body: formData
});
setPublishProgress(85);
setCurrentPublishPhase(
lang === 'bn'
? 'পোস্ট কনফার্মেশন ও পারমালিঙ্ক সংগ্রহ করা হচ্ছে...'
: 'Retrieving live confirmation permalinks...'
);
const data = await resp.json();
const serverResults = data.results || {};
const mappedResults: Record<PlatformType, PublishResult> = {} as any;
const newRecords: PublishRecord[] = [];
// Handle multi-page Facebook responses
if (serverResults.facebookPages && Array.isArray(serverResults.facebookPages)) {
setMultiPagePublishResults(serverResults.facebookPages);
for (const pageRes of serverResults.facebookPages) {
if (pageRes.success) {
newRecords.push({
id: Math.random().toString(36).substring(2, 9),
platform: 'facebook',
postId: pageRes.postId,
postUrl: pageRes.postUrl,
title: `[${pageRes.pageName || 'Facebook'}] ${caption.substring(0, 50) || `${publishFormat.toUpperCase()} update`}`,
timestamp: 'Just now',
thumbnail: customPhotoFile ? customPhotoFile.url : (customFile ? customFile.url : (fbAccount.avatarUrl || ''))
});
}
}
}
for (const p of selectedPlatforms) {
const sRes = serverResults[p];
if (sRes && sRes.success) {
mappedResults[p] = {
platform: p,
success: true,
postId: sRes.postId,
postUrl: sRes.postUrl,
executionTimeMs: sRes.executionTimeMs || 1200,
logs: [{
timestamp: new Date().toISOString(),
phase: 'COMPLETED',
message: `Published [${publishFormat}] to ${p} via real API endpoint.`,
level: 'success'
}]
};
newRecords.push({
id: Math.random().toString(36).substring(2, 9),
platform: p,
postId: sRes.postId,
postUrl: sRes.postUrl,
title: caption.substring(0, 60) || `${publishFormat.toUpperCase()} update`,
timestamp: 'Just now',
thumbnail: customPhotoFile ? customPhotoFile.url : (customFile ? customFile.url : (fbAccount.avatarUrl || ''))
});
} else {
mappedResults[p] = {
platform: p,
success: false,
error: sRes?.error || 'Failed to publish to real account via API.',
executionTimeMs: 0,
logs: [{
timestamp: new Date().toISOString(),
phase: 'ERROR',
message: sRes?.error || 'Unknown error',
level: 'error'
}]
};
}
}
setPublishProgress(100);
setLatestResults(mappedResults);
if (newRecords.length > 0) {
onPublishSuccess(newRecords);
}
} catch (err: any) {
console.error('Publishing failed:', err);
const fallbackResults: Record<PlatformType, PublishResult> = {} as any;
for (const p of selectedPlatforms) {
fallbackResults[p] = {
platform: p,
success: false,
error: err.message || 'Connection error to backend publisher',
executionTimeMs: 0,
logs: [{
timestamp: new Date().toISOString(),
phase: 'ERROR',
message: err.message,
level: 'error'
}]
};
}
setLatestResults(fallbackResults);
} finally {
setIsPublishing(false);
}
};
const currentTheme = STATUS_THEMES.find(t => t.id === statusTheme) || STATUS_THEMES[0];
const fbAccount = accounts.facebook;
return (
<div className="space-y-6 pb-12">
{/* All Social Media Live Connected Cards - Exact Uploaded Screenshot Style */}
<SocialAccountsBannerList
lang={lang}
accounts={accounts}
facebookPages={facebookPages || []}
onSyncRealData={onSyncRealData}
isSyncingRealData={isSyncingRealData}
onNavigateToConnect={onNavigateToConnect}
/>
{/* Format Switcher: Reels, Feed Post, Status Update */}
<div className="bg-slate-900/90 border border-slate-800 p-2 rounded-2xl shadow-lg">
<div className="grid grid-cols-3 gap-2">
{/* 1. Reels Option */}
<button
onClick={() => { setPublishFormat('reel'); setInputError(null); }}
className={`p-3 sm:p-4 rounded-xl text-left transition-all flex items-start gap-3 relative overflow-hidden ${
publishFormat === 'reel'
? 'bg-gradient-to-r from-emerald-950/80 to-slate-900 border-2 border-emerald-500 shadow-md ring-2 ring-emerald-500/20'
: 'bg-slate-950/40 border border-slate-800 hover:border-slate-700 opacity-75 hover:opacity-100'
}`}
>
<div className={`p-2 rounded-lg ${publishFormat === 'reel' ? 'bg-emerald-600 text-white' : 'bg-slate-800 text-slate-400'}`}>
<Film className="w-5 h-5" />
</div>
<div>
<div className="flex items-center gap-1.5">
<span className="font-bold text-sm text-white">{t.studio.typeReels}</span>
<span className="px-1.5 py-0.2 rounded text-[9px] font-mono bg-emerald-500/20 text-emerald-400">9:16</span>
</div>
<p className="text-[11px] text-slate-400 mt-0.5 line-clamp-1">{t.studio.typeReelsDesc}</p>
</div>
</button>
{/* 2. Feed Post Option */}
<button
onClick={() => { setPublishFormat('post'); setInputError(null); }}
className={`p-3 sm:p-4 rounded-xl text-left transition-all flex items-start gap-3 relative overflow-hidden ${
publishFormat === 'post'
? 'bg-gradient-to-r from-blue-950/80 to-slate-900 border-2 border-blue-500 shadow-md ring-2 ring-blue-500/20'
: 'bg-slate-950/40 border border-slate-800 hover:border-slate-700 opacity-75 hover:opacity-100'
}`}
>
<div className={`p-2 rounded-lg ${publishFormat === 'post' ? 'bg-blue-600 text-white' : 'bg-slate-800 text-slate-400'}`}>
<ImageIcon className="w-5 h-5" />
</div>
<div>
<div className="flex items-center gap-1.5">
<span className="font-bold text-sm text-white">{t.studio.typePost}</span>
<span className="px-1.5 py-0.2 rounded text-[9px] font-mono bg-blue-500/20 text-blue-400">Media</span>
</div>
<p className="text-[11px] text-slate-400 mt-0.5 line-clamp-1">{t.studio.typePostDesc}</p>
</div>
</button>
{/* 3. Status Update Option */}
<button
onClick={() => { setPublishFormat('status'); setInputError(null); }}
className={`p-3 sm:p-4 rounded-xl text-left transition-all flex items-start gap-3 relative overflow-hidden ${
publishFormat === 'status'
? 'bg-gradient-to-r from-purple-950/80 to-slate-900 border-2 border-purple-500 shadow-md ring-2 ring-purple-500/20'
: 'bg-slate-950/40 border border-slate-800 hover:border-slate-700 opacity-75 hover:opacity-100'
}`}
>
<div className={`p-2 rounded-lg ${publishFormat === 'status' ? 'bg-purple-600 text-white' : 'bg-slate-800 text-slate-400'}`}>
<MessageSquare className="w-5 h-5" />
</div>
<div>
<div className="flex items-center gap-1.5">
<span className="font-bold text-sm text-white">{t.studio.typeStatus}</span>
<span className="px-1.5 py-0.2 rounded text-[9px] font-mono bg-purple-500/20 text-purple-400">Text</span>
</div>
<p className="text-[11px] text-slate-400 mt-0.5 line-clamp-1">{t.studio.typeStatusDesc}</p>
</div>
</button>
</div>
</div>
{/* Main Grid: Composer (Left) & Smartphone Mockup (Right) */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
{/* Left Column: 3-Step Composer (7 Cols) */}
<div className="lg:col-span-7 space-y-5">
{/* Step 1: Platforms */}
<div className="bg-slate-900/80 border border-slate-800 rounded-2xl p-5 shadow-lg">
<div className="flex items-center justify-between mb-3">
<label className="text-xs font-bold text-slate-200 uppercase tracking-wider">
{t.studio.step1Title}
</label>
<span className="text-xs text-slate-400">
{selectedPlatforms.length} Selected
</span>
</div>
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2.5">
{(['facebook', 'youtube', 'instagram', 'tiktok', 'linkedin'] as PlatformType[]).map((p) => {
const spec = PLATFORM_SPECS[p];
const acc = accounts[p];
const isSelected = selectedPlatforms.includes(p);
return (
<button
key={p}
onClick={() => togglePlatform(p)}
className={`p-3 rounded-xl border text-left transition-all relative overflow-hidden ${
isSelected
? 'bg-slate-800 border-emerald-500 ring-2 ring-emerald-500/20 shadow-md'
: 'bg-slate-950/60 border-slate-800/80 opacity-60 hover:opacity-100'
}`}
>
<div className="flex items-center justify-between mb-1.5">
<span className="w-2.5 h-2.5 rounded-full" style={{ backgroundColor: spec?.brandColor || '#3b82f6' }} />
<div className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] ${
isSelected ? 'bg-emerald-600 text-white' : 'bg-slate-800 text-slate-500'
}`}>
{isSelected && <Check className="w-2.5 h-2.5" />}
</div>
</div>
<div className="font-bold text-xs text-white capitalize">{p}</div>
<div className="text-[10px] text-slate-400 truncate">{acc?.connected ? acc.accountName : (lang === 'bn' ? 'কানেক্ট করা নেই' : 'Not Connected')}</div>
{p === 'facebook' && acc?.connected && (
<span className="mt-1 block text-[9px] text-emerald-400 font-semibold font-mono">Live API</span>
)}
{p === 'youtube' && acc?.connected && (
<span className="mt-1 block text-[9px] text-red-400 font-semibold font-mono">Live API</span>
)}
</button>
);
})}
</div>
{/* Multiple Facebook Pages Selection */}
{selectedPlatforms.includes('facebook') && accounts.facebook?.connected && facebookPages && facebookPages.length > 0 && (
<div className="mt-4 pt-4 border-t border-slate-800/80 space-y-2.5 animate-fadeIn">
<div className="flex items-center justify-between">
<div className="flex items-center gap-1.5">
<Layers className="w-3.5 h-3.5 text-blue-400" />
<span className="text-xs font-bold text-slate-200 uppercase tracking-wider">
{lang === 'bn' ? 'টার্গেট ফেসবুক পেজ (Target Pages)' : 'Target Facebook Pages'}
</span>
<span className="px-2 py-0.5 rounded-full text-[10px] font-mono font-bold bg-blue-500/20 text-blue-400 border border-blue-500/30">
{selectedPageIds.length} {lang === 'bn' ? 'টি নির্বাচিত' : 'Selected'}
</span>
</div>
<div className="flex items-center gap-2">
<button
type="button"
onClick={() => {
if (selectedPageIds.length === facebookPages.length) {
setSelectedPageIds([facebookPages[0].id]);
} else {
setSelectedPageIds(facebookPages.map(p => p.id));
}
}}
className="text-[11px] text-emerald-400 hover:text-emerald-300 font-medium transition-colors"
>
{selectedPageIds.length === facebookPages.length
? (lang === 'bn' ? 'ডিফল্ট পেজ' : 'Select Default')
: (lang === 'bn' ? 'সব পেজ সিলেক্ট করুন' : 'Select All Pages')}
</button>
{onNavigateToConnect && currentUser?.role === 'admin' && (
<button
type="button"
onClick={onNavigateToConnect}
className="text-[11px] text-blue-400 hover:text-blue-300 flex items-center gap-0.5 font-medium ml-1"
>
<Plus className="w-3 h-3" />
<span>{lang === 'bn' ? 'পেজ যুক্ত/ম্যানেজ' : 'Add/Manage'}</span>
</button>
)}
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
{facebookPages.map((pg) => {
const isPageSelected = selectedPageIds.includes(pg.id);
return (
<div
key={pg.id}
onClick={() => {
setSelectedPageIds(prev => {
if (prev.includes(pg.id)) {
if (prev.length === 1) return prev; // Keep at least one selected
return prev.filter(id => id !== pg.id);
} else {
return [...prev, pg.id];
}
});
}}
className={`p-2.5 rounded-xl border flex items-center justify-between cursor-pointer transition-all ${
isPageSelected
? 'bg-blue-950/40 border-blue-500/80 text-white shadow-sm ring-1 ring-blue-500/30'
: 'bg-slate-950/50 border-slate-800/80 text-slate-400 hover:border-slate-700'
}`}
>
<div className="flex items-center gap-2.5 min-w-0">
{pg.avatarUrl ? (
<img src={pg.avatarUrl} alt={pg.name} className="w-7 h-7 rounded-full object-cover ring-1 ring-white/20 shrink-0" />
) : (
<div className="w-7 h-7 rounded-full bg-blue-600/30 text-blue-400 flex items-center justify-center text-xs font-bold shrink-0">
{pg.name.charAt(0)}
</div>
)}
<div className="truncate">
<div className="text-xs font-bold text-white truncate flex items-center gap-1">
<span>{pg.name}</span>
{pg.isVerified && <span className="text-[9px] text-blue-400">✓</span>}
</div>
<div className="text-[10px] text-slate-400 font-mono">ID: {pg.id} • {pg.followersCount || pg.fanCount || 0} Followers</div>
</div>
</div>
<div className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] ml-2 shrink-0 ${
isPageSelected ? 'bg-blue-600 text-white' : 'bg-slate-800 text-slate-600'
}`}>
{isPageSelected && <Check className="w-2.5 h-2.5" />}
</div>
</div>
);
})}
</div>
</div>
)}
</div>
{/* Step 2: Media Content & Format Setup (NO DEMO PRESETS) */}
<div className="bg-slate-900/80 border border-slate-800 rounded-2xl p-5 shadow-lg">
{/* Format = REEL */}
{publishFormat === 'reel' && (
<div className="space-y-4">
<div className="flex items-center justify-between">
<label className="text-xs font-bold text-slate-200 uppercase tracking-wider flex items-center gap-1.5">
<Film className="w-3.5 h-3.5 text-emerald-400" />
<span>{lang === 'bn' ? 'ভিডিও আপলোড (৯:১৬ রিলস)' : 'Upload Video Reel (9:16 Vertical)'}</span>
</label>
{customFile && (
<button
onClick={removeVideo}
className="text-xs text-rose-400 hover:text-rose-300 flex items-center gap-1 font-semibold"
>
<X className="w-3.5 h-3.5" />
<span>{lang === 'bn' ? 'মুছে ফেলুন' : 'Remove Video'}</span>
</button>
)}
</div>
{!customFile ? (
/* Video Upload Dropzone */
<label className="border-2 border-dashed border-slate-700 hover:border-emerald-500/80 bg-slate-950/60 hover:bg-slate-950 p-6 rounded-2xl flex flex-col items-center justify-center text-center cursor-pointer transition-all group">
<div className="w-12 h-12 rounded-full bg-emerald-500/10 text-emerald-400 group-hover:bg-emerald-500/20 flex items-center justify-center mb-3 transition-colors">
<FileVideo className="w-6 h-6" />
</div>
<h4 className="text-sm font-bold text-white mb-1">
{lang === 'bn' ? 'আপনার রিল ভিডিও ফাইল সিলেক্ট করুন' : 'Select your Reel video file'}
</h4>
<p className="text-xs text-slate-400 mb-2">
{lang === 'bn' ? 'MP4 অথবা MOV ফরম্যাট (প্রস্তাবিত ৯:১৬ ভার্টিক্যাল)' : 'MP4 or MOV format (Recommended 9:16 vertical, max 1080x1920)'}
</p>
<span className="px-3 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-semibold shadow transition-all">
<Upload className="w-3.5 h-3.5 inline mr-1" />
{t.studio.uploadCustom}
</span>
<input
type="file"
accept="video/mp4,video/quicktime,video/webm"
onChange={handleCustomUpload}
className="hidden"
/>
</label>
) : (
/* Uploaded Video File Preview Card */
<div className="p-4 rounded-xl bg-slate-950 border border-emerald-500/40 space-y-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="p-2 rounded-lg bg-emerald-500/10 text-emerald-400">
<Film className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-bold text-white truncate max-w-xs">{customFile.name}</h4>
<span className="text-[10px] text-slate-400 font-mono">
{(customFile.size / 1024 / 1024).toFixed(2)} MB • Ready for Meta Reels
</span>
</div>
</div>
<span className="px-2 py-0.5 rounded text-[10px] font-bold uppercase bg-emerald-500/20 text-emerald-400 border border-emerald-500/30">
Ready
</span>
</div>
<div className="rounded-lg overflow-hidden bg-black aspect-video max-h-48 flex items-center justify-center">
<video
src={customFile.url}
controls
className="max-h-48 w-full object-contain"
/>
</div>
</div>
)}
</div>
)}
{/* Format = POST (PHOTO OR VIDEO - BOTH FULLY SUPPORTED) */}
{publishFormat === 'post' && (
<div className="space-y-4">
<div className="flex items-center justify-between">
<label className="text-xs font-bold text-slate-200 uppercase tracking-wider flex items-center gap-1.5">
<ImageIcon className="w-3.5 h-3.5 text-blue-400" />
<span>{lang === 'bn' ? 'পোস্ট মিডিয়া: ছবি অথবা ভিডিও আপলোড' : 'Post Media: Photo or Video Upload'}</span>
</label>
{(customPhotoFile || customFile) && (
<button
onClick={() => {
removePhoto();
removeVideo();
}}
className="text-xs text-rose-400 hover:text-rose-300 flex items-center gap-1 font-semibold"
>
<X className="w-3.5 h-3.5" />
<span>{lang === 'bn' ? 'মুছে ফেলুন' : 'Remove Media'}</span>
</button>
)}
</div>
{/* Hidden input elements for specific pickers */}
<input
type="file"
ref={postPhotoInputRef}
accept="image/*"
onChange={handlePhotoUpload}
className="hidden"
/>
<input
type="file"
ref={postVideoInputRef}
accept="video/mp4,video/quicktime,video/webm"
onChange={handleCustomUpload}
className="hidden"
/>
{!customPhotoFile && !customFile ? (
/* Dual Photo & Video Upload Dropzone */
<div className="border-2 border-dashed border-slate-700 hover:border-blue-500/80 bg-slate-950/60 hover:bg-slate-950 p-6 rounded-2xl flex flex-col items-center justify-center text-center transition-all group">
<div className="flex items-center gap-2 mb-3">
<div className="w-11 h-11 rounded-full bg-blue-500/10 text-blue-400 flex items-center justify-center">
<ImageIcon className="w-5 h-5" />
</div>
<span className="text-slate-600 font-bold">+</span>
<div className="w-11 h-11 rounded-full bg-teal-500/10 text-teal-400 flex items-center justify-center">
<Film className="w-5 h-5" />
</div>
</div>
<h4 className="text-sm font-bold text-white mb-1">
{lang === 'bn' ? 'ফিড পোস্টের জন্য ছবি অথবা ভিডিও আপলোড করুন' : 'Upload photo or video for your feed post'}
</h4>
<p className="text-xs text-slate-400 mb-4 max-w-sm">
{lang === 'bn'
? 'ছবি (JPG, PNG, WEBP) অথবা যেকোনো ভিডিও (MP4, MOV) আপলোড করা যাবে।'
: 'Both photos (JPG, PNG, WEBP) and videos (MP4, MOV) are fully supported.'}
</p>
{/* Dual Action Buttons */}
<div className="flex flex-wrap items-center justify-center gap-2.5">
<button
type="button"
onClick={() => postPhotoInputRef.current?.click()}
className="px-3.5 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 text-white text-xs font-bold shadow-md shadow-blue-600/30 transition-all flex items-center gap-1.5"
>
<ImageIcon className="w-3.5 h-3.5" />
<span>{lang === 'bn' ? '📷 ছবি আপলোড করুন' : '📷 Select Photo'}</span>
</button>
<button
type="button"
onClick={() => postVideoInputRef.current?.click()}
className="px-3.5 py-2 rounded-xl bg-teal-600 hover:bg-teal-500 text-white text-xs font-bold shadow-md shadow-teal-600/30 transition-all flex items-center gap-1.5"
>
<Film className="w-3.5 h-3.5" />
<span>{lang === 'bn' ? '🎥 ভিডিও আপলোড করুন' : '🎥 Select Video'}</span>
</button>
</div>
{/* Fallback drag-and-drop input */}
<label className="mt-3 text-[11px] text-slate-500 hover:text-slate-400 cursor-pointer underline">
<span>{lang === 'bn' ? 'অথবা ড্র্যাগ করে ফাইল ড্রপ করুন' : 'or drag & drop file here'}</span>
<input
type="file"
accept="image/*,video/mp4,video/quicktime,video/webm"
onChange={handlePostMediaUpload}
className="hidden"
/>
</label>
</div>
) : customPhotoFile ? (
/* Attached Photo Card */
<div className="p-4 rounded-xl bg-slate-950 border border-blue-500/40 space-y-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="p-2 rounded-lg bg-blue-500/10 text-blue-400">
<ImageIcon className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-bold text-white truncate max-w-xs">{customPhotoFile.name}</h4>
<span className="text-[10px] text-blue-400 font-mono">Photo Post Attached</span>
</div>
</div>
<div className="flex items-center gap-2">
<button
type="button"
onClick={() => postVideoInputRef.current?.click()}
className="text-[11px] text-slate-400 hover:text-teal-400 font-medium"
>
{lang === 'bn' ? 'ভিডিওতে পরিবর্তন' : 'Switch to Video'}
</button>
<span className="px-2 py-0.5 rounded text-[10px] font-bold uppercase bg-blue-500/20 text-blue-400 border border-blue-500/30">
Photo
</span>
</div>
</div>
<div className="rounded-lg overflow-hidden bg-black max-h-48 flex items-center justify-center">
<img
src={customPhotoFile.url}
alt="Uploaded preview"
className="max-h-48 w-full object-contain"
/>
</div>
</div>
) : (
/* Attached Video Card */
<div className="p-4 rounded-xl bg-slate-950 border border-teal-500/40 space-y-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="p-2 rounded-lg bg-teal-500/10 text-teal-400">
<Film className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-bold text-white truncate max-w-xs">{customFile?.name}</h4>
<span className="text-[10px] text-teal-400 font-mono">
Video Post • {customFile ? (customFile.size / (1024 * 1024)).toFixed(1) : 0} MB
</span>
</div>
</div>
<div className="flex items-center gap-2">
<button
type="button"
onClick={() => postPhotoInputRef.current?.click()}
className="text-[11px] text-slate-400 hover:text-blue-400 font-medium"
>
{lang === 'bn' ? 'ছবিতে পরিবর্তন' : 'Switch to Photo'}
</button>
<span className="px-2 py-0.5 rounded text-[10px] font-bold uppercase bg-teal-500/20 text-teal-400 border border-teal-500/30">
Video
</span>
</div>
</div>
<div className="rounded-lg overflow-hidden bg-black max-h-52 flex items-center justify-center">
<video
src={customFile?.url}
controls
className="max-h-52 w-full object-contain"
/>
</div>
</div>
)}
</div>
)}
{/* Format = STATUS (TEXT ONLY WITH THEMES) */}
{publishFormat === 'status' && (
<div className="space-y-3">
<div className="flex items-center justify-between">
<label className="text-xs font-bold text-slate-200 uppercase tracking-wider flex items-center gap-1.5">
<Palette className="w-3.5 h-3.5 text-purple-400" />
<span>{t.studio.statusTheme}</span>
</label>
<span className="text-[11px] text-purple-400 font-semibold">
{lang === 'bn' ? 'ফেসবুক কালার স্ট্যাটাস' : 'Facebook Gradient Status'}
</span>
</div>
<div className="grid grid-cols-3 sm:grid-cols-6 gap-2">
{STATUS_THEMES.map((theme) => (
<button
key={theme.id}
onClick={() => setStatusTheme(theme.id)}
className={`h-12 rounded-xl p-1 transition-all relative overflow-hidden flex items-center justify-center font-bold text-xs ${theme.bgClass} ${
statusTheme === theme.id ? 'ring-2 ring-white scale-105 shadow-lg' : 'opacity-80 hover:opacity-100'
}`}
>
<span className="text-[10px] text-white font-mono drop-shadow">{theme.name}</span>
{statusTheme === theme.id && (
<div className="absolute top-1 right-1 w-3 h-3 bg-white text-slate-900 rounded-full flex items-center justify-center text-[8px] font-bold">
✓
</div>
)}
</button>
))}
</div>
</div>
)}
</div>
{/* Step 3: Caption, Text & Tags */}
<div className="bg-slate-900/80 border border-slate-800 rounded-2xl p-5 shadow-lg space-y-3">
<div className="flex items-center justify-between">
<label className="text-xs font-bold text-slate-200 uppercase tracking-wider">
{publishFormat === 'status'
? (lang === 'bn' ? 'স্ট্যাটাস বার্তা (Status Text)' : 'Status Message')
: t.studio.step3Title}
</label>
<span className="text-xs font-mono text-slate-400">
{caption.length} / 2200
</span>
</div>
<textarea
rows={publishFormat === 'status' ? 4 : 3}
value={caption}
onChange={(e) => { setCaption(e.target.value); setInputError(null); }}
placeholder={publishFormat === 'status' ? t.studio.statusPlaceholder : t.studio.captionPlaceholder}
className="w-full bg-slate-950 border border-slate-800 rounded-xl p-3 text-xs sm:text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 font-sans"
/>
{/* Error message */}
{inputError && (
<div className="p-2.5 rounded-lg bg-rose-500/10 border border-rose-500/30 flex items-center gap-2 text-rose-400 text-xs font-medium">
<AlertCircle className="w-4 h-4 shrink-0" />
<span>{inputError}</span>
</div>
)}
{/* Custom Hashtags - User Defined (No Default Presets) */}
<div className="pt-2 border-t border-slate-800/80 space-y-2.5">
<div className="flex items-center justify-between">
<span className="text-xs font-bold text-slate-300 flex items-center gap-1.5">
<Hash className="w-3.5 h-3.5 text-emerald-400" />
<span>
{lang === 'bn'
? 'আমার হ্যাশট্যাগসমূহ (Custom Hashtags):'
: lang === 'zh'
? '自定义话题标签 (My Hashtags):'
: 'My Custom Hashtags:'}
</span>
</span>
{userHashtags.length > 0 && (
<span className="text-[11px] text-slate-400 font-mono">
{userHashtags.length} {lang === 'bn' ? 'টি সেভ করা' : 'saved'}
</span>
)}
</div>
{/* Tag creation input bar */}
<form onSubmit={handleCreateTag} className="flex items-center gap-2">
<div className="relative flex-1">
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-500 font-bold font-mono text-xs">#</span>
<input
type="text"
value={newTagInput}
onChange={(e) => setNewTagInput(e.target.value)}
placeholder={
lang === 'bn'
? 'হ্যাশট্যাগ লিখুন (যেমন: গান, তালনদী, রিলস)...'
: lang === 'zh'
? '输入新标签 (例如: 音乐, 视频)...'
: 'Create tag (e.g. music, acoustic, reels)...'
}
className="w-full pl-7 pr-3 py-2 bg-slate-950 border border-slate-800 rounded-xl text-xs text-slate-100 placeholder-slate-500 focus:outline-none focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 font-mono"
/>
</div>
<button
type="submit"
disabled={!newTagInput.trim()}
className="px-3.5 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 disabled:opacity-40 disabled:hover:bg-emerald-600 text-white text-xs font-semibold flex items-center gap-1.5 transition-all shrink-0 shadow-sm shadow-emerald-600/30"
>
<Plus className="w-3.5 h-3.5" />
<span>{lang === 'bn' ? 'যোগ করুন' : 'Add Tag'}</span>
</button>
</form>
{/* Tag Chips list */}
{userHashtags.length > 0 ? (
<div className="flex flex-wrap items-center gap-1.5 pt-0.5">
{userHashtags.map((tag) => {
const isAdded = caption.includes(tag);
return (
<span
key={tag}
onClick={() => handleToggleTagInCaption(tag)}
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-mono cursor-pointer transition-all border ${
isAdded
? 'bg-emerald-950/80 border-emerald-500/80 text-emerald-300 font-bold shadow-sm'
: 'bg-slate-950 border-slate-800 hover:border-slate-700 text-slate-300 hover:text-white'
}`}
title={
isAdded
? (lang === 'bn' ? 'ক্যাপশন থেকে বাদ দিতে ক্লিক করুন' : 'Click to remove from caption')
: (lang === 'bn' ? 'ক্যাপশনে যোগ করতে ক্লিক করুন' : 'Click to add into caption')
}
>
<span>{tag}</span>
{isAdded && <span className="text-[10px] text-emerald-400 font-bold">✓</span>}
<button
type="button"
onClick={(e) => handleRemoveTag(tag, e)}
className="hover:text-rose-400 p-0.5 rounded text-slate-500 hover:bg-rose-500/10 transition-colors ml-0.5"
title={lang === 'bn' ? 'ডিলিট করুন' : 'Delete'}
>
<X className="w-3 h-3" />
</button>
</span>
);
})}
</div>
) : (
<p className="text-[11px] text-slate-500 italic">
{lang === 'bn'
? 'কোনো ডিফল্ট হ্যাশট্যাগ নেই। নিজের পছন্দমতো হ্যাশট্যাগ লিখে "+ যোগ করুন" বাটনে ক্লিক করুন।'
: 'No default hashtags. Create your own custom tags above.'}
</p>
)}
</div>
{/* Big Action Button */}
<div className="pt-2">
<button
onClick={handlePublish}
disabled={isPublishing || selectedPlatforms.length === 0}
className={`w-full py-4 px-4 rounded-xl font-bold text-sm flex items-center justify-center gap-2 shadow-xl transition-all ${
isPublishing || selectedPlatforms.length === 0
? 'bg-slate-800 text-slate-500 cursor-not-allowed'
: 'bg-gradient-to-r from-emerald-600 via-teal-600 to-blue-600 hover:from-emerald-500 hover:to-blue-500 text-white shadow-emerald-500/20 hover:scale-[1.01]'
}`}
>
{isPublishing ? (
<>
<RefreshCw className="w-4 h-4 animate-spin text-white" />
<span>{lang === 'bn' ? 'সাবমিট হচ্ছে...' : 'Submitting...'}</span>
</>
) : (
<>
<Send className="w-4 h-4 fill-current text-white" />
<span className="text-base font-bold tracking-wide">
{lang === 'bn' ? 'সাবমিট (Submit)' : 'Submit'}
</span>
</>
)}
</button>
</div>
{/* Publishing Progress Bar */}
{isPublishing && (
<div className="p-3.5 rounded-xl bg-slate-950 border border-slate-800 space-y-2 animate-fadeIn">
<div className="flex items-center justify-between text-xs">
<span className="text-slate-300">{currentPublishPhase}</span>
<span className="text-emerald-400 font-mono font-bold">{publishProgress}%</span>
</div>
<div className="w-full h-2 bg-slate-800 rounded-full overflow-hidden">
<div
className="h-full bg-gradient-to-r from-emerald-500 to-teal-400 transition-all duration-300"
style={{ width: `${publishProgress}%` }}
/>
</div>
</div>
)}
{/* Published Results Card */}
{latestResults && (
<div className="p-4 rounded-xl bg-emerald-950/30 border border-emerald-500/30 space-y-3">
<div className="flex items-center justify-between">
<span className="text-xs font-bold text-emerald-400 flex items-center gap-1.5">
<CheckCircle2 className="w-4 h-4" />
<span>{t.studio.successTitle}</span>
</span>
<span className="text-[11px] text-slate-400">
{Object.values(latestResults).filter(r => r.success).length} of {Object.values(latestResults).length} live
</span>
</div>
{/* Multi-Page Facebook breakdown if published to multiple pages */}
{multiPagePublishResults.length > 0 && (
<div className="space-y-1.5 pt-1 border-t border-emerald-500/20">
<div className="text-[11px] font-bold text-slate-300 flex items-center gap-1.5">
<Layers className="w-3.5 h-3.5 text-blue-400" />
<span>{lang === 'bn' ? 'ফেসবুক পেজ প্রকাশের রিপোর্ট:' : 'Facebook Pages Dispatch Report:'}</span>
</div>
<div className="grid grid-cols-1 gap-1.5">
{multiPagePublishResults.map((pageRes, idx) => (
<div key={idx} className="p-2 rounded-lg bg-slate-900 border border-slate-800 flex items-center justify-between text-xs">
<div className="flex items-center gap-2 min-w-0">
<span className={`w-2 h-2 rounded-full ${pageRes.success ? 'bg-emerald-400' : 'bg-rose-400'}`} />
<div className="truncate">
<span className="font-bold text-white block truncate">{pageRes.pageName || 'Facebook Page'}</span>
<span className="text-[10px] text-slate-400 font-mono">
{pageRes.success ? `Post ID: ${pageRes.postId}` : (pageRes.error || 'Error')}
</span>
</div>
</div>
{pageRes.postUrl && (
<a
href={pageRes.postUrl}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1 text-[11px] text-emerald-400 hover:underline shrink-0 bg-emerald-950/50 px-2 py-1 rounded border border-emerald-500/30 font-medium"
>
<span>{lang === 'bn' ? 'পোস্ট দেখুন' : 'View Post'}</span>
<ExternalLink className="w-3 h-3" />
</a>
)}
</div>
))}
</div>
</div>
)}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs">
{Object.entries(latestResults).map(([plat, res]) => (
<div key={plat} className="p-2.5 rounded-lg bg-slate-900 border border-slate-800 flex items-center justify-between">
<div>
<span className="font-bold text-white capitalize block">{plat}</span>
{res.postId && <span className="text-[10px] text-slate-400 font-mono truncate max-w-[120px] block">{res.postId}</span>}
{res.error && <span className="text-[10px] text-rose-400 block truncate max-w-[140px]">{res.error}</span>}
</div>
{res.postUrl && (
<a
href={res.postUrl}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1 text-[11px] text-emerald-400 hover:underline shrink-0 bg-emerald-950/50 px-2 py-1 rounded border border-emerald-500/30"
>
<span>Live</span>
<ExternalLink className="w-3 h-3" />
</a>
)}
</div>
))}
</div>
</div>
)}
</div>
</div>
{/* Right Column: Live Mobile Mockup Preview (5 Cols) */}
<div className="lg:col-span-5 flex flex-col items-center">
{/* Switch Mockup View Tabs */}
<div className="w-full max-w-[340px] mb-3 flex items-center justify-between bg-slate-900 p-1 rounded-xl border border-slate-800 text-xs">
{(['facebook', 'youtube', 'instagram', 'tiktok', 'linkedin'] as PlatformType[]).map((p) => {
const spec = PLATFORM_SPECS[p];
return (
<button
key={p}
onClick={() => setPreviewPlatform(p)}
className={`flex-1 py-1.5 rounded-lg font-semibold text-[11px] capitalize transition-all ${
previewPlatform === p
? 'bg-slate-800 text-white shadow'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<span className="inline-block w-1.5 h-1.5 rounded-full mr-1" style={{ backgroundColor: spec?.brandColor || '#ef4444' }} />
{p === 'facebook' ? 'FB' : p === 'youtube' ? 'YT' : p === 'instagram' ? 'IG' : p === 'tiktok' ? 'TikTok' : 'LinkedIn'}
</button>
);
})}
</div>
{/* Smartphone Frame */}
<div className="w-full max-w-[340px] aspect-[9/18.5] bg-black rounded-[42px] p-3 shadow-2xl ring-4 ring-slate-800 relative flex flex-col justify-between overflow-hidden">
{/* Camera island */}
<div className="absolute top-4 left-1/2 -translate-x-1/2 w-24 h-5 bg-black rounded-full z-30 flex items-center justify-center">
<span className="w-2 h-2 rounded-full bg-slate-900 mr-2" />
<span className="w-2.5 h-2.5 rounded-full bg-slate-800" />
</div>
{/* Screen Container */}
<div className="relative w-full h-full rounded-[32px] overflow-hidden bg-slate-950 flex flex-col justify-between">
{/* Top Navigation Bar */}
<div className="relative z-20 pt-6 px-4 pb-2 bg-gradient-to-b from-black/80 to-transparent flex items-center justify-between text-white text-xs font-semibold">
<span className="text-[11px] uppercase tracking-wider font-mono opacity-80">
{previewPlatform.toUpperCase()} • {publishFormat.toUpperCase()}
</span>
<span className={`text-[10px] px-2 py-0.5 rounded-full font-mono ${
accounts[previewPlatform]?.connected ? 'bg-blue-500/30 text-blue-300' : 'bg-slate-800 text-slate-400'
}`}>
{accounts[previewPlatform]?.connected ? 'Live View' : 'Disconnected'}
</span>
</div>
{!accounts[previewPlatform]?.connected ? (
<div className="relative z-10 w-full h-full flex flex-col items-center justify-center p-6 text-center">
<div className="w-14 h-14 rounded-2xl bg-slate-900 border border-slate-800 flex items-center justify-center mb-3 shadow-inner">
<span className="w-4 h-4 rounded-full" style={{ backgroundColor: PLATFORM_SPECS[previewPlatform]?.brandColor || '#94a3b8' }} />
</div>
<h4 className="text-xs font-bold text-white mb-1">
{PLATFORM_SPECS[previewPlatform]?.name} {lang === 'bn' ? 'কানেক্ট করা নেই' : 'Not Connected'}
</h4>
<p className="text-[11px] text-slate-400 mb-4 max-w-[210px] leading-relaxed">
{lang === 'bn'
? 'এই প্ল্যাটফর্মটি বর্তমানে ডিসকানেক্ট রয়েছে। কোনো পেজ বা অ্যাকাউন্টের তথ্য প্রদর্শিত হবে না।'
: 'This account is disconnected. No page or account information is active.'}
</p>
{onNavigateToConnect && (
<button
onClick={onNavigateToConnect}
className="px-3.5 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-semibold shadow-md transition-all"
>
{lang === 'bn' ? 'অ্যাকাউন্ট কানেক্ট করুন' : 'Connect Account'}
</button>
)}
</div>
) : (
<>
{/* FORMAT: STATUS UPDATE PREVIEW */}
{publishFormat === 'status' && (
<div className="relative z-10 w-full h-full flex flex-col justify-between p-4 pt-12 overflow-y-auto">
{/* Status Author Bar */}
<div className="flex items-center gap-2.5 pb-3">
<img
src={accounts[previewPlatform].avatarUrl || fbAccount.avatarUrl}
alt="Avatar"
className="w-10 h-10 rounded-full object-cover ring-1 ring-white/30"
/>
<div>
<div className="flex items-center gap-1">
<span className="font-bold text-xs text-white">{accounts[previewPlatform].accountName}</span>
<span className="w-3.5 h-3.5 rounded-full bg-blue-500 text-white flex items-center justify-center text-[8px] font-bold">✓</span>
</div>
<span className="text-[10px] text-slate-400 block">Just now • 🌐 Public</span>
</div>
</div>
{/* Gradient Card with Text */}
<div className={`w-full min-h-[220px] rounded-2xl p-6 flex items-center justify-center text-center shadow-lg transition-all ${currentTheme.bgClass}`}>
<p className={`font-bold leading-relaxed text-sm sm:text-base ${currentTheme.textClass} drop-shadow-sm`}>
{caption || (lang === 'bn' ? 'আপনার মনে এখন কি চলছে? স্ট্যাটাস লিখুন...' : "What's on your mind? Type a status...")}
</p>
</div>
{/* Facebook Engagement Action Bar */}
<div className="pt-3 border-t border-slate-800/80">
<div className="flex items-center justify-between text-[11px] text-slate-400 pb-2">
<span className="flex items-center gap-1">
<span className="w-4 h-4 rounded-full bg-blue-600 text-white flex items-center justify-center text-[9px]">👍</span>
<span>0</span>
</span>
<span>0 comments • 0 shares</span>
</div>
<div className="grid grid-cols-3 gap-1 pt-1 border-t border-slate-800/60 text-slate-300 text-[11px]">
<button className="py-1.5 flex items-center justify-center gap-1 hover:bg-slate-800/40 rounded">
<Heart className="w-3.5 h-3.5 text-blue-400" />
<span>Like</span>
</button>
<button className="py-1.5 flex items-center justify-center gap-1 hover:bg-slate-800/40 rounded">
<MessageCircle className="w-3.5 h-3.5" />
<span>Comment</span>
</button>
<button className="py-1.5 flex items-center justify-center gap-1 hover:bg-slate-800/40 rounded">
<Share2 className="w-3.5 h-3.5" />
<span>Share</span>
</button>
</div>
</div>
</div>
)}
{/* FORMAT: FEED POST PREVIEW */}
{publishFormat === 'post' && (
<div className="relative z-10 w-full h-full flex flex-col justify-between p-3 pt-12 overflow-y-auto">
<div>
<div className="flex items-center gap-2.5 pb-2">
<img
src={accounts[previewPlatform].avatarUrl || fbAccount.avatarUrl}
alt="Avatar"
className="w-9 h-9 rounded-full object-cover ring-1 ring-white/30"
/>
<div>
<div className="flex items-center gap-1">
<span className="font-bold text-xs text-white">{accounts[previewPlatform].accountName}</span>
<span className="w-3 h-3 rounded-full bg-blue-500 text-white flex items-center justify-center text-[7px] font-bold">✓</span>
</div>
<span className="text-[10px] text-slate-400 block">Just now • 🌐 Public</span>
</div>
</div>
<p className="text-xs text-slate-200 line-clamp-3 pb-2 leading-relaxed">
{caption || (lang === 'bn' ? 'পোস্টের ক্যাপশন লিখুন...' : 'Write your caption...')}
</p>
</div>
{/* Post Media Container (Photo OR Video) */}
<div className="w-full aspect-[4/3] rounded-xl overflow-hidden bg-slate-900 border border-slate-800 relative my-auto flex items-center justify-center">
{customFile ? (
<video
src={customFile.url}
controls
playsInline
className="w-full h-full object-cover"
/>
) : customPhotoFile ? (
<img
src={customPhotoFile.url}
alt="Post visual"
className="w-full h-full object-cover"
/>
) : (
<div className="text-center p-4">
<div className="flex items-center justify-center gap-2 mb-2 text-slate-500">
<ImageIcon className="w-6 h-6 text-blue-400" />
<Film className="w-6 h-6 text-teal-400" />
</div>
<span className="text-[11px] text-slate-300 font-medium block">
{lang === 'bn' ? 'ছবি অথবা ভিডিও যোগ করুন' : 'Attach Photo or Video'}
</span>
<span className="text-[10px] text-slate-500">
{lang === 'bn' ? 'ফিড পোস্টে ছবি ও ভিডিও ২ টাই সাপোর্ট করে' : 'Both photo and video are supported'}
</span>
</div>
)}
</div>
{/* Actions */}
<div className="pt-2 border-t border-slate-800">
<div className="flex items-center justify-between text-[11px] text-slate-400 pb-1.5">
<span>👍 0</span>
<span>0 comments</span>
</div>
<div className="grid grid-cols-3 gap-1 pt-1 border-t border-slate-800/60 text-slate-300 text-[11px]">
<button className="py-1 flex items-center justify-center gap-1 hover:bg-slate-800 rounded">
<Heart className="w-3.5 h-3.5" />
<span>Like</span>
</button>
<button className="py-1 flex items-center justify-center gap-1 hover:bg-slate-800 rounded">
<MessageCircle className="w-3.5 h-3.5" />
<span>Comment</span>
</button>
<button className="py-1 flex items-center justify-center gap-1 hover:bg-slate-800 rounded">
<Share2 className="w-3.5 h-3.5" />
<span>Share</span>
</button>
</div>
</div>
</div>
)}
{/* FORMAT: 9:16 VERTICAL REEL PREVIEW */}
{publishFormat === 'reel' && (
<>
{customFile ? (
<video
src={customFile.url}
autoPlay
loop
muted
playsInline
className="absolute inset-0 w-full h-full object-cover"
/>
) : (
<div className="absolute inset-0 w-full h-full bg-slate-900 flex flex-col items-center justify-center p-6 text-center">
<Film className="w-12 h-12 text-slate-700 mb-2" />
<span className="text-xs font-bold text-slate-300">
{lang === 'bn' ? 'কোনো ভিডিও আপলোড করা হয়নি' : 'No Video Uploaded'}
</span>
<span className="text-[10px] text-slate-500 mt-1 max-w-[200px]">
{lang === 'bn' ? 'উপরে আপনার ৯:১৬ MP4 রিল আপলোড করলে এখানে লাইভ চলবে।' : 'Upload a 9:16 MP4 video above to preview and publish.'}
</span>
</div>
)}
<div className="absolute inset-0 bg-gradient-to-b from-black/40 via-transparent to-black/85 pointer-events-none" />
{/* Right Side Social Floating Icons */}
<div className="absolute right-3 bottom-20 z-10 flex flex-col items-center gap-4 text-white">
<div className="flex flex-col items-center">
<div className="w-9 h-9 rounded-full bg-black/40 backdrop-blur-md flex items-center justify-center hover:scale-110 transition-transform">
<Heart className="w-5 h-5 text-red-500 fill-current" />
</div>
<span className="text-[10px] font-mono mt-0.5 font-bold">0</span>
</div>
<div className="flex flex-col items-center">
<div className="w-9 h-9 rounded-full bg-black/40 backdrop-blur-md flex items-center justify-center">
<MessageCircle className="w-5 h-5 text-white" />
</div>
<span className="text-[10px] font-mono mt-0.5 font-bold">0</span>
</div>
<div className="flex flex-col items-center">
<div className="w-9 h-9 rounded-full bg-black/40 backdrop-blur-md flex items-center justify-center">
<Share2 className="w-5 h-5 text-white" />
</div>
<span className="text-[10px] font-mono mt-0.5 font-bold">Share</span>
</div>
</div>
{/* Bottom Caption & Profile Overlay */}
<div className="relative z-10 p-4 space-y-2 text-white">
<div className="flex items-center gap-2">
<img
src={accounts[previewPlatform].avatarUrl || fbAccount.avatarUrl}
alt="Author Avatar"
className="w-7 h-7 rounded-full object-cover border border-white/40"
/>
<div>
<div className="flex items-center gap-1">
<span className="text-xs font-bold">{accounts[previewPlatform].accountName}</span>
<span className="w-3 h-3 rounded-full bg-blue-500 text-white flex items-center justify-center text-[7px] font-bold">✓</span>
</div>
<span className="text-[9px] text-slate-300">Original audio</span>
</div>
</div>
<p className="text-xs text-white/90 line-clamp-2 leading-relaxed font-sans">
{caption || (lang === 'bn' ? 'রিলের ক্যাপশন লিখুন...' : 'Add a caption for your Reel...')}
</p>
</div>
</>
)}
</>
)}
</div>
</div>
</div>
</div>
</div>
);
};