import{j as s}from"./client-By3tlFYA.js";import{u as x,r,a as v}from"./index-TEHZzOO_.js";import{u as f,a as g,bI as N,eh as M,ei as _,ej as k,I as A,S,ek as w,cg as y,a5 as j}from"./useSelectableClick-C6FBaLSu.js";import{S as C}from"./list_alt-DxJSZxN2.js";import"./api-C8Dh2R2O.js";import{J as B}from"./status_quoted-DpF5Slbd.js";import{C as E}from"./check_box-DyXZQAhx.js";import{g as F}from"./lists-BkRGTklx.js";import{M as T}from"./message-CVkQtbZv.js";import"./index-DkCxcZFY.js";import"./relative_timestamp-BOUL06oe.js";import"./ready-DpOgoWSg.js";import"./short_number-C9zm8Jg6.js";import"./numbers-BLyy7tyF.js";import"./index-DUY7J2K7.js";import"./skeleton-CwYXpOUk.js";import"./load_locale-Fyp848fa.js";import"./index-DiPYjm3h.js";import"./done-Bx77AbGW.js";const u=v({newList:{id:"lists.new_list_name",defaultMessage:"New list name"},createList:{id:"lists.create",defaultMessage:"Create"},close:{id:"lightbox.close",defaultMessage:"Close"}}),R=({id:t,title:n,checked:m,onChange:i})=>{const l=r.useCallback(d=>{i(t,d.target.checked)},[t,i]);return s.jsxs("label",{className:"lists__item",children:[s.jsxs("div",{className:"lists__item__title",children:[s.jsx(j,{id:"list-ul",icon:C}),s.jsx("span",{children:n})]}),s.jsx(E,{value:t,checked:m,onChange:l})]})},q=({onCreate:t})=>{const n=x(),m=f(),[i,l]=r.useState(""),d=r.useCallback(({target:{value:a}})=>{l(a)},[l]),p=r.useCallback(()=>{i.trim().length!==0&&m(w({title:i})).then(a=>(y(a)&&(t(a.payload),l("")),""))},[l,m,t,i]);return s.jsxs("form",{className:"lists__item",onSubmit:p,children:[s.jsxs("label",{className:"lists__item__title",children:[s.jsx(j,{id:"list-ul",icon:C}),s.jsx("input",{type:"text",value:i,onChange:d,maxLength:30,required:!0,placeholder:n.formatMessage(u.newList)})]}),s.jsx(B,{text:n.formatMessage(u.createList),type:"submit"})]})},te=({accountId:t,onClose:n})=>{const m=x(),i=f(),l=g(e=>e.accounts.get(t)),d=g(e=>F(e)),[p,a]=r.useState([]);r.useEffect(()=>{i(N()),M(t).then(e=>(a(e.map(c=>c.id)),"")).catch(()=>{})},[i,a,t]);const L=r.useCallback((e,c)=>{c?(a(o=>[e,...o]),_(e,t).catch(()=>{a(o=>o.filter(h=>h!==e))})):(a(o=>o.filter(h=>h!==e)),k(e,t).catch(()=>{a(o=>[e,...o])}))},[a,t]),b=r.useCallback(e=>{a(c=>[e.id,...c]),_(e.id,t).catch(()=>{a(c=>c.filter(o=>o!==e.id))})},[a,t]);return s.jsxs("div",{className:"modal-root__modal dialog-modal",children:[s.jsxs("div",{className:"dialog-modal__header",children:[s.jsx(A,{className:"dialog-modal__header__close",title:m.formatMessage(u.close),icon:"times",iconComponent:S,onClick:n}),s.jsx("span",{className:"dialog-modal__header__title",children:s.jsx(T,{id:"lists.add_to_lists",defaultMessage:"Add {name} to lists",values:{name:s.jsxs("strong",{children:["@",l==null?void 0:l.acct]})}})})]}),s.jsx("div",{className:"dialog-modal__content",children:s.jsxs("div",{className:"lists-scrollable",children:[s.jsx(q,{onCreate:b}),d.map(e=>s.jsx(R,{id:e.id,title:e.title,checked:p.includes(e.id),onChange:L},e.id))]})})]})};export{te as default};
//# sourceMappingURL=list_adder-index-QrScEsP8.js.map
