import"./p-5d02c032.js";import"./p-b1bf9564.js";import"@sankhyalabs/core";import{P as n}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-f076d742.js";import"./p-ff1990ad.js";import"./p-7bbbfd42.js";import{V as i}from"./p-9019a32f.js";import{T as s}from"./p-3072136e.js";class t{constructor(n){this._defaultButtons=[],this._defaultButtons=[...n]}process(n,i,s,t=[],r=[]){var o;this.taskbarID=n,this.customButtons=new Map,this.buttonsArray=[],this.disabledButtons=[...t],null===(o=this.getButtonsArray(i,s))||void 0===o||o.forEach((n=>{let o;"string"==typeof n?o=n:(this.customButtons.set(n.name,n),o=n.name),r.includes(o)||(this.isEnabled(i,o,s,t)||this.disabledButtons.push(o),this.buttonsArray.push(o))})),this.buttons=this.buttonsArray.join(",")}getButtonsArray(n,i){return n?n.getButtons(this.taskbarID,i,[...this._defaultButtons]):this._defaultButtons}isEnabled(n,i,s,t){const r=!t.includes(i);return n&&n.isEnabled?n.isEnabled(this.taskbarID,s,i,r):r}}const r=[s.FORM_MODE,s.PREVIOUS,s.NEXT,s.REFRESH,s.SPACER,s.ACTIONS_BUTTON,s.DATA_EXPORTER,s.ATTACH,s.CLONE,s.UPDATE,s.REMOVE,s.INSERT,s.CONFIGURATOR,s.MORE_OPTIONS];var o;function a(n,t,r){var a,e;const l=[{name:o.FILTER,hint:null!==(a=null==r?void 0:r.getMessage("snkCrud.customButtons.filter"))&&void 0!==a?a:"Abre o painel de filtros",iconName:"filter"},{name:o.ENTITY_SEARCH,hint:null!==(e=null==r?void 0:r.getMessage("snkCrud.customButtons.entitySearch"))&&void 0!==e?e:"Busca na entidade",iconName:"search"}],d=[s.CANCEL,s.SAVE];return{getButtons:(r,o,a)=>{var e,u;if(!r)return console.warn("taskbarID não fornecido"),[];if((null==o?void 0:o.insertionMode)||(null==o?void 0:o.isDirty))return d;if(n===i.FORM){const n=a.indexOf(s.FORM_MODE);n>-1&&(a=[...a.slice(0,n),s.GRID_MODE,...a.slice(n+1)])}if((null===(u=null===(e=null==o?void 0:o.selectionInfo)||void 0===e?void 0:e.records)||void 0===u?void 0:u.length)>1){const n=a.indexOf(s.UPDATE);n>-1&&(a=[...a.slice(0,n),s.UPDATE_MULTIPLE,...a.slice(n+1)])}const c=function(n,i){const t=n.findIndex((n=>n===s.SPACER||"string"==typeof n&&"SPACER"===n));return t>-1?[...n.slice(0,t),...i,...n.slice(t)]:[...i,...n]}(a,l);return(null==t?void 0:t.getButtons)?t.getButtons(r,o,c):c},isEnabled:(n,i,r,o)=>{var a;if(!i)return o;if(void 0===i.selectedRecord&&[s.UPDATE,s.REMOVE,s.ATTACH,s.CLONE].includes(r))return!1;const e=function(n){const i=[];return(null==n?void 0:n.hasPrevious)||i.push(s.PREVIOUS),(null==n?void 0:n.hasNext)||i.push(s.NEXT),i}(i);return!e.includes(r)&&(null!==(a=null==t?void 0:t.isEnabled(n,i,r,o))&&void 0!==a?a:o)},getMoreOptions(n,i,s,r){var o;return null===(o=null==t?void 0:t.getMoreOptions)||void 0===o?void 0:o.call(t,n,i,s,r)}}}function e(i,s){var t;const r=i&&!!(null===(t=i.selectionInfo)||void 0===t?void 0:t.length),o={primary:"snkGridHeaderTaskbar",secondary:"snkGridHeaderTaskbar",singleTaskbar:"snkGridHeaderTaskbar.singleTaskbar"}[s];let a=r?`${o}.selected`:`${o}.unselected`;return(null==i?void 0:i.isDirty)&&s===n.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}function l(n,i){const s={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[i];return(null==n?void 0:n.isDirty)?`snkGridTopTaskbar.finish_edition${s}`:`snkGridTopTaskbar.regular${s}`}!function(n){n.FILTER="FILTER",n.ENTITY_SEARCH="ENTITY_SEARCH"}(o||(o={}));export{o as C,r as D,t as S,e as a,a as b,l as g}