import"./rolldown-runtime-BM3Ffeng.js";import{D as e,dt as t,ot as n}from"./element-plus-vendor-BF9PNysW.js";import{A as r,Ct as i,D as a,E as o,G as s,I as c,N as l,O as u,P as d,Pt as f,Tt as p,Xt as m,Z as h,et as g,ht as _,k as v,l as y,pt as b,s as x,v as S,y as C}from"./vue-vendor-DMUmTARL.js";import{v as w}from"./index-kSn5YXd0.js";import{c as T,u as E}from"./share-5Ahzjf5B.js";import{t as D}from"./route-block-D7Rwj2No.js";import{n as O,t as k}from"./ShareInvalidPanel-CvUZK2pj.js";var A={class:`zf-file-index__body h-full`},j={key:1,class:`mx-auto flex w-full max-w-md flex-1 flex-col justify-center space-y-8`},M={class:`text-center md:text-left`},N={class:`mb-2 text-2xl font-bold text-primary`},P={class:`text-secondary`},F={class:`space-y-2`},I={key:0,class:`space-y-2`},L=c({__name:`index`,setup(c){let D=w(),L=x(),R=p(null),z=p(null),B=i({shareKeyInput:``,passwordInput:``,viewState:`idle`,pendingKind:`none`,invalidMsg:``,inputVersion:0}),V=p(null),H=o(()=>{let e=B.shareKeyInput.trim(),t=e.match(/\/share\/([^/?#]+)/);if(t)try{return decodeURIComponent(t[1])}catch{return t[1]}return e}),U=o(()=>B.pendingKind===`none`?B.viewState===`needPassword`?`查看文件`:`下一步`:`验证中...`);b(()=>B.shareKeyInput,(e,t)=>{e!==t&&(B.inputVersion+=1,V.value=null,B.passwordInput=``,B.invalidMsg=``,B.viewState!==`idle`&&(B.viewState=`idle`))}),h(()=>{s(()=>R.value?.focus?.())});let W=e=>e?.response?.data?.msg||``,G=async(e,t)=>{await L.push({path:`/share/${encodeURIComponent(e)}`,query:t?{pwd:t}:void 0})},K=async e=>{let t=B.inputVersion;B.pendingKind=`probing`,B.invalidMsg=``;try{let n=await T(e);if(t!==B.inputVersion)return;let r=!!n.data?.needPassword;if(V.value={shareKey:e,status:`valid`,needPassword:r,errorMsg:``},!r){await G(e);return}B.viewState=`needPassword`,await s(),z.value?.focus?.()}catch(n){if(t!==B.inputVersion)return;let r=W(n)||`该分享链接不存在、已过期或被删除`;V.value={shareKey:e,status:`invalid`,needPassword:!1,errorMsg:r},B.invalidMsg=r,B.viewState=`invalid`}finally{t===B.inputVersion&&(B.pendingKind=`none`)}},q=async e=>{let t=V.value;if(!t||t.shareKey!==e||!t.needPassword){await K(e);return}if(!B.passwordInput.trim()){D.warning(`请输入访问密码`);return}let n=B.inputVersion;B.pendingKind=`verifying`;try{let t=await E({shareKey:e,password:B.passwordInput});if(n!==B.inputVersion)return;if(t.data===!0){await G(e,B.passwordInput);return}D.error(`密码错误，请重新输入`)}catch(t){if(n!==B.inputVersion)return;let r=W(t);r&&(V.value={shareKey:e,status:`invalid`,needPassword:!1,errorMsg:r},B.invalidMsg=r,B.viewState=`invalid`)}finally{n===B.inputVersion&&(B.pendingKind=`none`)}},J=async()=>{let e=H.value;if(!e){D.warning(`请输入分享码`);return}if(B.pendingKind!==`none`)return;let t=V.value;if(t?.shareKey===e){if(t.status===`invalid`){B.viewState=`invalid`,B.invalidMsg=t.errorMsg;return}if(t.needPassword){await q(e);return}await G(e);return}await K(e)},Y=()=>{B.viewState=`idle`,B.invalidMsg=``,V.value=null,B.passwordInput=``,s(()=>R.value?.focus?.())};return(i,o)=>{let s=t,c=n,p=e;return g(),r(`div`,A,[d(O,null,{default:_(()=>[f(B).viewState===`invalid`?(g(),u(k,{key:0,msg:f(B).invalidMsg,"action-text":`重新输入`,onAction:Y},null,8,[`msg`])):(g(),r(`div`,j,[a(`div`,M,[a(`h2`,N,m(f(B).viewState===`needPassword`?`访问受限`:`访问分享链接`),1),a(`p`,P,m(f(B).viewState===`needPassword`?`此分享受密码保护，请输入访问密码`:`请输入分享码以查看文件`),1)]),d(p,{class:`space-y-6`,onSubmit:C(J,[`prevent`])},{default:_(()=>[a(`div`,F,[o[2]||=a(`label`,{class:`ml-0.5 block text-sm font-medium text-regular`},`分享码`,-1),d(s,{ref_key:`shareKeyInputRef`,ref:R,modelValue:f(B).shareKeyInput,"onUpdate:modelValue":o[0]||=e=>f(B).shareKeyInput=e,placeholder:`请输入分享码，例如 ebcdaeee`,size:`large`,class:`zf-ds-clean-input`,disabled:f(B).pendingKind!==`none`,onKeyup:S(J,[`enter`])},null,8,[`modelValue`,`disabled`])]),d(y,{name:`el-zoom-in-top`},{default:_(()=>[f(B).viewState===`needPassword`?(g(),r(`div`,I,[o[3]||=a(`label`,{class:`ml-0.5 block text-sm font-medium text-regular`},` 访问密码 `,-1),d(s,{ref_key:`passwordInputRef`,ref:z,modelValue:f(B).passwordInput,"onUpdate:modelValue":o[1]||=e=>f(B).passwordInput=e,type:`password`,placeholder:`请输入访问密码`,"show-password":``,size:`large`,class:`zf-ds-clean-input`,disabled:f(B).pendingKind!==`none`,onKeyup:S(J,[`enter`])},null,8,[`modelValue`,`disabled`])])):v(``,!0)]),_:1}),d(c,{type:`primary`,size:`large`,loading:f(B).pendingKind!==`none`,class:`!h-[48px] w-full !rounded-lg !text-[15px] !font-semibold !tracking-wide transition-all active:!scale-[0.99]`,onClick:J},{default:_(()=>[l(m(f(U)),1)]),_:1},8,[`loading`])]),_:1})]))]),_:1})])}}});typeof D==`function`&&D(L);var R=L;export{R as default};