Spaces:
Running
Running
File size: 5,702 Bytes
7c5da52 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | "use client";
import React from "react";
import { Info, X, Eye, Download, Edit3, Trash2, Share2 } from "lucide-react";
import { useCloud } from "@/context/CloudContext";
import { formatBytes } from "@/lib/api";
export function FileInspectorDrawer() {
const {
inspectedFile,
setInspectedFile,
getDownloadUrl,
setPreviewFile,
triggerDownload,
sharesMap,
setShareTarget,
canRename,
canDelete,
setRenameTarget,
setNewPathInput,
handleDeleteFile,
} = useCloud();
if (!inspectedFile) return null;
const fileShare = sharesMap[inspectedFile.path];
const pendingCount =
fileShare?.enabled && Array.isArray(fileShare.requests)
? fileShare.requests.filter((r) => r.status === "pending").length
: 0;
return (
<aside className="w-80 shrink-0 glass rounded-3xl p-5 border border-white/10 flex flex-col justify-between h-fit sticky top-24">
<div className="space-y-4">
<div className="flex items-center justify-between border-b border-white/10 pb-3">
<span className="text-xs font-bold uppercase tracking-wider text-indigo-300 flex items-center gap-1.5">
<Info className="w-4 h-4" /> Chi tiết Tệp tin
</span>
<button
onClick={() => setInspectedFile(null)}
className="p-1 rounded-lg hover:bg-white/10 text-slate-400"
>
<X className="w-4 h-4" />
</button>
</div>
{/* Mini Media Thumbnail if video or image */}
{inspectedFile.category === "video" ? (
<video
controls
src={getDownloadUrl(inspectedFile.path, true)}
className="w-full rounded-2xl bg-black border border-white/10 max-h-44"
/>
) : inspectedFile.category === "image" ? (
<img
src={getDownloadUrl(inspectedFile.path, true)}
alt={inspectedFile.name}
className="w-full rounded-2xl object-cover max-h-44 border border-white/10"
/>
) : null}
<div>
<h4 className="text-sm font-bold text-white break-all">{inspectedFile.name}</h4>
<p className="text-xs font-mono text-slate-400 mt-1 break-all">
cloud://thtuanit/{inspectedFile.path}
</p>
</div>
<div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/5 space-y-2 text-xs font-mono">
<div className="flex justify-between">
<span className="text-slate-400">Người sở hữu:</span>
<span className="text-indigo-300 font-bold">@{inspectedFile.owner}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-400">Dung lượng:</span>
<span className="text-white">{formatBytes(inspectedFile.size)}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-400">Bytes:</span>
<span className="text-slate-300">{inspectedFile.size.toLocaleString()}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-400">Cập nhật:</span>
<span className="text-slate-300">{inspectedFile.updatedAt || "N/A"}</span>
</div>
</div>
<div className="space-y-2 pt-2">
<button
onClick={() => setShareTarget(inspectedFile)}
className="w-full py-2.5 rounded-xl bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-500 hover:to-teal-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition shadow-lg shadow-emerald-600/20"
>
<Share2 className="w-4 h-4" />
<span>
{fileShare?.enabled
? pendingCount > 0
? `Quản lý Link Share (${pendingCount} chờ duyệt)`
: "Đang chia sẻ • Quản lý Link"
: "Chia sẻ nhanh qua Link"}
</span>
</button>
<button
onClick={() => setPreviewFile(inspectedFile)}
className="w-full py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition"
>
<Eye className="w-4 h-4" /> Mở Trình phát Toàn màn hình
</button>
<button
onClick={() => triggerDownload(inspectedFile)}
className="w-full py-2.5 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-semibold text-slate-200 flex items-center justify-center gap-2 transition"
>
<Download className="w-4 h-4" /> Tải tệp về máy
</button>
{canRename && (
<button
onClick={() => {
setRenameTarget(inspectedFile);
setNewPathInput(inspectedFile.path);
}}
className="w-full py-2.5 rounded-xl bg-amber-500/15 hover:bg-amber-500/25 border border-amber-500/30 text-xs font-semibold text-amber-300 flex items-center justify-center gap-2 transition"
>
<Edit3 className="w-4 h-4" /> Đổi tên / Di chuyển
</button>
)}
{canDelete && (
<button
onClick={() => handleDeleteFile(inspectedFile)}
className="w-full py-2.5 rounded-xl bg-rose-500/15 hover:bg-rose-500/25 border border-rose-500/30 text-xs font-semibold text-rose-300 flex items-center justify-center gap-2 transition"
>
<Trash2 className="w-4 h-4" /> Xóa khỏi Kho lưu trữ
</button>
)}
</div>
</div>
</aside>
);
}
|