Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

555 řádky
29 KiB

  1. 'use client';
  2. import { useState, useEffect } from 'react';
  3. import { Card, Portal, MediaItem } from '@/types';
  4. const isVideoUrl = (url: string) => /\.(mp4|webm|mov|m4v|ogv)(\?|$)/i.test(url);
  5. const isPdfFile = (file: File) =>
  6. file.type === 'application/pdf' || /\.pdf$/i.test(file.name);
  7. async function uploadBlobAsImage(blob: Blob, name: string): Promise<string | null> {
  8. const formData = new FormData();
  9. formData.append('file', new File([blob], name, { type: blob.type || 'image/png' }));
  10. const res = await fetch('/api/upload', { method: 'POST', body: formData });
  11. const data = await res.json();
  12. return data.url || null;
  13. }
  14. async function pdfToImageItems(
  15. file: File,
  16. onProgress: (page: number, total: number) => void
  17. ): Promise<MediaItem[]> {
  18. const pdfjs = await import('pdfjs-dist');
  19. // Worker file is copied to /public via the postinstall script
  20. pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';
  21. const arrayBuffer = await file.arrayBuffer();
  22. const pdf = await pdfjs.getDocument({ data: arrayBuffer }).promise;
  23. const baseName = file.name.replace(/\.pdf$/i, '').replace(/[^a-zA-Z0-9-_]/g, '_');
  24. const items: MediaItem[] = [];
  25. for (let i = 1; i <= pdf.numPages; i++) {
  26. onProgress(i, pdf.numPages);
  27. const page = await pdf.getPage(i);
  28. const viewport = page.getViewport({ scale: 1.5 });
  29. const canvas = document.createElement('canvas');
  30. canvas.width = viewport.width;
  31. canvas.height = viewport.height;
  32. const ctx = canvas.getContext('2d');
  33. if (!ctx) continue;
  34. await page.render({ canvasContext: ctx, viewport }).promise;
  35. const blob: Blob = await new Promise((resolve, reject) => {
  36. canvas.toBlob(b => b ? resolve(b) : reject(new Error('toBlob failed')), 'image/png');
  37. });
  38. const url = await uploadBlobAsImage(blob, `${baseName}-page${i}.png`);
  39. if (url) items.push({ url });
  40. }
  41. return items;
  42. }
  43. export default function AdminDashboard() {
  44. const [activeTab, setActiveTab] = useState<'cards' | 'settings'>('cards');
  45. // Card State
  46. const [cards, setCards] = useState<Card[]>([]);
  47. const [isEditing, setIsEditing] = useState<Partial<Card> | null>(null);
  48. // Portal State
  49. const [portal, setPortal] = useState<Partial<Portal>>({});
  50. const [savingPortal, setSavingPortal] = useState(false);
  51. const [uploading, setUploading] = useState<{ [key: string]: boolean }>({});
  52. // NEW UI STATES: Toast and Confirm Dialog
  53. const [toast, setToast] = useState<string | null>(null);
  54. const [confirmDialog, setConfirmDialog] = useState<{ message: string, onConfirm: () => void } | null>(null);
  55. const [pdfProgress, setPdfProgress] = useState<{ name: string; page: number; total: number } | null>(null);
  56. // Helper to show auto-dismissing toast
  57. const showToast = (message: string) => {
  58. setToast(message);
  59. setTimeout(() => setToast(null), 3000);
  60. };
  61. useEffect(() => {
  62. fetch('/api/cards').then(res => res.json()).then(setCards);
  63. fetch('/api/portals').then(res => res.json()).then(data => data && setPortal(data));
  64. }, []);
  65. const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>, field: string, isPortal = false) => {
  66. if (!e.target.files?.[0]) return;
  67. setUploading(prev => ({ ...prev, [field]: true }));
  68. const formData = new FormData();
  69. formData.append('file', e.target.files[0]);
  70. const res = await fetch('/api/upload', { method: 'POST', body: formData });
  71. const data = await res.json();
  72. if (data.url) {
  73. if (isPortal) {
  74. setPortal(prev => ({ ...prev, [field]: data.url }));
  75. } else {
  76. setIsEditing(prev => ({ ...prev, [field]: data.url }));
  77. }
  78. }
  79. setUploading(prev => ({ ...prev, [field]: false }));
  80. };
  81. const handleUploadExtraMedia = async (e: React.ChangeEvent<HTMLInputElement>) => {
  82. const files = e.target.files;
  83. if (!files || files.length === 0) return;
  84. setUploading(prev => ({ ...prev, extraMedia: true }));
  85. const uploaded: MediaItem[] = [];
  86. for (const file of Array.from(files)) {
  87. try {
  88. if (isPdfFile(file)) {
  89. const items = await pdfToImageItems(file, (page, total) =>
  90. setPdfProgress({ name: file.name, page, total })
  91. );
  92. uploaded.push(...items);
  93. setPdfProgress(null);
  94. } else {
  95. const formData = new FormData();
  96. formData.append('file', file);
  97. const res = await fetch('/api/upload', { method: 'POST', body: formData });
  98. const data = await res.json();
  99. if (data.url) uploaded.push({ url: data.url });
  100. }
  101. } catch (err) {
  102. console.error('Upload failed for', file.name, err);
  103. showToast(`Failed to process "${file.name}".`);
  104. setPdfProgress(null);
  105. }
  106. }
  107. setIsEditing(prev => ({
  108. ...prev,
  109. extraMedia: [...(prev?.extraMedia || []), ...uploaded],
  110. }));
  111. setUploading(prev => ({ ...prev, extraMedia: false }));
  112. e.target.value = '';
  113. };
  114. const removeExtraMedia = (index: number) => {
  115. setIsEditing(prev => ({
  116. ...prev,
  117. extraMedia: (prev?.extraMedia || []).filter((_, i) => i !== index),
  118. }));
  119. };
  120. const toggleAutoplay = (index: number) => {
  121. setIsEditing(prev => ({
  122. ...prev,
  123. extraMedia: (prev?.extraMedia || []).map((m, i) =>
  124. i === index ? { ...m, autoplay: !m.autoplay } : m
  125. ),
  126. }));
  127. };
  128. const handleSaveCard = async () => {
  129. if (!isEditing) return;
  130. const generateSafeId = () => 'card-' + Date.now().toString(36) + Math.random().toString(36).substring(2);
  131. const newCard = { ...isEditing, id: isEditing.id || generateSafeId() } as Card;
  132. await fetch('/api/cards', {
  133. method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(newCard)
  134. });
  135. setCards(prev => {
  136. const exists = prev.find(c => c.id === newCard.id);
  137. return exists ? prev.map(c => c.id === newCard.id ? newCard : c) : [...prev, newCard];
  138. });
  139. setIsEditing(null);
  140. };
  141. const handleDeleteCard = (id: string) => {
  142. // Replace window.confirm with our custom dialog
  143. setConfirmDialog({
  144. message: 'Are you sure you want to delete this card? This action cannot be undone.',
  145. onConfirm: async () => {
  146. await fetch(`/api/cards?id=${id}`, { method: 'DELETE' });
  147. setCards(prev => prev.filter(c => c.id !== id));
  148. setConfirmDialog(null);
  149. showToast('Card successfully deleted.');
  150. }
  151. });
  152. };
  153. const moveCard = async (index: number, direction: 'up' | 'down') => {
  154. const newCards = [...cards];
  155. if (direction === 'up' && index > 0) {
  156. [newCards[index - 1], newCards[index]] = [newCards[index], newCards[index - 1]];
  157. } else if (direction === 'down' && index < newCards.length - 1) {
  158. [newCards[index + 1], newCards[index]] = [newCards[index], newCards[index + 1]];
  159. } else {
  160. return; // Do nothing if trying to move out of bounds
  161. }
  162. // Recalculate displayOrder for the whole array
  163. const updatedCards = newCards.map((c, i) => ({ ...c, displayOrder: i }));
  164. // Optimistically update the UI
  165. setCards(updatedCards);
  166. // Persist the new order to the backend
  167. await fetch('/api/cards', {
  168. method: 'PUT',
  169. headers: { 'Content-Type': 'application/json' },
  170. body: JSON.stringify(updatedCards)
  171. });
  172. };
  173. const handleSavePortal = async () => {
  174. setSavingPortal(true);
  175. await fetch('/api/portals', {
  176. method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(portal)
  177. });
  178. setSavingPortal(false);
  179. showToast('Portal settings saved successfully!'); // Replaced window.alert
  180. };
  181. // Shared Input Classes for high contrast
  182. const inputClasses = "w-full border border-gray-300 p-2.5 rounded-lg outline-none focus:ring-2 focus:ring-blue-500 bg-white text-gray-900 placeholder-gray-400";
  183. return (
  184. <div className="min-h-screen bg-gray-50 font-sans pb-12">
  185. {/* Top Header */}
  186. <div className="bg-blue-900 text-white shadow-md py-6 px-4">
  187. <div className="max-w-5xl mx-auto flex justify-between items-center">
  188. <div>
  189. <h1 className="text-2xl font-bold">Captive Portal CMS</h1>
  190. <p className="text-sm text-blue-200">Local Administration</p>
  191. </div>
  192. <a href="/" target="_blank" className="bg-blue-800 hover:bg-blue-700 text-white px-4 py-2 rounded text-sm transition-colors">
  193. View Live Portal ↗
  194. </a>
  195. </div>
  196. </div>
  197. <div className="max-w-5xl mx-auto mt-8 px-4">
  198. {/* Tab Navigation */}
  199. <div className="flex space-x-2 mb-6">
  200. <button onClick={() => setActiveTab('cards')} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'cards' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}>
  201. Manage Cards
  202. </button>
  203. <button onClick={() => setActiveTab('settings')} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'settings' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}>
  204. Portal Settings
  205. </button>
  206. </div>
  207. <div className="bg-white rounded-b-xl rounded-tr-xl shadow-sm border border-gray-200 overflow-hidden min-h-[500px]">
  208. {/* TAB: CARDS */}
  209. {activeTab === 'cards' && (
  210. <div className="p-6 md:p-8">
  211. <div className="flex justify-between items-center mb-8 border-b pb-4">
  212. <h2 className="text-xl font-bold text-gray-800">Card Grid</h2>
  213. <button onClick={() => setIsEditing({ title: '', cardType: 'INFO_PAGE', displayOrder: cards.length })} className="bg-blue-600 text-white px-5 py-2.5 rounded-lg shadow-sm hover:bg-blue-700 font-medium">
  214. + Add New Card
  215. </button>
  216. </div>
  217. <div className="space-y-3 mb-8">
  218. {cards.length === 0 && <p className="text-gray-500 italic text-center py-8">No cards available. Create one to get started.</p>}
  219. {cards.map((card, idx) => (
  220. // CHANGED: flex-col on mobile, flex-row on sm+, added gap-4 for mobile spacing
  221. <div key={card.id} className="flex flex-col sm:flex-row sm:items-center justify-between p-4 border rounded-lg bg-gray-50 hover:bg-gray-100 transition-colors gap-4">
  222. <div className="flex items-center gap-4">
  223. {card.imageUrl ? <img src={card.imageUrl} className="w-16 h-16 object-cover rounded-md shadow-sm shrink-0" alt="" /> : <div className="w-16 h-16 bg-gray-200 rounded-md shadow-sm flex items-center justify-center text-gray-400 text-xs shrink-0">No Image</div>}
  224. <div>
  225. <span className="font-semibold text-gray-800 block">{card.title}</span>
  226. <span className="text-xs text-gray-500 uppercase tracking-wider">{card.cardType}</span>
  227. </div>
  228. </div>
  229. {/* CHANGED: flex-wrap to ensure buttons don't overflow on small screens, w-full on mobile */}
  230. <div className="flex flex-wrap items-center gap-2 w-full sm:w-auto justify-end">
  231. <button onClick={() => moveCard(idx, 'up')} className="p-2 text-gray-500 hover:text-gray-800 hover:bg-gray-200 rounded" title="Move Up">↑</button>
  232. <button onClick={() => moveCard(idx, 'down')} className="p-2 text-gray-500 hover:text-gray-800 hover:bg-gray-200 rounded" title="Move Down">↓</button>
  233. <div className="w-px h-6 bg-gray-300 mx-1 hidden sm:block"></div>
  234. <button onClick={() => setIsEditing(card)} className="px-4 py-2 text-blue-600 hover:bg-blue-50 rounded font-medium">Edit</button>
  235. <button onClick={() => handleDeleteCard(card.id)} className="px-4 py-2 text-red-600 hover:bg-red-50 rounded font-medium">Delete</button>
  236. </div>
  237. </div>
  238. ))}
  239. </div>
  240. </div>
  241. )}
  242. {/* TAB: SETTINGS */}
  243. {activeTab === 'settings' && (
  244. <div className="p-6 md:p-8">
  245. <h2 className="text-xl font-bold text-gray-800 mb-8 border-b pb-4">Global Portal Settings</h2>
  246. <div className="grid grid-cols-1 md:grid-cols-2 gap-10">
  247. <div className="space-y-6">
  248. <div>
  249. <label className="block text-sm font-semibold text-gray-700 mb-1">Portal Title</label>
  250. <input type="text" value={portal.title || ''} onChange={e => setPortal({...portal, title: e.target.value})} className={inputClasses} />
  251. </div>
  252. <div>
  253. <label className="block text-sm font-semibold text-gray-700 mb-1">Welcome Text</label>
  254. <textarea value={portal.welcomeText || ''} onChange={e => setPortal({...portal, welcomeText: e.target.value})} className={`${inputClasses} h-32 resize-none`} />
  255. </div>
  256. <div className="flex gap-8">
  257. <div>
  258. <label className="block text-sm font-semibold text-gray-700 mb-1">Theme Color</label>
  259. <div className="flex items-center gap-4">
  260. <input type="color" value={portal.themeColor || '#1e3a8a'} onChange={e => setPortal({...portal, themeColor: e.target.value})} className="h-12 w-12 rounded cursor-pointer border-0 p-0" />
  261. <span className="text-gray-900 font-mono font-medium">{portal.themeColor || '#1e3a8a'}</span>
  262. </div>
  263. </div>
  264. {/* NEW: Max Columns Setting updated for 3 */}
  265. <div className="flex-1">
  266. <label className="block text-sm font-semibold text-gray-700 mb-1">Grid Max Columns: {portal.maxGridColumns || 5}</label>
  267. <input
  268. type="range"
  269. min="3"
  270. max="8"
  271. value={portal.maxGridColumns || 5}
  272. onChange={e => setPortal({...portal, maxGridColumns: parseInt(e.target.value)})}
  273. className="w-full mt-3 accent-blue-600"
  274. />
  275. <div className="flex justify-between text-xs text-gray-400 mt-1">
  276. <span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. <div className="space-y-6">
  282. {/* Logo Upload with Remove Button */}
  283. <div>
  284. <label className="block text-sm font-semibold text-gray-700 mb-1">Logo Image</label>
  285. <input type="file" accept="image/*" onChange={e => handleUpload(e, 'logoUrl', true)} className="block w-full text-sm text-gray-900 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:bg-gray-100 cursor-pointer" />
  286. {uploading['logoUrl'] && <span className="text-xs text-blue-500">Uploading...</span>}
  287. {portal.logoUrl && (
  288. <div className="mt-2 bg-gray-100 p-4 rounded inline-block relative border">
  289. <img src={portal.logoUrl} className="h-16 object-contain" alt="Logo Preview" />
  290. <button onClick={() => setPortal({...portal, logoUrl: ''})} className="absolute -top-2 -right-2 bg-red-500 text-white w-6 h-6 rounded-full text-xs font-bold hover:bg-red-600 shadow">✕</button>
  291. </div>
  292. )}
  293. </div>
  294. {/* Hero Upload with Remove Button */}
  295. <div>
  296. <label className="block text-sm font-semibold text-gray-700 mb-1">Hero Background Image</label>
  297. <input type="file" accept="image/*" onChange={e => handleUpload(e, 'heroImageUrl', true)} className="block w-full text-sm text-gray-900 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:bg-gray-100 cursor-pointer" />
  298. {uploading['heroImageUrl'] && <span className="text-xs text-blue-500">Uploading...</span>}
  299. {portal.heroImageUrl && (
  300. <div className="mt-2 relative rounded shadow border inline-block w-full">
  301. <img src={portal.heroImageUrl} className="h-32 w-full object-cover rounded" alt="Hero Preview" />
  302. <button onClick={() => setPortal({...portal, heroImageUrl: ''})} className="absolute top-2 right-2 bg-red-500 text-white w-8 h-8 flex items-center justify-center rounded-full text-sm font-bold hover:bg-red-600 shadow-lg">✕</button>
  303. </div>
  304. )}
  305. </div>
  306. <div className="bg-gray-50 p-4 rounded-lg border border-gray-200">
  307. <label className="flex items-center gap-3 cursor-pointer">
  308. <input type="checkbox" checked={!!portal.fadeHeroImage} onChange={e => setPortal({...portal, fadeHeroImage: e.target.checked})} className="w-5 h-5 text-blue-600 rounded" />
  309. <div>
  310. <span className="block text-sm font-semibold text-gray-900">Fade Image into Background Color</span>
  311. <span className="block text-xs text-gray-600">Creates a smooth gradient from the top of the image into the solid theme color at the bottom.</span>
  312. </div>
  313. </label>
  314. </div>
  315. </div>
  316. </div>
  317. <div className="mt-10 pt-6 border-t border-gray-200 flex justify-end">
  318. <button onClick={handleSavePortal} disabled={savingPortal} className="bg-blue-600 text-white px-10 py-3 rounded-lg hover:bg-blue-700 font-bold shadow disabled:opacity-50 transition-colors">
  319. {savingPortal ? 'Saving...' : 'Save Portal Settings'}
  320. </button>
  321. </div>
  322. </div>
  323. )}
  324. </div>
  325. </div>
  326. {/* MODAL FOR EDITING/CREATING CARDS */}
  327. {isEditing && (
  328. <div
  329. className="fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm p-4 transition-opacity"
  330. onClick={() => setIsEditing(null)} // Click outside to close
  331. >
  332. <div
  333. className="bg-white rounded-2xl w-full max-w-3xl max-h-[90vh] overflow-y-auto shadow-2xl p-6 md:p-8 relative animate-in fade-in zoom-in-95 duration-200"
  334. onClick={(e) => e.stopPropagation()} // Prevent inside clicks from closing
  335. >
  336. <button
  337. onClick={() => setIsEditing(null)}
  338. className="absolute top-6 right-6 text-gray-400 hover:text-gray-900 bg-gray-100 hover:bg-gray-200 rounded-full w-8 h-8 flex items-center justify-center transition-colors"
  339. >
  340. </button>
  341. <h3 className="text-2xl font-bold mb-6 text-gray-900 border-b pb-4">
  342. {isEditing.id ? 'Edit Card' : 'Create New Card'}
  343. </h3>
  344. <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
  345. <div className="space-y-5">
  346. <div>
  347. <label className="block text-sm font-semibold text-gray-800 mb-1">Title</label>
  348. <input type="text" value={isEditing.title || ''} onChange={e => setIsEditing({...isEditing, title: e.target.value})} className={inputClasses} placeholder="e.g., Local History" />
  349. </div>
  350. <div>
  351. <label className="block text-sm font-semibold text-gray-800 mb-1">Card Type</label>
  352. <select value={isEditing.cardType || 'INFO_PAGE'} onChange={e => setIsEditing({...isEditing, cardType: e.target.value as any})} className={inputClasses}>
  353. <option value="INFO_PAGE">Info Page</option>
  354. <option value="IMAGE_GALLERY">Image Gallery</option>
  355. <option value="EXTERNAL_LINK">External Link</option>
  356. </select>
  357. </div>
  358. <div>
  359. <label className="block text-sm font-semibold text-gray-800 mb-1">Short Description</label>
  360. <textarea value={isEditing.shortDescription || ''} onChange={e => setIsEditing({...isEditing, shortDescription: e.target.value})} className={`${inputClasses} h-24 resize-none`} placeholder="Brief summary..." />
  361. </div>
  362. </div>
  363. <div className="space-y-5">
  364. {/* Cover Image */}
  365. <div>
  366. <label className="block text-sm font-semibold text-gray-800 mb-1">
  367. Cover Image <span className="text-gray-400 font-normal text-xs">(shown in grid)</span>
  368. </label>
  369. <div className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:bg-gray-50 transition-colors">
  370. <input type="file" accept="image/*" onChange={e => handleUpload(e, 'imageUrl')} className="block w-full text-sm text-gray-700 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100 cursor-pointer" />
  371. {uploading['imageUrl'] && <p className="mt-2 text-sm text-blue-600 font-medium">Uploading...</p>}
  372. </div>
  373. {isEditing.imageUrl && (
  374. <div className="mt-3 relative rounded-lg overflow-hidden border border-gray-200 group">
  375. <img src={isEditing.imageUrl} className="w-full h-32 object-cover" alt="Cover preview" />
  376. <button
  377. onClick={() => setIsEditing({...isEditing, imageUrl: ''})}
  378. className="absolute top-2 right-2 bg-red-500 text-white w-8 h-8 rounded-full text-sm font-bold shadow opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-600"
  379. title="Remove cover image"
  380. >✕</button>
  381. </div>
  382. )}
  383. </div>
  384. {/* Gallery Media (images + videos + PDFs) */}
  385. <div>
  386. <label className="block text-sm font-semibold text-gray-800 mb-1">
  387. Gallery Media <span className="text-gray-400 font-normal text-xs">(images, videos or PDFs — PDF pages become slides)</span>
  388. </label>
  389. <div className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:bg-gray-50 transition-colors">
  390. <input
  391. type="file"
  392. accept="image/*,video/*,application/pdf,.pdf"
  393. multiple
  394. onChange={handleUploadExtraMedia}
  395. className="block w-full text-sm text-gray-700 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-purple-50 file:text-purple-700 hover:file:bg-purple-100 cursor-pointer"
  396. />
  397. {uploading['extraMedia'] && !pdfProgress && <p className="mt-2 text-sm text-purple-600 font-medium">Uploading...</p>}
  398. {pdfProgress && (
  399. <p className="mt-2 text-sm text-purple-600 font-medium">
  400. Processing &ldquo;{pdfProgress.name}&rdquo;: page {pdfProgress.page} of {pdfProgress.total}
  401. </p>
  402. )}
  403. </div>
  404. {(isEditing.extraMedia || []).length > 0 && (
  405. <div className="mt-3 space-y-2">
  406. {(isEditing.extraMedia || []).map((item, i) => {
  407. const video = isVideoUrl(item.url);
  408. return (
  409. <div key={item.url + i} className="flex items-center gap-3 p-2 bg-gray-50 border border-gray-200 rounded-lg">
  410. <div className="relative w-16 h-16 rounded-md overflow-hidden bg-black shrink-0">
  411. {video ? (
  412. <>
  413. <video src={item.url} className="w-full h-full object-cover" muted preload="metadata" />
  414. <div className="absolute inset-0 flex items-center justify-center bg-black/30 text-white text-xl">▶</div>
  415. </>
  416. ) : (
  417. <img src={item.url} className="w-full h-full object-cover" alt="" />
  418. )}
  419. <span className="absolute bottom-0 left-0 right-0 text-center text-white text-[10px] bg-black/60">{i + 1}</span>
  420. </div>
  421. <div className="flex-1 min-w-0">
  422. <div className="text-xs font-semibold text-gray-700 uppercase tracking-wider">
  423. {video ? 'Video' : 'Image'}
  424. </div>
  425. {video && (
  426. <label className="flex items-center gap-2 mt-1 cursor-pointer">
  427. <input
  428. type="checkbox"
  429. checked={!!item.autoplay}
  430. onChange={() => toggleAutoplay(i)}
  431. className="w-4 h-4 text-blue-600 rounded"
  432. />
  433. <span className="text-sm text-gray-700">Autoplay (muted)</span>
  434. </label>
  435. )}
  436. </div>
  437. <button
  438. onClick={() => removeExtraMedia(i)}
  439. className="bg-red-500 hover:bg-red-600 text-white w-8 h-8 rounded-full text-sm font-bold shrink-0"
  440. title="Remove"
  441. >✕</button>
  442. </div>
  443. );
  444. })}
  445. </div>
  446. )}
  447. </div>
  448. </div>
  449. </div>
  450. <div className="flex gap-3 pt-8 mt-6 border-t border-gray-200 justify-end">
  451. <button onClick={() => setIsEditing(null)} className="px-5 py-2.5 text-gray-700 hover:bg-gray-100 rounded-lg font-medium transition-colors">
  452. Cancel
  453. </button>
  454. <button onClick={handleSaveCard} className="bg-green-600 text-white px-8 py-2.5 rounded-lg hover:bg-green-700 font-medium shadow-sm transition-colors">
  455. Save Card
  456. </button>
  457. </div>
  458. </div>
  459. </div>
  460. )}
  461. {/* CUSTOM CONFIRM DIALOG */}
  462. {confirmDialog && (
  463. <div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in duration-200">
  464. <div className="bg-white rounded-xl shadow-2xl p-6 max-w-sm w-full animate-in zoom-in-95">
  465. <h3 className="text-xl font-bold text-gray-900 mb-2">Confirm Action</h3>
  466. <p className="text-gray-600 mb-6 leading-relaxed">{confirmDialog.message}</p>
  467. <div className="flex justify-end gap-3">
  468. <button
  469. onClick={() => setConfirmDialog(null)}
  470. className="px-4 py-2.5 text-gray-700 hover:bg-gray-100 rounded-lg font-medium transition-colors"
  471. >
  472. Cancel
  473. </button>
  474. <button
  475. onClick={confirmDialog.onConfirm}
  476. className="px-6 py-2.5 bg-red-600 text-white rounded-lg hover:bg-red-700 font-medium transition-colors shadow-sm"
  477. >
  478. Delete
  479. </button>
  480. </div>
  481. </div>
  482. </div>
  483. )}
  484. {/* CUSTOM TOAST NOTIFICATION */}
  485. {toast && (
  486. <div className="fixed bottom-6 right-6 z-[70] bg-gray-900 text-white px-6 py-4 rounded-lg shadow-2xl flex items-center gap-3 animate-in slide-in-from-bottom-5 fade-in duration-300">
  487. <div className="w-6 h-6 bg-green-500 rounded-full flex items-center justify-center text-gray-900 font-bold text-sm">
  488. </div>
  489. <span className="font-medium">{toast}</span>
  490. </div>
  491. )}
  492. </div>
  493. );
  494. }