import{Ct as e,E as t,Tt as n}from"./vue-vendor-DMUmTARL.js";import{I as r,Y as i,v as a,vt as o,yt as s}from"./index-BcZTP2Ia.js";import{n as c}from"./file-data-uFMtP6Ff.js";import{t as l}from"./useFileLoading-BrkxqmY6.js";import{t as u}from"./useFilePwd-ydEI5tjE.js";import{c as d,o as f,s as p,u as m}from"./share-CRJ09TKV.js";var h,{routerRef:g,routeRef:_}=o(),v=(e,t=``)=>Array.isArray(e)?e.length>0?String(e[0]||t):t:e==null?t:String(e),y=e=>v(e,`/`)||`/`,b=e=>e.response?.data||{};function x(){if(h)return h;let o=t(()=>v(_.value?.params?.shareKey,``)),x=n(null),S=n(!1),C=n(``),w=n(`/`),T=n(void 0),E=n(!1),D=n(``),O=e({orderBy:``,orderDirection:``}),k=c(),{getSharePathPwd:A,popPassword:j,putSharePathPwd:M}=u(),N=s(),{loading:P,firstLoading:F}=l(),I=e=>e?.storageKey||e?.shareLinkInfo?.storageKey||``,L=e=>{let t=I(e);return t?(N.updateShareRuntime({shareKey:String(o.value||``),storageKey:t}),console.info(`[share] 分享运行态 storageKey 已固化`,{shareKey:o.value,storageKey:t}),!0):(console.warn(`[share] 分享信息缺少 storageKey，清理分享运行态`,{shareKey:o.value}),N.clearShareRuntime(),!1)},R=()=>v(x.value?.sharePath||x.value?.shareLinkInfo?.sharePath,`/`),z=(e=`manual-clear`)=>{(N.shareRuntime.shareKey||N.shareRuntime.storageKey)&&console.info(`[share] 清理分享运行态 storageKey`,{reason:e,shareKey:N.shareRuntime.shareKey}),N.clearShareRuntime()},B=(e={})=>{let t=g.value,n=_.value;if(!t||!n)return;let r=`/share/${encodeURIComponent(o.value)}`,i={...n.query||{},...e};t.push({path:r,query:i})},V=e=>{let t=(e||`/`).split(`/`).filter(Boolean);t.pop();let n=`/`+t.join(`/`);return n===`//`?`/`:n||`/`},H=e=>{let t=T.value&&T.value!==e?T.value:V(e||`/`);y(_.value?.query?.path)!==t&&B({path:t})},U=async e=>!!(await m({shareKey:o.value,password:e})).data,W=(e,t)=>A(o.value,e,R(),t),G=async(e=`/`,t,n)=>{let s=a();P.value=!0;try{let i=e||`/`,a=R(),s=t||A(o.value,i,a,!0),c=await p({shareKey:o.value,path:i,password:C.value,folderPassword:s,orderBy:O.orderBy||N.globalConfig.defaultSortField||`name`,orderDirection:O.orderDirection||N.globalConfig.defaultSortOrder||`asc`});if(s){let e=c.data.passwordPattern||r(`/`,a,i,`/`);M(o.value,e,s,n)}let l=(c.data.fileItemList||[]).map(e=>{if(e.type===`FILE`){let t=e.path?e.path.endsWith(`/`)?e.path+e.name:e.path+`/`+e.name:e.name;return{...e,url:f(o.value,t,C.value)}}return e}),u=c.data.currentPath||e||`/`;if(w.value=u,T.value=u,u!==`/`){let e=c.data.parentPath||V(u);l=[{name:e===`/`?`/`:e.split(`/`).filter(Boolean).pop()||`/`,path:e,type:`BACK`},...l]}k.updateFileList(l),N.updateFolderConfig({...N.folderConfig,permission:c.data.permission||{}}),P.value=!1,F.value=!0,c.data.shareLinkInfo&&(x.value=c.data.shareLinkInfo,L(c.data.shareLinkInfo))}catch(t){P.value=!1;let n=b(t);if(n.code===i.responseCode.INVALID_PASSWORD||n.code===i.responseCode.REQUIRED_PASSWORD){let t=n.code===i.responseCode.INVALID_PASSWORD;j({title:t?`密码错误`:`提示`,message:t?`文件夹密码错误，请重新输入：`:`此文件夹已加密，请输入密码：`,defaultValue:A(o.value,e,R(),!0),initialInputErrorMessage:t?`密码错误，请重新输入`:``}).then(async({value:t,checkbox:n})=>{await G(e,t,!!n)}).catch(()=>{H(e)})}else console.error(`加载分享文件失败:`,t),s.error(n.msg||`加载文件列表失败`)}};return h={shareVerified:S,sharePassword:C,shareInvalid:E,shareErrorMsg:D,initShare:async()=>{z(`init-start`);try{let e=await d(o.value);x.value=e.data,L(e.data)}catch(e){E.value=!0,D.value=b(e).msg||`分享链接不存在或已失效`,z(`init-failed`);return}let e=v(_.value?.query?.pwd,``);e&&(C.value=e);let t=y(_.value?.query?.path);T.value=void 0,(!x.value?.needPassword||e)&&(e?await U(e)&&(S.value=!0,await G(t)):(S.value=!0,await G(t)))},verifySharePassword:U,getShareFolderPassword:W,loadShareFiles:G,sortShareChangeMethod:({prop:e,order:t})=>{O.orderBy=e||``,O.orderDirection=t===`descending`?`desc`:`asc`,G(y(_.value?.query?.path))},clearShareRuntime:z},h}export{x as t};