import{At as e,B as t,Bt as n,D as r,Dt as i,F as a,G as o,J as s,L as c,Mt as l,N as u,R as d,Tt as f,Ut as p,bt as m,ct as h,h as g,ht as _,j as v,ot as y,p as b,qt as x}from"./vue-3bs2-dMU.js";import{K as S,St as C,U as w,Wt as T,dt as E,w as D}from"./stores-DmetsdTd.js";import{C as O,D as k,K as A,M as j,N as M,S as N,T as P,U as F,W as I,b as L,et as R,nt as z,rt as B,w as V,y as H}from"./vuetify-gGrfRH2I.js";o(),f();var U={class:`d-flex ga-3 flex-row`},W=t({__name:`TrackerEditRow`,props:s({availableTrackers:{}},{modelValue:{required:!0},modelModifiers:{}}),emits:s([`delete`],[`update:modelValue`]),setup(e){let t=_(e,`modelValue`),{t:r}=S(),{trackers:i}=b(D()),o=v({get:()=>t.value[0],set:e=>t.value[0]=e}),s=v({get:()=>t.value[1],set:e=>t.value[1]=e}),c=[e=>!o.value||!s.value||s.value.length===0||C(e)||r(`dialogs.bulkEditTrackers.edit.row.rules.invalid_url`)];return(t,l)=>(y(),a(`div`,U,[d(M,{modelValue:o.value,"onUpdate:modelValue":l[0]||=e=>o.value=e,class:`w-50`,items:e.availableTrackers,label:n(r)(`dialogs.bulkEditTrackers.edit.row.old_url`)},null,8,[`modelValue`,`items`,`label`]),d(j,{modelValue:s.value,"onUpdate:modelValue":l[1]||=e=>s.value=e,class:`w-50`,items:n(i),rules:c,label:n(r)(`dialogs.bulkEditTrackers.edit.row.new_url`)},null,8,[`modelValue`,`items`,`label`]),d(A,{color:`error`,variant:`text`,icon:`mdi-minus`,onClick:l[2]||=e=>t.$emit(`delete`)})]))}});o();var G=t({__name:`TrackersEditField`,props:s({allTrackers:{}},{modelValue:{required:!0},modelModifiers:{}}),emits:[`update:modelValue`],setup(e){let t=e,n=_(e,`modelValue`),i=v(()=>t.allTrackers.filter(e=>!n.value.map(e=>e[0]).includes(e)));function o(){n.value.push([void 0,void 0])}function s(e,t){n.value[e]=t}function c(e){n.value.splice(e,1)}return(e,t)=>(y(),a(r,null,[(y(!0),a(r,null,h(n.value,(e,t)=>(y(),u(B,{key:t},{default:m(()=>[d(W,{"model-value":e,"available-trackers":i.value,"onUpdate:modelValue":e=>s(t,e),onDelete:e=>c(t)},null,8,[`model-value`,`available-trackers`,`onUpdate:modelValue`,`onDelete`])]),_:2},1024))),128)),d(B,null,{default:m(()=>[d(A,{"prepend-icon":`mdi-plus`,color:`accent`,variant:`text`,text:e.$t(`dialogs.bulkEditTrackers.edit.row.add`),onClick:o},null,8,[`text`])]),_:1})],64))}});o(),f(),p();var K=t({__name:`BulkUpdateTrackersDialog`,props:{guid:{},hashes:{}},setup(t){let r=t,a=l(!1),o=l(!1),s=e({add:``,edit:[],remove:``}),f=E(()=>[...new Set(r.hashes.flatMap(e=>_.torrentTrackers.get(e)??[]))],T.text.asc),{t:p}=S(),{isOpened:h}=w(r.guid),_=D();function v(){h.value=!1}async function b(){o.value=!0,await _.bulkUpdateTrackers(r.hashes,{add:s.add,replace:s.edit,remove:s.remove.split(`
`).filter(e=>e.length)}).then(e=>{if(e.rejected.length>0){o.value=!1;let t=[...new Set(e.rejected.map(String))].join(`
`);g.error(p(`dialogs.bulkEditTrackers.edit.result`,{rejected:e.rejected.length,total:e.total,reason:t}));return}v()})}return(e,t)=>(y(),u(N,{modelValue:n(h),"onUpdate:modelValue":t[4]||=e=>i(h)?h.value=e:null},{default:m(()=>[d(O,null,{default:m(()=>[d(P,{class:`ios-margin`},{default:m(()=>[d(F,{color:`transparent`},{default:m(()=>[d(I,null,{default:m(()=>[c(x(n(p)(`dialogs.bulkEditTrackers.title`)),1)]),_:1}),d(A,{icon:`mdi-close`,onClick:v})]),_:1})]),_:1}),d(V,null,{default:m(()=>[d(n(H),{ref:`form`,modelValue:a.value,"onUpdate:modelValue":t[3]||=e=>a.value=e},{default:m(()=>[d(R,null,{default:m(()=>[d(z,{title:n(p)(`dialogs.bulkEditTrackers.add`)},null,8,[`title`]),d(B,null,{default:m(()=>[d(L,{modelValue:s.add,"onUpdate:modelValue":t[0]||=e=>s.add=e,placeholder:`https://example1.com/announce
https://example2.com/announce`},null,8,[`modelValue`])]),_:1}),d(z,{title:n(p)(`dialogs.bulkEditTrackers.edit.title`)},null,8,[`title`]),d(G,{modelValue:s.edit,"onUpdate:modelValue":t[1]||=e=>s.edit=e,"all-trackers":n(f)},null,8,[`modelValue`,`all-trackers`]),d(z,{title:n(p)(`dialogs.bulkEditTrackers.remove`)},null,8,[`title`]),d(B,null,{default:m(()=>[d(L,{modelValue:s.remove,"onUpdate:modelValue":t[2]||=e=>s.remove=e,placeholder:`https://example1.com/announce
https://example2.com/announce`},null,8,[`modelValue`])]),_:1})]),_:1})]),_:1},8,[`modelValue`])]),_:1}),d(k,null,{default:m(()=>[d(A,{color:`error`,onClick:v},{default:m(()=>[c(x(n(p)(`common.cancel`)),1)]),_:1}),d(A,{color:`accent`,disabled:!a.value,loading:o.value,onClick:b},{default:m(()=>[c(x(n(p)(`common.save`)),1)]),_:1},8,[`disabled`,`loading`])]),_:1})]),_:1})]),_:1},8,[`modelValue`]))}});export{K as default};