import{At as e,B as t,Bt as n,Dt as r,G as i,L as a,Mt as o,N as s,P as c,Q as l,R as u,T as d,Tt as f,Ut as p,X as m,bt as h,ot as g,qt as _,w as v,y}from"./vue-3bs2-dMU.js";import{K as b,U as x,m as S}from"./stores-DmetsdTd.js";import{C,D as w,G as T,K as E,S as D,T as O,ht as k,w as A,y as j}from"./vuetify-gGrfRH2I.js";i(),f(),p(),y();var M=t({__name:`MoveTorrentFileDialog`,props:{guid:{},hash:{},isFolder:{type:Boolean},oldName:{}},setup(t){let i=t,{isOpened:f}=x(i.guid),{t:p}=b(),y=S(),M=o(),N=o(),P=o(!1),F=e({newName:``}),I=[e=>!!e||p(`dialogs.moveTorrent.required`)];async function L(){await M.value?.validate(),P.value&&(i.isFolder?await y.renameTorrentFolder(i.hash,i.oldName,F.newName):await y.renameTorrentFile(i.hash,i.oldName,F.newName),R())}function R(){f.value=!1}return l(()=>{if(F.newName=i.oldName,i.isFolder)m(()=>N.value?.select());else{let e=F.newName.lastIndexOf(`/`),t=F.newName.lastIndexOf(`.`);m(()=>{N.value?.setSelectionRange(e+1,t==-1?F.newName.length:t)})}}),(e,i)=>(g(),s(D,{modelValue:n(f),"onUpdate:modelValue":i[3]||=e=>r(f)?f.value=e:null},{default:h(()=>[u(C,null,{default:h(()=>[u(O,null,{default:h(()=>[a(_(n(p)(`dialogs.moveTorrentFile.title`,1+Number(t.isFolder))),1)]),_:1}),u(A,null,{default:h(()=>[u(n(j),{ref_key:`form`,ref:M,modelValue:P.value,"onUpdate:modelValue":i[1]||=e=>P.value=e,onSubmit:i[2]||=d(()=>{},[`prevent`])},{default:h(()=>[t.oldName?(g(),s(T,{key:0,"model-value":t.oldName,disabled:``,label:e.$t(`dialogs.moveTorrentFile.oldName`)},null,8,[`model-value`,`label`])):c(``,!0),u(T,{ref_key:`input`,ref:N,modelValue:F.newName,"onUpdate:modelValue":i[0]||=e=>F.newName=e,rules:I,autofocus:``,label:e.$t(`dialogs.moveTorrent.newPath`),onKeydown:v(L,[`enter`])},null,8,[`modelValue`,`label`])]),_:1},8,[`modelValue`])]),_:1}),u(w,null,{default:h(()=>[u(k),u(E,{color:`error`,onClick:R},{default:h(()=>[a(_(e.$t(`common.cancel`)),1)]),_:1}),u(E,{color:`accent`,disabled:!P.value,onClick:L},{default:h(()=>[a(_(e.$t(`common.save`)),1)]),_:1},8,[`disabled`])]),_:1})]),_:1})]),_:1},8,[`modelValue`]))}});export{M as default};