import{j as e}from"./jsx-runtime-C5WNSv3b.js";import{r as y}from"./index-CqIc3cxq.js";import{L as P,f as N}from"./chunk-EPOLDU6W-BCLmut3y.js";import{s as O}from"./progress-bar-DpWhcyhC.js";import{c as x}from"./misc-W4055b-0.js";import{u as v}from"./pe-CIZUOJMr.js";import{b as _,a as I}from"./root-loader-BOzEMapJ.js";function E(r){const t=N();return y.useEffect(()=>{t.state==="idle"&&t.data!=null&&r?.("fetcher-done")},[t,r]),t}function L({className:r,file:t,appFile:a,appName:u,syncTo:n,line:o,column:c,children:l,onUpdate:s}){const i=E(s),h=v();if(!t&&!a)return console.error('LaunchEditor: requires either "file" or "appFile" prop.'),null;const d=typeof a=="string"?[a]:a,m=t?"file":"appFile",f=n?.file?"file":n?.appFile?"appFile":"";return e.jsxs(i.Form,{action:"/launch-editor",method:"POST",className:"flex items-center",children:[h,O,e.jsx("input",{type:"hidden",name:"line",value:typeof o=="number"?o:void 0}),e.jsx("input",{type:"hidden",name:"column",value:c}),e.jsx("input",{type:"hidden",name:"type",value:m}),e.jsx("input",{type:"hidden",name:"file",value:t}),e.jsx("input",{type:"hidden",name:"appName",value:u}),d?.map(p=>e.jsx("input",{type:"hidden",name:"appFile",value:p},p)),n?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"hidden",name:"syncTo.type",value:f}),e.jsx("input",{type:"hidden",name:"syncTo.file",value:n.file}),e.jsx("input",{type:"hidden",name:"syncTo.appName",value:n.appName}),e.jsx("input",{type:"hidden",name:"syncTo.appFile",value:n.appFile})]}):null,e.jsx("button",{type:"submit",className:x("launch_button",i.state==="idle"?null:"cursor-progress",i.data?.status==="error"?"cursor-not-allowed":null,r),children:l})]})}function g({className:r,file:t,appFile:a,appName:u,line:n,children:o}){const c=_(),l=I();if(Array.isArray(a))return e.jsx("div",{children:"Cannot open more than one file"});if(t){const p=j=>j.replace(/\\/g,"/"),b=ENV.EPICSHOP_GITHUB_ROOT.replace("/tree/","/blob/");return e.jsx("a",{className:"launch_button !no-underline",href:p(t).replace(p(ENV.EPICSHOP_CONTEXT_CWD),b)+(n?`#L${n}`:""),rel:"noreferrer",target:"_blank",children:o})}const s=c.find(p=>p.name===u),i=ENV.EPICSHOP_GITHUB_ROOT.replace("/tree/","/blob/"),[h,d]=a?a.split(","):["",""],m=n||(d?Number(d):void 0),f=[...s?.relativePath.split(l.separator)??[],h].join("/");return e.jsx("a",{className:x("launch_button !no-underline",r),href:`${i}/${f}${m?`#L${m}`:""}`,rel:"noreferrer",target:"_blank",children:o})}function S({appFile:r="README.mdx",appName:t,file:a,relativePath:u}){const n=E(),o=l=>{if(!l.altKey||ENV.EPICSHOP_DEPLOYED)return;l.preventDefault();const s=new FormData,i=a?"file":"appFile";s.append(i,a??r),s.append("type",i),t&&s.append("appName",t),n.submit(s,{method:"POST",action:"/launch-editor"})},c=ENV.EPICSHOP_GITHUB_ROOT.replace(/\/tree\/|\/blob\//,"/edit/");return e.jsxs(P,{className:"self-center font-mono text-sm",onClick:o,target:"_blank",to:`${c}/${u}`.replace(/\\/g,"/"),children:[e.jsx("span",{className:"@min-[720px]:hidden",children:"Edit"}),e.jsx("span",{className:"hidden @min-[720px]:block @min-[900px]:hidden",children:"Edit on GitHub"}),e.jsx("span",{className:"hidden @min-[900px]:block",children:"Edit this page on GitHub"})]})}const G=ENV.EPICSHOP_DEPLOYED?g:L;export{S as E,G as L};
//# sourceMappingURL=launch-editor-D2exGfVu.js.map
