import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,f as r,l as i,s as a}from"./hooks.module-BrXTvcfS.js";import{H as o,Pt as s}from"./content_renderer-DOj8g78V.js";import{n as c}from"./bulk_action-LboOPmOm.js";import{a as l}from"./i18n-BaLR3UdQ.js";import{t as u}from"./server-BXh06Wz_.js";import{i as d}from"./toast-C6WyPqyA.js";import{t as f}from"./jsxRuntime.module-Cao1NCKs.js";import{J as p}from"./hooks-ClTXKdUl.js";import{t as m}from"./Modal-hBkTa-Ee.js";import{t as h}from"./Button-Du0dYm4Z.js";import{t as g}from"./FormCheckbox-B6Pj6_Zs.js";n(),t();function _(){let[t,n]=a(),[_,b]=a(),[x,S]=a(!1),[C,w]=a(0),[T,E]=a([]),[D,O]=a(!1);p(`openBulkActionsDialog`,async({selectedOrActiveNoteIds:e})=>{n(e),b(await o.getNote(`_bulkAction`)),O(!0)}),i(()=>{!t||!_||u.post(`bulk-action/affected-notes`,{noteIds:t,includeDescendants:x}).then(({affectedNoteCount:e})=>w(e))},[t,x,_]);let k=r(()=>{_&&E(c.parseActions(_))},[_]);return i(()=>{k()},[k]),p(`entitiesReloaded`,({loadResults:e})=>{e.getAttributeRows().find(e=>e.type===`label`&&e.name===`action`&&e.noteId===`_bulkAction`)&&k()}),f(m,{className:`bulk-actions-dialog`,size:`xl`,title:l(`bulk_actions.bulk_actions`),footer:f(e,{children:[f(h,{text:l(`modal.cancel`),onClick:()=>O(!1)}),f(h,{text:l(`bulk_actions.execute_bulk_actions`),kind:`primary`})]}),show:D,onSubmit:async()=>{let e=T.map(e=>e.getConfirmationMessage()).filter(e=>!!e);if(e.length&&!await s.confirm(e.join(`

`)))return;let n=T.map(e=>({...e.actionDef,name:e.constructor.actionName}));await u.post(`bulk-action/execute`,{noteIds:t,includeDescendants:x,actions:n}),d.showMessage(l(`bulk_actions.bulk_actions_executed`),3e3),O(!1)},onHidden:()=>O(!1),children:[f(`h4`,{children:[l(`bulk_actions.affected_notes`),`: `,f(`span`,{children:C})]}),f(g,{name:`include-descendants`,label:l(`bulk_actions.include_descendants`),currentValue:x,onChange:S}),f(`h4`,{children:l(`bulk_actions.available_actions`)}),f(v,{}),f(`h4`,{children:l(`bulk_actions.chosen_actions`)}),f(y,{existingActions:T})]})}function v(){return f(`table`,{class:`bulk-available-action-list`,children:c.ACTION_GROUPS.map(e=>f(`tr`,{children:[f(`td`,{children:[e.title,`:`]}),e.actions.map(({actionName:e,actionTitle:t})=>f(h,{size:`small`,text:t,onClick:()=>c.addAction(`_bulkAction`,e)}))]}))})}function y({existingActions:e}){return f(`table`,{class:`bulk-existing-action-list`,children:e?e.map(e=>e.doRender()).filter(e=>e!==null):f(`p`,{children:l(`bulk_actions.none_yet`)})})}export{_ as default};