// @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,Di as n,_n as r,qi as i}from"./lucide-icons-BdRF0moN.js";import{t as a}from"./jsx-runtime-By8HlURe.js";import{h as o}from"./useQuery-rCAlChE8.js";import{o as s,t as c}from"./useCurrentUser-C6OJJlWo.js";import{t as l}from"./button-Cs26nq0r.js";import{t as u}from"./useNostrPublish-CrMjnYm4.js";import{t as d}from"./useUploadFile-BpPXwoE0.js";import{d as f}from"./ComposeDialogContent-YxhSZA-Y.js";import{a as p,c as m,n as h,t as g}from"./dialog-C3CFmras.js";import{t as _}from"./textarea-B93xm6Zg.js";import{s as v}from"./extraKinds-BydAXtVV.js";import{g as y}from"./sidebarItems-BFr7FKBa.js";import{t as b}from"./label-BBIj2Nkw.js";import{t as x}from"./webxdcMeta-BE41E4P0.js";import{KindFeedPage as S}from"./KindFeedPage-lpUdiMxy.js";var C=e(i(),1),w=a();function T({open:e,onOpenChange:i}){let{user:a}=c(),{mutateAsync:v}=d(),{mutateAsync:y}=u(),S=o(),T=(0,C.useRef)(null),[E,D]=(0,C.useState)(null),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(),[M,N]=(0,C.useState)(),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(!1),R=(0,C.useCallback)(()=>{D(null),k(``),j(void 0),N(void 0),F(!1),L(!1)},[]),z=(0,C.useCallback)(e=>{e||R(),i(e)},[i,R]),B=(0,C.useCallback)(async e=>{let t=e.target.files?.[0];if(t){D(t),L(!0);try{let e=await x(t);if(j(e.name),e.iconFile)try{let[[,t]]=await v(e.iconFile);N(t)}catch{}}catch{}finally{L(!1)}}},[v]),V=(0,C.useCallback)(async()=>{if(!(!E||!a)){F(!0);try{let e=E.type?E:new File([E],E.name,{type:`application/x-webxdc`}),t=await v(e),[[,n]]=t;n.endsWith(`.xdc`)||(n+=`.xdc`);let r=[[`url`,n],[`m`,`application/x-webxdc`]],i=t.find(e=>e[0]===`x`);i&&r.push([`x`,i[1]]);let a=t.find(e=>e[0]===`ox`);a&&r.push([`ox`,a[1]]);let o=t.find(e=>e[0]===`size`);o&&r.push([`size`,o[1]]);let c=A?`Webxdc app: ${A}`:`Webxdc app`;r.push([`alt`,c]);let l=crypto.randomUUID();r.push([`webxdc`,l]),M&&r.push([`image`,M]);let u=await y({kind:1063,content:O||(A?`${A}`:``),tags:r,created_at:Math.floor(Date.now()/1e3)});s({title:`Published`,description:`${A??`Webxdc app`} shared successfully.`}),f(S,u),z(!1)}catch{s({title:`Publish failed`,description:`Could not publish the webxdc app.`,variant:`destructive`})}finally{F(!1)}}},[E,a,A,M,O,v,y,S,z]);return(0,w.jsx)(g,{open:e,onOpenChange:z,children:(0,w.jsxs)(h,{className:`max-w-md`,children:[(0,w.jsx)(p,{children:(0,w.jsxs)(m,{className:`flex items-center gap-2`,children:[(0,w.jsx)(n,{className:`size-5`}),`Share Webxdc App`]})}),(0,w.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(b,{children:`App file`}),E?(0,w.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-xl border border-border bg-muted/30`,children:[M?(0,w.jsx)(`img`,{src:M,alt:A??`App icon`,className:`size-10 rounded-xl object-cover`,decoding:`async`}):(0,w.jsx)(`div`,{className:`flex items-center justify-center size-10 rounded-xl bg-primary/10`,children:(0,w.jsx)(n,{className:`size-5 text-primary`})}),(0,w.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-sm font-medium truncate`,children:A??E.name}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I?`Reading metadata...`:E.name})]}),(0,w.jsx)(l,{variant:`ghost`,size:`sm`,className:`text-xs`,onClick:()=>{R(),T.current?.click()},children:`Change`})]}):(0,w.jsxs)(`button`,{type:`button`,onClick:()=>T.current?.click(),className:`w-full flex flex-col items-center gap-3 p-8 rounded-xl border-2 border-dashed border-border hover:border-primary/50 hover:bg-muted/30 transition-colors cursor-pointer`,children:[(0,w.jsx)(`div`,{className:`size-12 rounded-full bg-muted flex items-center justify-center`,children:(0,w.jsx)(t,{className:`size-5 text-muted-foreground`})}),(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(`p`,{className:`text-sm font-medium`,children:`Choose a .xdc file`}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Webxdc apps are sandboxed HTML5 archives`})]})]}),(0,w.jsx)(`input`,{ref:T,type:`file`,accept:`.xdc`,className:`hidden`,onChange:B})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(b,{htmlFor:`webxdc-description`,children:`Description`}),(0,w.jsx)(_,{id:`webxdc-description`,placeholder:`What does this app do?`,value:O,onChange:e=>k(e.target.value),rows:3,className:`resize-none`})]}),(0,w.jsx)(l,{onClick:V,disabled:!E||P||I,className:`w-full rounded-full`,children:P?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(r,{className:`size-4 animate-spin mr-2`}),`Publishing...`]}):`Publish`})]})]})})}var E=v(`webxdc`),D={"#m":[`application/x-webxdc`]};function O(){let[e,t]=(0,C.useState)(!1),n=(0,C.useCallback)(()=>{t(!0)},[]);return(0,w.jsx)(S,{kind:E.kind,title:E.label,icon:y(`webxdc`,`size-5`),tagFilters:D,onFabClick:n,emptyMessage:`No webxdc apps found yet. Check your relay connections or try again later.`,extra:(0,w.jsx)(T,{open:e,onOpenChange:t})})}export{O as WebxdcFeedPage};
// @license-end
