// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later // @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{A as t,Fr as n,_n as r,fr as i,ir as a,jr as o,oi as s,qi as c}from"./lucide-icons-BdRF0moN.js";import{t as l}from"./jsx-runtime-By8HlURe.js";import{t as u}from"./dist-DQ82bf9M.js";import{u as d}from"./esm-CRVqHnq2.js";import{t as f}from"./useQuery-rCAlChE8.js";import{t as p}from"./useAppContext-Ughdk2-Z.js";import{r as m}from"./sanitizeUrl-Bk5f35GN.js";import{t as h}from"./downloadFile-kpATXaJi.js";import{l as g,o as _,t as v}from"./useCurrentUser-C6OJJlWo.js";import{t as y}from"./utils-BFSTDHdM.js";import{t as b}from"./button-Cs26nq0r.js";import{t as ee}from"./useNostrPublish-CrMjnYm4.js";import{t as te}from"./nostrId-DuqQCAdJ.js";import{n as x}from"./useFollowActions-cve70R08.js";import{n as ne,r as S,t as re}from"./avatar--oX_CTF4.js";import{c as C,n as w,u as ie}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as T}from"./input-CM5Fnyvy.js";import{t as E}from"./skeleton-CVls4GW9.js";import{r as D}from"./safeNip19-CtQLwPmS.js";import{a as O,c as k,i as A,n as j,r as M,t as N}from"./dialog-C3CFmras.js";import{t as ae}from"./getDisplayName-B6lnEGRj.js";import{_ as P,a as F,c as oe,d as se,f as I,g as L,h as R,i as z,l as B,m as ce,n as le,o as ue,p as V,s as H,t as U,u as de}from"./memorycard-BpAZd6ha.js";import{s as fe}from"./extraKinds-BydAXtVV.js";import{g as pe}from"./sidebarItems-BFr7FKBa.js";import{c as me}from"./LayoutContext-CjQBLGO-.js";import{t as he}from"./SubHeaderBar-BYwNp4Nc.js";import{t as W}from"./label-BBIj2Nkw.js";import{o as G,w as ge,x as K}from"./index-CYEZWNq6.js";import{t as _e}from"./PageHeader-CMi4aeE4.js";import{t as ve}from"./KindInfoButton-BL9_-Fdi.js";var q=e(c(),1),J=8e3;function ye(e=`global`){let{nostr:t}=u(),{user:n}=v(),{data:r}=x(),i=r?.pubkeys,a=e===`global`||e===`mine`&&!!n||e===`follows`&&!!n&&i!==void 0;return f({queryKey:[`memory-cards`,`gallery`,e,n?.pubkey??``],enabled:a,queryFn:async({signal:r})=>{let a={kinds:[U],limit:600};if(e===`mine`&&n)a.authors=[n.pubkey];else if(e===`follows`&&n){let e=new Set(i??[]);e.add(n.pubkey),a.authors=[...e]}return oe(await t.query([a],{signal:AbortSignal.any([r,AbortSignal.timeout(J)])}))}})}function be(e,t){let{nostr:n}=u();return f({queryKey:[`memory-cards`,`card`,e??``,t??``],enabled:!!e,queryFn:async({signal:r})=>{if(!e)return null;let i={kinds:[U],authors:[e]};t&&(i[`#m`]=[t]);let a=await n.query([i],{signal:AbortSignal.any([r,AbortSignal.timeout(J)])});if(!a.length)return null;let o=new Map;for(let e of a){let t=ue(e)||`?`,n=o.get(t);n?n.push(e):o.set(t,[e])}let s=t??[...o.entries()].sort((e,t)=>t[1].length-e[1].length)[0][0];return{cardId:s,blocks:de(o.get(s)??[]),cardIds:[...o.keys()]}}})}function Y(){let{user:e}=v(),{mutateAsync:t}=ee(),n=(0,q.useCallback)(async(e,n,r)=>{await t({kind:U,content:e.content,tags:I(e,n,r)})},[t]),r=(0,q.useCallback)(async(e,n)=>{let r=Object.keys(e).map(Number).sort((e,t)=>e-t);for(let i of r)await t({kind:U,content:e[i].content,tags:I(e[i],n,i)});return r.length},[t]),i=(0,q.useCallback)(async(e,n,r)=>{let i=se(n);if(!i)throw Error(`Not a valid PlayStation memory card image (needs a 128 KB "MC" header).`);let a=r?.trim()||void 0;await t({kind:U,content:F(i.header),tags:z(e,0,i.header,{state:`header`,name:a})});for(let n of i.blocks)await t({kind:U,content:F(n.bytes),tags:z(e,n.index,n.bytes,{state:n.state,name:a,filename:n.filename,region:n.region,title:n.title})});return i.blocks.length+1},[t]),a=(0,q.useCallback)(async(e,t)=>{let{image:n,present:r,hasHeader:i}=V(t);return await h(`${e}.mcd`,n),{present:r,hasHeader:i}},[]),o=(0,q.useCallback)(async(e,t,n)=>{let r=le(n);if(!r)throw Error(`Block #${t} is not 8192 bytes`);await h(`${e}-block${t}.bin`,r)},[]);return{canManage:!!e,myPubkey:e?.pubkey,publishBlock:n,cloneCard:r,uploadCard:i,downloadCard:a,downloadBlock:o}}var X=l(),xe=fe(`cards`);function Se(e){if(e){try{let t=d.decode(e);if(t.type===`npub`)return t.data;if(t.type===`nprofile`)return t.data.pubkey}catch{}return te(e)?e:void 0}}function Z({pubkey:e,size:t=`sm`}){let n=g(e).data?.metadata,r=ae(n,e),i=D(e),a=(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,X.jsxs)(re,{className:t===`md`?`size-8`:`size-5`,children:[n?.picture&&(0,X.jsx)(S,{src:m(n.picture),alt:``}),(0,X.jsx)(ne,{className:`text-[10px]`,children:r[0]?.toUpperCase()??`?`})]}),(0,X.jsx)(`span`,{className:`truncate text-sm text-muted-foreground`,children:r})]});return i?(0,X.jsx)(w,{to:`/${i}`,className:`min-w-0 hover:underline`,onClick:e=>e.stopPropagation(),children:a}):a}function Ce({index:e,event:t}){let n=(0,q.useMemo)(()=>{if(!t)return null;try{return H(B(t.content))}catch{return null}},[t]);if(n)return(0,X.jsx)(P,{frames:n.frames,size:30,className:`rounded-[3px] border-white/15 shadow-[0_0_6px_rgba(80,180,255,0.25)]`});let r=!!t;return(0,X.jsxs)(`div`,{"aria-hidden":!0,className:y(`flex size-[30px] shrink-0 items-center justify-center rounded-[3px] border`,r?`border-cyan-300/30 bg-cyan-300/10`:`border-dashed border-white/10 bg-white/[0.02]`),children:[r&&(0,X.jsx)(`div`,{className:`size-1.5 rounded-full bg-cyan-300/50`}),(0,X.jsxs)(`span`,{className:`sr-only`,children:[`Slot `,e]})]})}function we({card:e}){let t=D(e.pubkey),n=t?`/memory-cards/${t}/${encodeURIComponent(e.cardId)}`:`#`,r=e.blocks.size-+!!e.blocks.has(0);return(0,X.jsxs)(w,{to:n,className:`group block rounded-2xl border border-border bg-card p-3 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-slate-700/60 bg-gradient-to-b from-slate-800 to-slate-950 shadow-inner`,children:[(0,X.jsx)(`div`,{className:`flex h-2.5 items-stretch gap-[3px] bg-slate-900/80 px-3 py-[3px]`,children:Array.from({length:8}).map((e,t)=>(0,X.jsx)(`div`,{className:`flex-1 rounded-[1px] bg-gradient-to-b from-amber-300/80 to-amber-500/60`},t))}),(0,X.jsxs)(`div`,{className:`relative p-3`,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 opacity-40 mix-blend-overlay`,style:{backgroundImage:`repeating-linear-gradient(to bottom, rgba(255,255,255,0.08) 0px, rgba(255,255,255,0.08) 1px, transparent 1px, transparent 3px)`}}),(0,X.jsx)(`div`,{className:`relative grid grid-cols-5 justify-items-center gap-2`,children:Array.from({length:15},(e,t)=>t+1).map(t=>(0,X.jsx)(Ce,{index:t,event:e.slots[t]},t))})]})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 px-0.5`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`p`,{className:`truncate text-sm font-bold leading-tight`,children:[e.name?`${e.name} `:``,(0,X.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.cardId})]}),(0,X.jsx)(`div`,{className:`mt-0.5`,children:(0,X.jsx)(Z,{pubkey:e.pubkey})})]}),(0,X.jsxs)(`span`,{className:`shrink-0 rounded-md border border-border bg-muted px-2 py-1 font-mono text-[11px] font-semibold tabular-nums text-muted-foreground`,children:[r,`/15`]}),(0,X.jsx)(s,{className:`size-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]})]})}var Te={mine:`You haven’t published any memory cards yet. Clone a card or copy a save block to make one.`,follows:`None of the people you follow have shared a memory card yet. Try the Global tab.`,global:`No memory cards found on your relays yet. Cards are published as kind 38192 events — check back soon, or point Ditto at a relay that carries them.`};function Ee({tab:e}){let{data:n,isLoading:r,isPending:i}=ye(e),{uploadCard:a,myPubkey:o}=Y(),[s,c]=(0,q.useState)(!1),l=e===`mine`,u=r||i,d=l?(0,X.jsx)(`div`,{className:`mb-4 flex justify-end`,children:(0,X.jsxs)(b,{size:`sm`,onClick:()=>c(!0),children:[(0,X.jsx)(t,{className:`mr-1.5 size-4`}),`Upload / update card`]})}):null,f;if(u)f=(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:Array.from({length:4}).map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-2xl border border-border p-3`,children:[(0,X.jsx)(E,{className:`h-[132px] w-full rounded-xl`}),(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,X.jsx)(E,{className:`size-5 rounded-full`}),(0,X.jsx)(E,{className:`h-4 w-1/2`})]})]},t))});else if(!n||n.length===0)f=(0,X.jsx)(`div`,{className:`rounded-xl border border-dashed border-border py-12 px-8 text-center`,children:(0,X.jsx)(`p`,{className:`mx-auto max-w-sm text-muted-foreground`,children:Te[e]})});else{let e=new Set(n.map(e=>e.pubkey)).size;f=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`font-semibold text-foreground`,children:n.length}),` `,`card`,n.length===1?``:`s`,!l&&(0,X.jsxs)(X.Fragment,{children:[` `,`from`,` `,(0,X.jsx)(`span`,{className:`font-semibold text-foreground`,children:e}),` `,`author`,e===1?``:`s`]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:n.map(e=>(0,X.jsx)(we,{card:e},`${e.pubkey}|${e.cardId}`))})]})}return(0,X.jsxs)(X.Fragment,{children:[d,f,s&&(0,X.jsx)(De,{existingIds:n?.map(e=>e.cardId)??[],myPubkey:o,uploadCard:a,onClose:()=>c(!1)})]})}function De({existingIds:e,myPubkey:t,uploadCard:n,onClose:i}){let a=C(),o=(0,q.useRef)(null),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(e[0]??`main`),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(!1);return(0,X.jsx)(N,{open:!0,onOpenChange:e=>!e&&i(),children:(0,X.jsxs)(j,{className:`sm:max-w-md`,children:[(0,X.jsxs)(O,{children:[(0,X.jsx)(k,{children:`Upload or update a memory card`}),(0,X.jsx)(M,{children:"Pick a PlayStation 1 memory card image (128 KB `.mcd` / `.mcr` / `.bin`). Its header and every occupied save block are published under your key. Your signer prompts once per block. Choosing an existing card id updates that card."})]}),(0,X.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(W,{htmlFor:`mc-upload-file`,children:`Memory card file`}),(0,X.jsx)(`input`,{ref:o,id:`mc-upload-file`,type:`file`,accept:`.mcd,.mcr,.bin,.gme,.mem,.vgs,.ps,.psm,application/octet-stream`,onChange:e=>c(e.target.files?.[0]??null),className:`block w-full text-sm text-muted-foreground file:mr-3 file:rounded-md file:border file:border-input file:bg-secondary file:px-3 file:py-1.5 file:text-sm file:font-medium hover:file:bg-secondary/80`})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(W,{htmlFor:`mc-upload-card`,children:`Card id`}),(0,X.jsx)(T,{id:`mc-upload-card`,value:l,onChange:e=>u(e.target.value),placeholder:`e.g. main`,autoComplete:`off`,list:`mc-upload-card-ids`}),e.length>0&&(0,X.jsx)(`datalist`,{id:`mc-upload-card-ids`,children:e.map(e=>(0,X.jsx)(`option`,{value:e},e))})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(W,{htmlFor:`mc-upload-name`,children:`Card name (optional)`}),(0,X.jsx)(T,{id:`mc-upload-name`,value:d,onChange:e=>f(e.target.value),placeholder:`e.g. My PSX Card`,autoComplete:`off`})]})]}),(0,X.jsxs)(A,{children:[(0,X.jsx)(b,{variant:`ghost`,onClick:i,disabled:p,children:`Cancel`}),(0,X.jsxs)(b,{onClick:async()=>{if(!s){_({title:`Choose a memory card file first.`,variant:`destructive`});return}let r=l.trim(),o=L(r);if(o){_({title:o,variant:`destructive`});return}m(!0);try{let o=await n(r,new Uint8Array(await s.arrayBuffer()),d);_({title:e.includes(r)?`Card updated`:`Card published`,description:`Published ${o} block${o===1?``:`s`} to “${r}”.`});let c=D(t??``);i(),c&&a(`/memory-cards/${c}/${encodeURIComponent(r)}`)}catch(e){_({title:`Upload failed`,description:String(e),variant:`destructive`})}finally{m(!1)}},disabled:p||!s,children:[p&&(0,X.jsx)(r,{className:`mr-1.5 size-4 animate-spin`}),e.includes(l.trim())?`Update card`:`Publish card`]})]})]})})}function Q({index:e,event:t,onCopy:r,onDownload:i}){let a=`inline-flex items-center gap-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-secondary`;return(0,X.jsxs)(`div`,{className:`mt-auto flex gap-1 pt-2 opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,children:[(0,X.jsxs)(`button`,{type:`button`,className:a,onClick:n=>{n.stopPropagation(),i(e,t)},children:[(0,X.jsx)(o,{className:`size-3`}),` .bin`]}),r&&(0,X.jsxs)(`button`,{type:`button`,className:a,onClick:n=>{n.stopPropagation(),r(e,t)},children:[(0,X.jsx)(n,{className:`size-3`}),` copy`]})]})}function Oe({index:e,event:t,onCopy:n,onDownload:r}){let i=(0,q.useMemo)(()=>{if(!t)return null;try{return H(B(t.content))}catch{return null}},[t]);if(!t)return(0,X.jsxs)(`div`,{className:`relative flex min-h-[132px] flex-col items-center justify-center rounded-xl border border-dashed border-border text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`absolute right-2.5 top-2 font-mono text-[11px] text-muted-foreground/70`,children:[`#`,e]}),(0,X.jsx)(`span`,{className:`text-2xl opacity-40`,children:`+`}),(0,X.jsx)(`span`,{className:`text-xs`,children:`free`})]});let a=R(t,`state`);if(a===`middle`||a===`last`||!i)return(0,X.jsxs)(`div`,{className:`group relative flex min-h-[132px] flex-col rounded-xl border border-border bg-secondary/20 p-3`,children:[(0,X.jsxs)(`span`,{className:`absolute right-2.5 top-2 font-mono text-[11px] text-muted-foreground/70`,children:[`#`,e]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`↳ continuation`}),r&&(0,X.jsx)(Q,{index:e,event:t,onCopy:n,onDownload:r})]});let o=R(t,`filename`),s=R(t,`region`),c=ce(s,o),l=i.title||R(t,`title`)||`(untitled save)`;return(0,X.jsxs)(`div`,{className:`group relative flex min-h-[132px] flex-col rounded-xl border border-border bg-card p-3`,children:[(0,X.jsxs)(`span`,{className:`absolute right-2.5 top-2 font-mono text-[11px] text-muted-foreground/70`,children:[`#`,e]}),(0,X.jsxs)(`div`,{className:`flex gap-2.5`,children:[(0,X.jsx)(P,{frames:i.frames,size:48}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 pr-4`,children:[(0,X.jsx)(`p`,{className:`line-clamp-3 break-words text-sm font-semibold leading-tight`,children:l}),o&&(0,X.jsx)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground`,children:o}),s&&(0,X.jsxs)(`span`,{className:`mt-1.5 inline-block rounded border border-border px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:[c?`${c} `:``,s]})]})]}),r&&(0,X.jsx)(Q,{index:e,event:t,onCopy:n,onDownload:r})]})}function ke({pubkey:e,cardId:t}){let{data:n,isLoading:r}=be(e,t);return r?(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 min-[420px]:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:9}).map((e,t)=>(0,X.jsx)(E,{className:`min-h-[132px] rounded-xl`},t))}):n?(0,X.jsx)(Ae,{pubkey:e,card:n}):(0,X.jsx)(`div`,{className:`rounded-xl border border-dashed border-border py-12 px-8 text-center`,children:(0,X.jsxs)(`p`,{className:`mx-auto max-w-sm text-muted-foreground`,children:[`No card found for this key`,t?` under card “${t}”`:``,`. It may not be published to your relays.`]})})}function Ae({pubkey:e,card:t}){let n=Object.keys(t.blocks).filter(e=>Number(e)>=1).length,r=!!t.blocks[0],{canManage:a,myPubkey:s,publishBlock:c,cloneCard:l,downloadCard:u,downloadBlock:d}=Y(),f=a&&s===e,[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(null),v=async()=>{try{let{present:e,hasHeader:n}=await u(t.cardId,t.blocks);_({title:`Downloaded ${t.cardId}.mcd`,description:n?`${e}/16 blocks written.`:`${e}/16 blocks — block 0 missing, so emulators may reject it.`})}catch(e){_({title:`Download failed`,description:String(e),variant:`destructive`})}},y=async(e,n)=>{try{await d(t.cardId,e,n)}catch(e){_({title:`Download failed`,description:String(e),variant:`destructive`})}};return(0,X.jsxs)(`div`,{className:`space-y-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 rounded-2xl border border-border bg-gradient-to-b from-secondary/40 to-card p-4`,children:[(0,X.jsxs)(`div`,{className:`flex h-16 w-24 shrink-0 items-center justify-center rounded-lg border border-border bg-muted text-[10px] font-bold tracking-wide text-muted-foreground`,children:[n,`/15`]}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-bold`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:t.cardId}),f&&(0,X.jsx)(`span`,{className:`rounded-full bg-primary/15 px-2 py-0.5 text-xs font-medium text-primary`,children:`your card`})]}),(0,X.jsx)(`div`,{className:`mt-1`,children:(0,X.jsx)(Z,{pubkey:e,size:`md`})}),(0,X.jsxs)(`div`,{className:`mt-2 max-w-xs`,children:[(0,X.jsx)(`div`,{className:`h-2 overflow-hidden rounded-full border border-border bg-background`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all`,style:{width:`${n/15*100}%`}})}),(0,X.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[n,` of 15 save blocks used`]})]})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(b,{variant:`outline`,size:`sm`,onClick:v,children:[(0,X.jsx)(o,{className:`mr-1.5 size-4`}),`Download .mcd`]}),a&&(0,X.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>m(!0),children:[(0,X.jsx)(i,{className:`mr-1.5 size-4`}),f?`Duplicate card`:`Clone to my card`]})]}),t.cardIds.length>1&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Other cards:`}),t.cardIds.filter(e=>e!==t.cardId).map(t=>{let n=D(e);return(0,X.jsx)(w,{to:n?`/memory-cards/${n}/${encodeURIComponent(t)}`:`#`,className:`rounded border border-border px-2 py-0.5 font-mono text-xs hover:bg-secondary`,children:t},t)})]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`🗂️`,` `,r?`System block 0: header and allocation table present.`:`System block 0 not published — emulators may reject a reconstructed image.`]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 min-[420px]:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:15},(e,t)=>t+1).map(e=>(0,X.jsx)(Oe,{index:e,event:t.blocks[e],onDownload:y,onCopy:a?(e,t)=>g({index:e,event:t}):void 0},e))}),p&&(0,X.jsx)(Me,{card:t,mine:f,myPubkey:s,cloneCard:l,onClose:()=>m(!1)}),h&&(0,X.jsx)(je,{source:h.event,defaultBlock:h.index,defaultCardId:f?t.cardId:`main`,myPubkey:s,publishBlock:c,onClose:()=>g(null)})]})}function je({source:e,defaultBlock:t,defaultCardId:n,myPubkey:i,publishBlock:a,onClose:o}){let s=C(),[c,l]=(0,q.useState)(n),[u,d]=(0,q.useState)(String(t)),[f,p]=(0,q.useState)(!1);return(0,X.jsx)(N,{open:!0,onOpenChange:e=>!e&&o(),children:(0,X.jsxs)(j,{className:`sm:max-w-md`,children:[(0,X.jsxs)(O,{children:[(0,X.jsx)(k,{children:`Copy save block to your card`}),(0,X.jsx)(M,{children:`Publishes this block under your key. The save bytes stay identical, so its integrity tag remains valid.`})]}),(0,X.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(W,{htmlFor:`mc-copy-card`,children:`Write to card id`}),(0,X.jsx)(T,{id:`mc-copy-card`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g. main`,autoComplete:`off`})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(W,{htmlFor:`mc-copy-block`,children:`Target block`}),(0,X.jsx)(`select`,{id:`mc-copy-block`,value:u,onChange:e=>d(e.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,children:Array.from({length:15},(e,t)=>t+1).map(e=>(0,X.jsxs)(`option`,{value:e,children:[`Block #`,e]},e))})]})]}),(0,X.jsxs)(A,{children:[(0,X.jsx)(b,{variant:`ghost`,onClick:o,disabled:f,children:`Cancel`}),(0,X.jsxs)(b,{onClick:async()=>{let t=c.trim(),n=L(t);if(n){_({title:n,variant:`destructive`});return}p(!0);try{await a(e,t,Number(u)),_({title:`Block copied`,description:`Published to “${t}” at block #${u}.`});let n=D(i??``);o(),n&&s(`/memory-cards/${n}/${encodeURIComponent(t)}`)}catch(e){_({title:`Copy failed`,description:String(e),variant:`destructive`})}finally{p(!1)}},disabled:f,children:[f&&(0,X.jsx)(r,{className:`mr-1.5 size-4 animate-spin`}),`Copy block`]})]})]})})}function Me({card:e,mine:t,myPubkey:n,cloneCard:i,onClose:a}){let o=C(),s=Object.keys(e.blocks).length,[c,l]=(0,q.useState)(t?`${e.cardId}-copy`:e.cardId),[u,d]=(0,q.useState)(!1);return(0,X.jsx)(N,{open:!0,onOpenChange:e=>!e&&a(),children:(0,X.jsxs)(j,{className:`sm:max-w-md`,children:[(0,X.jsxs)(O,{children:[(0,X.jsx)(k,{children:t?`Duplicate this card`:`Clone to your card`}),(0,X.jsxs)(M,{children:[`Re-publishes all `,s,` block`,s===1?``:`s`,` under your key. Your signer prompts once per block. Publishing to a card id you already use overwrites its blocks.`]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5 py-2`,children:[(0,X.jsx)(W,{htmlFor:`mc-clone-card`,children:`Write to card id`}),(0,X.jsx)(T,{id:`mc-clone-card`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g. main`,autoComplete:`off`})]}),(0,X.jsxs)(A,{children:[(0,X.jsx)(b,{variant:`ghost`,onClick:a,disabled:u,children:`Cancel`}),(0,X.jsxs)(b,{onClick:async()=>{let t=c.trim(),r=L(t);if(r){_({title:r,variant:`destructive`});return}d(!0);try{let r=await i(e.blocks,t);_({title:`Card cloned`,description:`Published ${r} block${r===1?``:`s`} to “${t}”.`});let s=D(n??``);a(),s&&o(`/memory-cards/${s}/${encodeURIComponent(t)}`)}catch(e){_({title:`Clone failed`,description:String(e),variant:`destructive`})}finally{d(!1)}},disabled:u,children:[u&&(0,X.jsx)(r,{className:`mr-1.5 size-4 animate-spin`}),`Publish ${s} block${s===1?``:`s`}`]})]})]})})}function $(){let{config:e}=p(),{user:t}=v(),{npub:n,cardId:r}=ie(),i=(0,q.useMemo)(()=>Se(n),[n]),o=r?decodeURIComponent(r):void 0,s=!!n,[c,l]=K(`memory-cards`,[`mine`,`follows`,`global`],`global`),u=t?c:`global`;return ge({title:`Memory Cards | ${e.appName}`,description:`PlayStation 1 memory cards shared over Nostr`}),me({showFAB:!1,hasSubHeader:!s}),(0,X.jsxs)(`main`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(_e,{title:`Memory Cards`,icon:pe(`cards`,`size-5`),backTo:s?`/memory-cards`:`/`,alwaysShowBack:s,children:(0,X.jsx)(ve,{kindDef:xe,icon:(0,X.jsx)(a,{className:`size-5`})})}),s?(0,X.jsx)(`div`,{className:`p-4`,children:i?(0,X.jsx)(ke,{pubkey:i,cardId:o}):(0,X.jsx)(`div`,{className:`rounded-xl border border-dashed border-border py-12 px-8 text-center`,children:(0,X.jsxs)(`p`,{className:`mx-auto max-w-sm text-muted-foreground`,children:[`That doesn’t look like a valid npub.`,` `,(0,X.jsx)(w,{to:`/memory-cards`,className:`text-primary hover:underline`,children:`Back to all cards`}),`.`]})})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(he,{children:[(0,X.jsx)(G,{label:`Mine`,active:u===`mine`,onClick:()=>l(`mine`),disabled:!t}),(0,X.jsx)(G,{label:`Follows`,active:u===`follows`,onClick:()=>l(`follows`),disabled:!t}),(0,X.jsx)(G,{label:`Global`,active:u===`global`,onClick:()=>l(`global`)})]}),(0,X.jsx)(`div`,{style:{height:20}}),(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(Ee,{tab:u})})]})]})}export{$ as MemoryCardsPage,$ as default}; // @license-end