var J=Object.create;var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames,D=Object.getOwnPropertySymbols,B=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var M=(e,o,s)=>o in e?v(e,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[o]=s,m=(e,o)=>{for(var s in o||(o={}))E.call(o,s)&&M(e,s,o[s]);if(D)for(var s of D(o))Q.call(o,s)&&M(e,s,o[s]);return e};var W=e=>v(e,"__esModule",{value:!0});var X=(e,o)=>{W(e);for(var s in o)v(e,s,{get:o[s],enumerable:!0})},Y=(e,o,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of V(o))!E.call(e,a)&&a!=="default"&&v(e,a,{get:()=>o[a],enumerable:!(s=G(o,a))||s.enumerable});return e},l=e=>Y(W(v(e!=null?J(B(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);X(exports,{activate:()=>se,deactivate:()=>ae});var n=l(require("vscode")),U=l(require("child_process")),x=l(require("fs")),N=l(require("fs/promises"));var c=l(require("vscode")),b=l(require("path")),Z=(e,o,s="web")=>{let a=i=>o.webview.asWebviewUri(c.Uri.file(b.join(e.extensionPath,s,"dist",i)));return`
    <html>
      <head>
        <meta charset="utf-8" />
        <meta
          name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
        />
        <link rel="stylesheet" href="${a("umi.css")}" />
        <style>
          html, body, #root {
            background-color: var(--vscode-editor-background);
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
          }
          // \u7ED9 webview \u5185\u5BB9\u52A0\u4E0A\u4E3B\u9898
          body.vscode-light {
            color: black;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-light h1, h2, h3, h4, h5, h6 {
            color: black;
          }
          body.vscode-dark {
            color: white;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-dark h1, h2, h3, h4, h5, h6 {
            color: white;
          }
          body.vscode-high-contrast {
            color: red;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-high-contrast h1, h2, h3, h4, h5, h6 {
            color: red;
          }
        </style>
        <script>
          window.vscodeEnv = ${JSON.stringify({language:c.env.language})}
        <\/script>
      </head>
      <body>
        <div id="root"></div>
        <script src="${a("umi.js")}"><\/script>
      </body>
    </html>
  `},r,$=(e,o,s,a)=>{let i=c.window.activeTextEditor?c.window.activeTextEditor.viewColumn:void 0;return r?r.reveal(i):(r=c.window.createWebviewPanel(o,s,c.ViewColumn.One,{enableScripts:!0,localResourceRoots:[c.Uri.file(b.join(e.extensionPath,"web/dist"))],retainContextWhenHidden:!0}),r.iconPath=c.Uri.file(b.join(e.extensionPath,a)),r.webview.html=Z(e,r)),r.onDidDispose(()=>{r=void 0},null,e.subscriptions),r};var A=l(require("vscode")),K,p=((K=A.extensions.getExtension("CloudStudio.common"))==null?void 0:K.exports)||{};var R=l(require("vscode")),y="",ee=async()=>{let e=await R.commands.executeCommand("cloudstudio.getBrowserUrl");return new URL(e)},g=async()=>y||(y=(await ee()).pathname.split("/")[2],y);var S=async()=>{let e=await p.getAxiosInstance(),o=await g(),{data:s}=await e.get(`/api/customize/templates/?spaceKey=${o}`);if(s.code===0)return s.data;console.log("data",s)};async function O(){let e=await p.getAxiosInstance(),o=await g(),{data:s}=await e.get(`/api/customize/templates/presets?spaceKey=${o}`);if(s.code===0)return s.data;console.log("data",s)}var F=async e=>{let o=await p.getAxiosInstance(),s=await g();return(await o.post("/api/customize/templates",m({source:s},e))).data},H=async e=>{let o=await p.getAxiosInstance(),s=await g(),a=m({},e);return delete a.id,console.log("\u66F4\u65B0\u6A21\u677F\u53C2\u6570",a),(await o.put(`/api/customize/templates/${e.id}`,m({source:s},a))).data};var t,k,j=x.realpathSync(n.workspace.workspaceFolders[0].uri.fsPath),te=x.existsSync(`${n.workspace.workspaceFolders[0].uri.fsPath}/.git`),oe=()=>{if(te)try{k=U.execSync('([ "$(git remote | wc -l)" -eq "1" ] && (git remote |xargs git remote get-url)) || (git remote get-url origin 2> /dev/null)',{cwd:j}).toString(),console.log("gitUrl",k)}catch(e){console.log("\u8BF7\u5148\u8FDB\u5165\u9879\u76EE\u6587\u4EF6\u5939\u518D\u53D1\u5E03"),console.log("output",e)}};async function se(e){if(!p.isCloudStudio)return;oe();let o=await n.commands.executeCommand("cloudstudio.getPublicConfig");t&&n.commands.executeCommand("custom-template.start");function s(i,u){let{callbackId:h}=u,T=m({callbackId:h},i);t==null||t.webview.postMessage(T)}e.subscriptions.push(n.commands.registerCommand("custom-template.start",async()=>{if(t)return t.reveal(n.ViewColumn.Active);t=$(e,"custom-template","\u81EA\u5B9A\u4E49\u6A21\u677F","assets/favicon.ico"),t.webview.onDidReceiveMessage(async i=>{var u,h;switch(i.type){case"deploy":case"reissue":if((await p.getUserInfo()).authenticationUserInfo.userName==="experience-user")t==null||t.webview.postMessage({event:"experience-user"});else{let w=U.execSync("du -s .",{cwd:j}).toString().replace(/\./g,"");t==null||t.webview.postMessage({memory:w});let f=i.params,d;i.type==="deploy"?d=await F(f):d=await H(f),t==null||t.webview.postMessage({reqData:d,event:i.type})}break;case"get template":let L=await O(),P=await S();t==null||t.webview.postMessage({iconsTagsData:L,templateData:P}),o&&(t==null||t.webview.postMessage({config:o})),k&&(t==null||t.webview.postMessage({gitUrl:k}));break;case"getPath":let C=await n.window.showOpenDialog({defaultUri:n.Uri.file(z()),canSelectFolders:!0,canSelectFiles:!1});s({result:(u=C==null?void 0:C[0])==null?void 0:u.path},i);break;case"getDefaultPath":let I=((h=process.env.IDE_SNAPSHOT_PATH)!=null?h:"").split(",");Promise.allSettled(I.map(w=>(0,N.stat)(w))).then(w=>{let f=w.map((d,q)=>d.status==="fulfilled"&&d.value.isDirectory()?I[q]:!1).filter(d=>d!==!1);s({result:{defaultPath:z(),snapshotPath:f}},i)});break;default:let _=await S();t==null||t.webview.postMessage({data:_});break}},void 0,e.subscriptions),t.onDidDispose(()=>{t=void 0},void 0,e.subscriptions)}));let a=n.commands.registerCommand("template.messageHandler",i=>{let u=JSON.parse(JSON.stringify(i));t==null||t.webview.postMessage(m({},u))});e.subscriptions.push(a)}function ae(){t==null||t.dispose(),t=void 0}var z=()=>{let{workspaceFolders:e}=n.workspace;return e&&e.length>0?e[0].uri.path:""};0&&(module.exports={activate,deactivate});
