import{u as p}from"./useProjectionStream-ayb6RvWW.js";import{bp as m,bo as f,Y as l}from"./index-D5GfLbIx.js";import{b as d}from"./mapEdit-BXIATxCI.js";import{r as i}from"./reflection-BwOBPyb9.js";function N(t){const e=p({autoConnect:!1});function a(r){const n=r?.payload;if(n)switch(r.kind){case"alarm":t.onAlarm?.(n);break;case"object-created":t.onObjectCreated?.(n);break;case"object-deleted":t.onObjectDeleted?.(n);break;case"object-patched":t.onObjectPatched?.(n);break;case"object-batch-changed":t.onObjectBatchChanged?.(n);break;case"pick-result":t.onPickResult?.(n);break;case"selection-detail":t.onSelectionDetail?.(n);break;case"workspace-shortcut":t.onWorkspaceShortcut?.(n);break;case"viewport-style-updated":t.onViewportStyleUpdated?.();break}}return m(()=>{e.on(a),e.connect()}),f(()=>{e.off(a),e.disconnect()}),{connected:e.connected}}function u(t=new Date){const e=a=>String(a).padStart(2,"0");return`${t.getFullYear()}${e(t.getMonth()+1)}${e(t.getDate())}_${e(t.getHours())}${e(t.getMinutes())}${e(t.getSeconds())}`}function b(t,e=new Date){const a=t.trim();return a?`${a}_${u(e)}`:u(e)}function h(t){const e=t.replace(/\\/g,"/"),a=e.slice(e.lastIndexOf("/")+1),r=a.lastIndexOf(".");return r>=0?a.slice(0,r):a}function j(t,e,a=".json"){const r=t.replace(/\\/g,"/"),n=r.lastIndexOf("/"),c=t.includes("\\")?"\\":"/",o=n>=0?r.slice(0,n).replace(/\//g,c):"",s=`${e}${a}`;return o?`${o}${c}${s}`:s}async function w(){try{const t=await i.getProjectFields();if(t.lastLoadedPath?.trim())return t.lastLoadedPath.trim();if(t.autoloadPath?.trim())return t.autoloadPath.trim()}catch{}return null}async function v(){try{const t=await d.list(),e=t.maps.find(a=>a.isCurrent);if(e?.name?.trim())return e.name.trim();if(t.currentFileName?.trim())return t.currentFileName.replace(/\.json$/i,"").trim()}catch{}return""}const g=/^[^\\/:*?"<>|]+$/;async function x(){try{return await l.confirm(`是否保存成新项目？

· 否，在原项目基础上保存：名称不变，直接覆盖原文件
· 是，保存成新项目：在服务器另存（默认名称含修改日期）`,"保存确认",{confirmButtonText:"是，保存成新项目",cancelButtonText:"否，在原项目基础上保存",distinguishCancelAndClose:!0,type:"info"}),"new"}catch(t){return t==="cancel"?"replace":"cancel"}}async function P(t,e){try{return((await l.prompt(`请输入${t}名称`,t,{inputValue:b(e),inputPattern:g,inputErrorMessage:'名称不能包含 \\ / : * ? " < > | 等字符',confirmButtonText:"保存到服务器",cancelButtonText:"取消"})).value??"").trim()||null}catch{return null}}async function B(t){if(t==="cancel")return null;if(t==="replace")return(await i.saveProject()).path;const e=await w(),a=e?h(e):"project",r=await P("保存成新项目",a);if(!r)return null;const n=e?j(e,r):`${r}.json`;return(await i.saveProject(n)).path}export{x as a,B as e,P as p,v as r,N as u};
