import{ba as V,a4 as A,i as P,X as B,M as H,e as D,f as c,g as F,m as Q,n as R}from"./app-JmgyQoR0.js";import{b as X,a,c as $,D as y,h,i as b,j as d,l as U,K as z,E,z as J,H as K}from"./vue-y3KLWBaS.js";const L=X({__name:"share",setup(W){const i=new URLSearchParams(window.location.search),g=i.get("localOnly"),w=i.get("visibility");let p=a("fetching"),u=a(i.get("title"));const l=i.get("text"),_=i.get("url");let k=a(null),f=a(null),m=a(null),x=a(V.noteVisibilities.includes(w)?w:null),C=a(g==="0"?!1:g==="1"?!0:null),I=a([]),M=a([]);async function S(){let o="";if(u.value&&(o+=`[ ${u.value} ]
`),l!=null&&l.startsWith(`${u.value}.
`)?o+=l.replace(`${u.value}.
`,""):l&&u.value!==l&&(o+=`${l}
`),_&&(o+=`${_}`),k.value=o.trim(),x.value==="specified"){const t=i.get("visibleUserIds"),n=i.get("visibleAccts");await Promise.all([...t?t.split(",").map(e=>({userId:e})):[],...n?n.split(",").map(D.parse):[]].map(e=>"username"in e?{username:e.username,host:e.host===null?void 0:e.host}:e).map(e=>c("users/show",e).then(r=>{M.value.push(r)},()=>{console.error(`Invalid user query: ${JSON.stringify(e)}`)})))}try{const t=i.get("replyId"),n=i.get("replyUri");if(t)f.value=await c("notes/show",{noteId:t});else if(n){const s=await c("ap/show",{uri:n});s.type==="Note"&&(f.value=s.object)}const e=i.get("renoteId"),r=i.get("renoteUri");if(e)m.value=await c("notes/show",{noteId:e});else if(r){const s=await c("ap/show",{uri:r});s.type==="Note"&&(m.value=s.object)}const v=i.get("fileIds");v&&await Promise.all(v.split(",").map(s=>c("drive/files/show",{fileId:s}).then(O=>{I.value.push(O)},()=>{console.error(`Failed to fetch a file ${s}`)})))}catch(t){F({type:"error",title:t.message,text:t.name})}p.value="writing"}S();function N(){window.close(),window.setTimeout(()=>{Q.push("/")},100)}const j=$(()=>[]),T=$(()=>[]);return A({title:P.ts.share,icon:"ph-share-network ph-bold ph-lg"}),(o,t)=>{const n=y("MkPageHeader"),e=y("MkSpacer"),r=y("MkStickyContainer");return h(),b(r,null,{header:d(()=>[U(n,{actions:j.value,tabs:T.value},null,8,["actions","tabs"])]),default:d(()=>[U(e,{"content-max":800},{default:d(()=>[p.value==="writing"?(h(),b(B,{key:0,fixed:"",instant:!0,"initial-text":k.value,"initial-visibility":x.value,"initial-files":I.value,"initial-local-only":C.value,reply:f.value,renote:m.value,"initial-visible-users":M.value,class:"_panel",onPosted:t[0]||(t[0]=v=>p.value="posted")},null,8,["initial-text","initial-visibility","initial-files","initial-local-only","reply","renote","initial-visible-users"])):p.value==="posted"?(h(),b(H,{key:1,primary:"",class:"close",onClick:t[1]||(t[1]=v=>N())},{default:d(()=>[z(E(J(P).ts.close),1)]),_:1})):K("",!0)]),_:1})]),_:1})}}}),Z=R(L,[["__scopeId","data-v-59e7c306"]]);export{Z as default};
