import { useState } from 'react' import { Check, Copy } from 'lucide-react' import { PLATFORMS, charLen, platformCopy, type PlatformKey } from '@/film/core/copy' import { quoteById } from '@/film/core/film' async function copyText(s: string) { try { await navigator.clipboard.writeText(s) return true } catch { const ta = document.createElement('textarea') ta.value = s ta.style.position = 'fixed' ta.style.opacity = '0' document.body.appendChild(ta) ta.select() const ok = document.execCommand('copy') ta.remove() return ok } } function CopyBtn({ text, label }: { text: string; label: string }) { const [ok, setOk] = useState(false) return ( { if (await copyText(text)) { setOk(true); setTimeout(() => setOk(false), 1400) } }} className={`flex items-center gap-1 rounded px-2 py-1 text-[11px] ring-1 transition ${ok ? 'bg-emerald-500/20 text-emerald-300 ring-emerald-500/40' : 'text-white/70 ring-white/15 hover:bg-white/5'}`} > {ok ? : }{ok ? '已复制' : label} ) } export default function CopyPanel({ id }: { id: number }) { const q = quoteById(id) const [tab, setTab] = useState('xhs') const p = PLATFORMS.find((x) => x.key === tab)! const c = platformCopy(id, q.text, tab) const tags = c.tags.map((t) => `#${t}`).join(' ') const tl = charLen(c.title) const all = `${c.title}\n\n${c.desc}\n\n${tags}` return ( {PLATFORMS.map((x) => ( setTab(x.key)} className={`rounded-md px-1 py-2 text-[12px] ring-1 transition ${tab === x.key ? 'bg-white/10 text-white ring-white/30' : 'text-white/55 ring-white/10 hover:text-white/80'}`}> {x.name} ))} 标题 p.titleMax ? 'text-red-400' : 'text-emerald-400'}>{tl}/{p.titleMax} 字 {c.title} 描述 {c.desc} 话题 {c.tags.length}{p.tagMax ? `/${p.tagMax}` : ' 个(不限)'} {c.tags.map((t) => #{t})} ) }
{c.title}
{c.desc}