@sankhyalabs/sankhyablocks 8.16.0-dev.39 → 8.16.0-dev.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/dist/cjs/index-f9e81701.js +8 -28
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/{snk-form-config.cjs.entry.js → snk-config-options_3.cjs.entry.js} +363 -1
  5. package/dist/cjs/{snk-filter-bar.cjs.entry.js → snk-filter-bar_4.cjs.entry.js} +685 -0
  6. package/dist/cjs/snk-simple-crud.cjs.entry.js +3 -1
  7. package/dist/collection/collection-manifest.json +11 -31
  8. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +3 -1
  9. package/dist/collection/sw.js +46 -0
  10. package/dist/components/snk-simple-crud2.js +3 -1
  11. package/dist/esm/{SnkFormConfigManager-139f09fa.js → SnkFormConfigManager-f1a0fc92.js} +1 -1
  12. package/dist/esm/{constants-8457af36.js → constants-7302ee87.js} +1 -1
  13. package/dist/esm/index-a7d3d3f1.js +8 -28
  14. package/dist/esm/loader.js +1 -1
  15. package/dist/esm/sankhyablocks.js +1 -1
  16. package/dist/esm/snk-actions-button_4.entry.js +1 -1
  17. package/dist/esm/snk-attach.entry.js +1 -1
  18. package/dist/esm/{snk-form-config.entry.js → snk-config-options_3.entry.js} +364 -4
  19. package/dist/esm/snk-configurator.entry.js +1 -1
  20. package/dist/esm/snk-crud.entry.js +1 -1
  21. package/dist/esm/snk-data-exporter.entry.js +1 -1
  22. package/dist/esm/snk-detail-view.entry.js +3 -3
  23. package/dist/esm/snk-field-config.entry.js +1 -1
  24. package/dist/esm/{snk-filter-bar.entry.js → snk-filter-bar_4.entry.js} +684 -2
  25. package/dist/esm/{snk-guides-viewer-c1ef991c.js → snk-guides-viewer-2f4dcdc5.js} +2 -2
  26. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  27. package/dist/esm/snk-simple-crud.entry.js +5 -3
  28. package/dist/esm/snk-tab-config.entry.js +1 -1
  29. package/dist/sankhyablocks/p-052213ba.entry.js +1 -0
  30. package/dist/sankhyablocks/{p-11a0a7ac.entry.js → p-0b6cd238.entry.js} +1 -1
  31. package/dist/sankhyablocks/p-0e320bd2.entry.js +1 -0
  32. package/dist/sankhyablocks/{p-281bc322.entry.js → p-275de842.entry.js} +1 -1
  33. package/dist/sankhyablocks/{p-8eb67fa4.entry.js → p-2d3f9482.entry.js} +1 -1
  34. package/dist/sankhyablocks/{p-7663f597.entry.js → p-41793e17.entry.js} +1 -1
  35. package/dist/sankhyablocks/{p-1b6d51bf.entry.js → p-5e51e833.entry.js} +1 -1
  36. package/dist/sankhyablocks/{p-d3341910.entry.js → p-72c10005.entry.js} +1 -1
  37. package/dist/sankhyablocks/{p-11cc69fc.js → p-7bd9683d.js} +1 -1
  38. package/dist/sankhyablocks/{p-95df461f.entry.js → p-8b4fc28f.entry.js} +1 -1
  39. package/dist/sankhyablocks/{p-b0ef4383.js → p-95ce311a.js} +1 -1
  40. package/dist/sankhyablocks/{p-5ea74956.entry.js → p-ab1645fb.entry.js} +1 -1
  41. package/dist/sankhyablocks/{p-47f79aa0.entry.js → p-cefb0ee1.entry.js} +1 -1
  42. package/dist/sankhyablocks/p-fa6c5826.entry.js +1 -0
  43. package/dist/sankhyablocks/{p-afbb070d.js → p-fadc8339.js} +1 -1
  44. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  45. package/package.json +3 -2
  46. package/dist/cjs/snk-config-options.cjs.entry.js +0 -239
  47. package/dist/cjs/snk-filter-item.cjs.entry.js +0 -312
  48. package/dist/cjs/snk-filter-list.cjs.entry.js +0 -152
  49. package/dist/cjs/snk-filter-modal.cjs.entry.js +0 -249
  50. package/dist/cjs/snk-form.cjs.entry.js +0 -144
  51. package/dist/esm/snk-config-options.entry.js +0 -235
  52. package/dist/esm/snk-filter-item.entry.js +0 -308
  53. package/dist/esm/snk-filter-list.entry.js +0 -148
  54. package/dist/esm/snk-filter-modal.entry.js +0 -245
  55. package/dist/esm/snk-form.entry.js +0 -140
  56. package/dist/sankhyablocks/p-06898e5a.entry.js +0 -1
  57. package/dist/sankhyablocks/p-3b60db06.entry.js +0 -1
  58. package/dist/sankhyablocks/p-60b29483.entry.js +0 -1
  59. package/dist/sankhyablocks/p-70a4af56.entry.js +0 -1
  60. package/dist/sankhyablocks/p-b9679243.entry.js +0 -1
  61. package/dist/sankhyablocks/p-d3f53df2.entry.js +0 -1
  62. package/dist/sankhyablocks/p-e8763234.entry.js +0 -1
  63. package/dist/sankhyablocks/p-feba9d4b.entry.js +0 -1
@@ -1,10 +1,10 @@
1
1
  import { r as registerInstance, c as createEvent, h, F as Fragment } from './index-a7d3d3f1.js';
2
2
  import { Action, ElementIDUtils } from '@sankhyalabs/core';
3
- import { S as SnkFormConfigManager } from './SnkFormConfigManager-139f09fa.js';
3
+ import { S as SnkFormConfigManager } from './SnkFormConfigManager-f1a0fc92.js';
4
4
  import { buildFormMetadata, FormMetadata } from '@sankhyalabs/ezui/dist/collection/utils/form';
5
5
  import { o as openFieldSearch, T as TaskbarProcessor, b as buildFieldSearch } from './field-search-f8b1d91e.js';
6
6
  import { T as TaskbarElement } from './taskbar-elements-d59867f1.js';
7
- import { d as VIEW_MODE } from './constants-8457af36.js';
7
+ import { V as VIEW_MODE } from './constants-7302ee87.js';
8
8
  import './DataFetcher-a9c598f2.js';
9
9
  import './pesquisa-fetcher-50fc7e6b.js';
10
10
  import { P as PresentationMode } from './index-3aa4977a.js';
@@ -1,14 +1,14 @@
1
- export { S as snk_guides_viewer } from './snk-guides-viewer-c1ef991c.js';
1
+ export { S as snk_guides_viewer } from './snk-guides-viewer-2f4dcdc5.js';
2
2
  import './index-a7d3d3f1.js';
3
3
  import '@sankhyalabs/core';
4
- import './SnkFormConfigManager-139f09fa.js';
4
+ import './SnkFormConfigManager-f1a0fc92.js';
5
5
  import './ConfigStorage-7b36d041.js';
6
6
  import './form-config-fetcher-adbe5d34.js';
7
7
  import './DataFetcher-a9c598f2.js';
8
8
  import './PrintUtils-3e4ff0f5.js';
9
9
  import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
10
10
  import './filter-item-type.enum-d45e026f.js';
11
- import './constants-8457af36.js';
11
+ import './constants-7302ee87.js';
12
12
  import '@sankhyalabs/ezui/dist/collection/utils/form';
13
13
  import './field-search-f8b1d91e.js';
14
14
  import './taskbar-elements-d59867f1.js';
@@ -1,7 +1,7 @@
1
1
  import { r as registerInstance, c as createEvent, h, g as getElement } from './index-a7d3d3f1.js';
2
2
  import { UserInterface, StringUtils, ApplicationContext, ObjectUtils, DataType, JSUtils, FloatingManager, ElementIDUtils } from '@sankhyalabs/core';
3
3
  import { CSSVarsUtils } from '@sankhyalabs/ezui/dist/collection/utils';
4
- import { d as VIEW_MODE, S as SIMPLE_CRUD_MODE } from './constants-8457af36.js';
4
+ import { V as VIEW_MODE, S as SIMPLE_CRUD_MODE } from './constants-7302ee87.js';
5
5
  import { T as TaskbarElement } from './taskbar-elements-d59867f1.js';
6
6
  import './DataFetcher-a9c598f2.js';
7
7
  import './pesquisa-fetcher-50fc7e6b.js';
@@ -15,7 +15,7 @@ import './filter-item-type.enum-d45e026f.js';
15
15
  import { F as FormConfigFetcher } from './form-config-fetcher-adbe5d34.js';
16
16
  import { T as TaskbarProcessor, b as buildFieldSearch, o as openFieldSearch } from './field-search-f8b1d91e.js';
17
17
  import { C as ConfigStorage } from './ConfigStorage-7b36d041.js';
18
- import { S as SnkFormConfigManager } from './SnkFormConfigManager-139f09fa.js';
18
+ import { S as SnkFormConfigManager } from './SnkFormConfigManager-f1a0fc92.js';
19
19
  import { g as getSelectedRecordsIDsInfo } from './GetSelectedRecordsIDsInfo-9fa41508.js';
20
20
  import { s as store } from './index-bdf75557.js';
21
21
  import './PrintUtils-3e4ff0f5.js';
@@ -720,9 +720,11 @@ const SnkSimpleCrud = class {
720
720
  window.removeEventListener("keydown", this._keyDownHandler);
721
721
  }
722
722
  gridConfigChangeHandler(evt) {
723
+ evt.stopPropagation();
724
+ if (!this.configName)
725
+ return;
723
726
  const config = evt.detail;
724
727
  ConfigStorage.saveGridConfig(config, this.configName, this.resolveResourceID());
725
- evt.stopPropagation();
726
728
  }
727
729
  modalConfigChangeHandler(evt) {
728
730
  const config = evt.detail;
@@ -1,7 +1,7 @@
1
1
  import { r as registerInstance, c as createEvent, h, F as Fragment, H as Host, g as getElement } from './index-a7d3d3f1.js';
2
2
  import { S as Sortable } from './Sortable-83960219.js';
3
3
  import { ApplicationContext, ElementIDUtils } from '@sankhyalabs/core';
4
- import { C as CONFIG_EVENTS, a as CONFIG_SORTABLE_EVENTS, K as KEY_EVENTS, c as TYPE_ACTIONS, T as TAB_NAMES } from './constants-8457af36.js';
4
+ import { C as CONFIG_EVENTS, a as CONFIG_SORTABLE_EVENTS, K as KEY_EVENTS, T as TYPE_ACTIONS, b as TAB_NAMES } from './constants-7302ee87.js';
5
5
 
6
6
  const snkTabConfigCss = "@keyframes activate{0%{clip-path:inset(calc(100% - 3px) 50% 0px 50%)}100%{clip-path:inset(calc(100% - 3px) 0px 0px 0px)}}.sc-snk-tab-config-h{--snk-tab-config--backward-icon:url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"16px\" width=\"10px\"><path d=\"M 9.7808475,13.860393 3.9204526,8.0000004 9.7808475,2.0624965 7.9301965,0.28895552 0.21915255,8.0000004 7.9301965,15.711044 Z\"/></svg>');--snk-tab-config--forward-icon:url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"16px\" width=\"10px\"><path d=\"M 0.21915251,13.860393 6.0795475,8.0000007 0.21915251,2.0624968 2.0698036,0.28895588 9.7808475,8.0000007 2.0698036,15.711044 Z\"/></svg>');--snk-tab-config__lower-bar--background-color:var(--color--disable-primary, #e5eaf0);--snk-tab-config__lower-bar--border:2px solid var(--color--disable-primary, #e5eaf0);--snk-tab-config__tab--color:var(--text--primary, #626e82);--snk-tab-config__tab--font-family:var(--font-pattern, \"Roboto\");--snk-tab-config__tab--font-size:var(--title--small, 14px);--snk-tab-config__tab--padding:var(--space--small, 6px) var(--space--medium, 12px);--snk-tab-config__tab-is-active--color:var(--color--primary, #008561);--snk-tab-config__tab-hover--color:var(--color--secondary, #383c45);--snk-tab-config__tab-is-focused--border:1px dashed var(--color--primary, #008561);--snk-tab-config__tab-label--text-shadow:var(--text-shadow, 0 0 0 #353535, 0 0 1px transparent);--snk-tab-config__tab-label--margin-bottom:var(--space--extra-small, 3px);--snk-tab-config__new-button-icon--color:var(--color--secondary-700, #1C1D22);--snk-tab-config__forward-button--background-color:var(--text--primary, #626e82);--snk-tab-config__forward-button-hover--background-color:var(--color--primary, #008561);--snk-tab-config__left-icon--padding-right:var(--space--small, 6px);--snk-tab-config__left-icon--color:var(--text--disable, #AFB6C0);--snk-tab-config__tab-label-disabled--color:var(--text--disable, #AFB6C0);--snk-tab-config__slot--margin-left:var(--space--small, 6px);display:flex;position:relative;width:100%;overflow:hidden}.tab-config__scroll.sc-snk-tab-config{display:flex;width:100%;scroll-behavior:smooth;overflow-x:auto;scrollbar-width:none}.tab-config__lower-bar.sc-snk-tab-config{position:absolute;left:0%;right:0%;top:91%;bottom:0%;border-radius:2px;background-color:var(--snk-tab-config__lower-bar--background-color);border:var(--snk-tab-config__lower-bar--border)}.tab-config__tab.sc-snk-tab-config{display:flex;border:none;background-color:unset;cursor:pointer;align-items:center;justify-content:center;min-width:fit-content;color:var(--snk-tab-config__tab--color);font-family:var(--snk-tab-config__tab--font-family);font-size:var(--snk-tab-config__tab--font-size);padding:var(--snk-tab-config__tab--padding)}.tab-config__tab.sc-snk-tab-config:focus,.tab-config__forward-button.sc-snk-tab-config,.tab-config__backward-button.sc-snk-tab-config{outline:none}.tab-config__tab--is-active.sc-snk-tab-config{position:relative;color:var(--snk-tab-config__tab-is-active--color)}.tab-config__tab.sc-snk-tab-config:hover{color:var(--snk-tab-config__tab-hover--color)}.tab-config__tab--is-active.sc-snk-tab-config:hover{color:var(--snk-tab-config__tab-is-active--color)}.tab-config__tab--is-active.sc-snk-tab-config::after{content:\"\";position:absolute;width:100%;height:100%;clip-path:inset(calc(100% - 3px) 0px 0px 0px);animation:activate 0.25s ease-in-out;background-color:var(--snk-tab-config__tab-is-active--color)}.tab-config__tab--is-focused.sc-snk-tab-config{border:var(--snk-tab-config__tab-is-focused--border)}.tab-config__tab-label.sc-snk-tab-config{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-shadow:var(--snk-tab-config__tab-label--text-shadow);margin-bottom:var(--snk-tab-config__tab-label--margin-bottom)}.tab-config__forward-button.sc-snk-tab-config,.tab-config__backward-button.sc-snk-tab-config{position:absolute;z-index:1;display:flex;box-sizing:border-box;padding:0px;top:0px;right:0px;width:16px;height:100%;border:none;background-color:unset;cursor:pointer;justify-content:center;align-items:center}.tab-config__new-button.sc-snk-tab-config{position:absolute;z-index:1;display:flex;box-sizing:border-box;padding:0px;top:0px;right:0px;height:100%;border:none;background-color:unset;cursor:pointer;justify-content:center;align-items:center}.tab-config__new-button.sc-snk-tab-config ez-icon.sc-snk-tab-config{--ez-icon--color:var(--snk-tab-config__new-button-icon--color)}.tab-config__backward-button.sc-snk-tab-config{left:0px;box-shadow:10px 10px 5px 5px white;background:white}.tab-config__forward-button.sc-snk-tab-config{box-shadow:10px 10px 5px 20px white;background:white}.tab-config__forward-button.sc-snk-tab-config::after,.tab-config__backward-button.sc-snk-tab-config::after{content:'';display:flex;width:10px;height:16px;background-color:var(--snk-tab-config__forward-button--background-color)}.tab-config__forward-button.sc-snk-tab-config::after{-webkit-mask-image:var(--snk-tab-config--forward-icon);mask-image:var(--snk-tab-config--forward-icon)}.tab-config__backward-button.sc-snk-tab-config::after{-webkit-mask-image:var(--snk-tab-config--backward-icon);mask-image:var(--snk-tab-config--backward-icon)}.tab-config__forward-button.sc-snk-tab-config:hover::after,.tab-config__backward-button.sc-snk-tab-config:hover::after{background-color:var(--snk-tab-config__forward-button-hover--background-color)}.tab-config__new-button.sc-snk-tab-config:hover ez-icon.sc-snk-tab-config{--ez-icon--color:var(--snk-tab-config__forward-button-hover--background-color)}.tab-config__hidden.sc-snk-tab-config{display:none}.tab-config__scroll.sc-snk-tab-config::-webkit-scrollbar{display:none}.tab-config__left-icon.sc-snk-tab-config{padding-right:var(--snk-tab-config__left-icon--padding-right);--ez-icon--color:var(--snk-tab-config__left-icon--color)}.tab-config__left-icon--eye-off.sc-snk-tab-config{--ez-icon--color:var(--snk-tab-config__left-icon--color)}.tab-config__right-icon.sc-snk-tab-config{visibility:hidden;padding-left:var(--snk-tab-config__left-icon--padding-right)}.tab-config__tab.sc-snk-tab-config:hover .tab-config__right-icon.sc-snk-tab-config{visibility:visible}.tab-config__tab--is-active.sc-snk-tab-config .tab-config__right-icon.sc-snk-tab-config{visibility:visible;--ez-icon--color:var(--snk-tab-config__tab-is-active--color)}.tab-config__tab.sc-snk-tab-config:hover .tab-config__right-icon.sc-snk-tab-config{--ez-icon--color:var(--snk-tab-config__tab-hover--color)}.tab-config__tab--is-active.sc-snk-tab-config:hover .tab-config__right-icon.sc-snk-tab-config{--ez-icon--color:var(--snk-tab-config__tab-is-active--color)}.tab-config__actions-button.sc-snk-tab-config{--ez-actions-button__btn-action--min-width:100px;visibility:hidden;opacity:0;transition:visibility 1s linear, opacity 0.3s linear}.tab-config__tab.sc-snk-tab-config:hover .tab-config__actions-button.sc-snk-tab-config{visibility:visible;opacity:1;transition:visibility 0.2s linear, opacity 0.10s linear}[data-draggable-element].sc-snk-tab-config{cursor:grab}.tab-config__tab-label-disabled.sc-snk-tab-config{color:var(--snk-tab-config__tab-label-disabled--color)}.tab-config__slot.sc-snk-tab-config{margin-left:var(--snk-tab-config__slot--margin-left)}";
7
7
 
@@ -0,0 +1 @@
1
+ import{r as t,c as i,h as e,H as s,g as r}from"./p-d2d301a6.js";import{DataType as l,StringUtils as n,ObjectUtils as a,ElementIDUtils as o,ErrorException as h,ApplicationContext as d,FloatingManager as c,DateUtils as u,ArrayUtils as m}from"@sankhyalabs/core";import{EzScrollDirection as f}from"@sankhyalabs/ezui/dist/collection/components/ez-scroller/EzScrollDirection";import{C as p}from"./p-4d9549cf.js";import{toString as v}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{F as b}from"./p-ff1990ad.js";import{F as k}from"./p-933c0c0b.js";import{F as g}from"./p-fa80e546.js";import{ApplicationUtils as _}from"@sankhyalabs/ezui/dist/collection/utils";import{P as F}from"./p-057fad05.js";import{ModalAction as x}from"@sankhyalabs/ezui/dist/collection/components/ez-modal-container";import{F as z}from"./p-d9804798.js";import"./p-06421fdb.js";import"./p-f3434fc4.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";function y(t){let i="";return t.forEach(((t,e)=>{var s;i+=` ${e>0?null!==(s=t.operand)&&void 0!==s?s:"OR":""} ${t.expression}`})),i.trim()}class w{constructor({filterConfig:t,configName:i,onComplete:e,getMessage:s,disablePersonalizedFilter:r,onAddPersonalizedFilter:l,onEditPersonalizedFilter:n,onDeletePersonalizedFilter:a}){this._filterConfig=t,this._configName=i,this._onComplete=e,this._getMessage=s,this._disablePersonalizedFilter=r,this._addPersonalizedFilterFn=l,this._editPersonalizedFilterFn=n,this._onDeletePersonalizedFilter=a}applyFilters(t){this._onComplete(t),this._closeModal()}buildFilterModal(){const t=document.createElement("snk-filter-modal");return t.className="ez-size-height--full",t.filters=this._filterConfig,t.configName=this._configName,t.disablePersonalizedFilter=this._disablePersonalizedFilter,t.getMessage=this._getMessage.bind(this),t.applyFilters=this.applyFilters.bind(this),t.closeModal=()=>this._closeModal(),t.addPersonalizedFilter=()=>this._addPersonalizedFilterFn(),t.editPersonalizedFilter=t=>this._editPersonalizedFilterFn(t),t.deletePersonalizedFilter=(t,i)=>this._onDeletePersonalizedFilter(t,i),t}async showModal(){const t={content:this.buildFilterModal(),position:"left",heightMode:"full",closeOutsideClick:!1,useScrimLight:!0};this._closeModal=await _.showModal(t)}async closeModal(){this._closeModal()}}const C=class{constructor(e){t(this,e),this.configUpdated=i(this,"configUpdated",7),this._updateSequence=[],this._loadingPending=!1,this._configUpdated=!1,this._firstLoad=!0,this._pendingVariables=!1,this._customfiltersToBeUpdated=[],this._calculateSortIndex=t=>{if(!t.visible)return 0;if(t.hardFixed)return 1e6;let i=t.fixed?1e5:0;return i+=this.hasValidValue(t)?1e4:0,i+=this._updateSequence.lastIndexOf(t.id)+1,i},this._filtersComparator=(t,i)=>this._calculateSortIndex(i)-this._calculateSortIndex(t),this.customFilterBarConfig=void 0,this.dataUnit=void 0,this.title=void 0,this.configName=void 0,this.resourceID=void 0,this.mode="regular",this.filterConfig=void 0,this.messagesBuilder=void 0,this.disablePersonalizedFilter=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.allowDefault=void 0,this.scrollerLocked=!1,this.showPersonalizedFilter=!1,this.personalizedFilterId=void 0}hasValidValue(t){return null!=t.value&&(!Array.isArray(t.value)||t.value.some((t=>!0===t.check)))}observeFilterConfig(t,i){a.equals(t,i)||this.handleFilterConfigsChanged(i,t)}handleFilterConfigsChanged(t,i){if(null!=t&&null==i)this._loadingPending=!0,this._configUpdated=!0;else{const e=new Map(t?t.map((t=>[t.id,t])):void 0);0===e.size&&i.length>0?(this._loadingPending=!0,this._configUpdated=!1):i.forEach((t=>{const i=e.get(t.id);if(null!=i){if(this._configUpdated=this._configUpdated||a.objectToString(i)!=a.objectToString(t),this._loadingPending=this._loadingPending||a.objectToString(i.value)!==a.objectToString(t.value),!this._loadingPending){const e=a.objectToString(i.groupedItems)!=a.objectToString(t.groupedItems);this._configUpdated=this._configUpdated||e,this._loadingPending=this._loadingPending||e}}else this._configUpdated=!0,this._loadingPending=this._loadingPending||null!=t.value}))}(this._loadingPending||this._configUpdated)&&this.configUpdated.emit(i),this.processAfterUpdateConfig()}async reload(){this.loadConfigFromStorage(!0)}async getFilterItem(t){const i=this.filterConfig.find((i=>i.id===t));return Promise.resolve(a.copy(i))}async updateFilterItem(t){return-1==this.filterConfig.findIndex((i=>i.id===t.id))?(console.warn("[SnkFilterBar.updateFilterItem] FilterItem não encontrado, o mesmo não será atualizado."),Promise.resolve()):(this._loadingPending=!0,this.updateFilter(t),Promise.resolve())}async addFilterItem(t){return this.filterConfig.findIndex((i=>i.id===t.id))>-1?(console.warn("[SnkFilterBar.addFilterItem] FilterItem já existe , o mesmo não será adicionado novamente."),Promise.resolve()):(this.filterConfig.push(t),this._loadingPending=!0,this.updateFilter(t),Promise.resolve())}async removeFilterItem(t){const i=this.filterConfig.findIndex((i=>i.id===t));if(-1==i)return console.warn("[SnkFilterBar.removeFilterItem] FilterItem não encontrado"),Promise.resolve(void 0);const e=this.filterConfig[i];return this.filterConfig=this.filterConfig.filter((i=>i.id!==t)),Promise.resolve(e)}componentDidLoad(){this._element&&o.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}processPendingFilter(){if(this._pendingVariables){const t=this._element.querySelector("#filter-PERSONALIZED_FILTER_GROUP");t&&t.showUp(!0).then((()=>{this.processAfterUpdateConfig()}))}else this.processAfterUpdateConfig()}getPersonalizedFilterItem(){return this.filterConfig.find((t=>t.type===b.PERSONALIZED))}async processAfterUpdateConfig(){if(this._loadingPending){if(await this._application.isLoadedByPk()&&!this._configUpdated)return;const t=this.getPersonalizedFilterItem();if(this._pendingVariables=!F.validateVariableValues(t),this._pendingVariables)return;this._loadingPending=!1,this.doLoadData(null!=this.dataUnit.getLastLoadRequest())}this._configUpdated&&(this._configUpdated=!1,p.saveFilterBarConfig(this.filterConfig,this.configName,this.resourceID))}async doLoadData(t=!1){try{if(this._firstLoad&&!1===this.autoLoad)return;if(this._firstLoad&&!t&&void 0===this.autoLoad&&!await this._application.getBooleanParam("global.carregar.registros.iniciar.tela"))return;this.dataUnit.loadData(void 0,void 0,!0)}finally{this._firstLoad=!1}}getMessage(t,i,e){var s;return null==this.messagesBuilder&&this._application&&(this.messagesBuilder=this._application.messagesBuilder),(null===(s=this.messagesBuilder)||void 0===s?void 0:s.getMessage(t,i))||e}getFilter(t){var i;const e=[];return null===(i=this.filterConfig)||void 0===i||i.filter((t=>this.isActiveFilter(t))).forEach((t=>{const i=(t=>{switch(t.type){case b.DEFAULT_FILTER:return function(t){return{name:t.id,expression:t.props.expression,params:[]}}(t);case b.BINARY_SELECT:return function(t){const{id:i,value:e,props:s}=t;return{name:i,expression:s.options.find((t=>t.name===e)).expression,params:[]}}(t);case b.MULTI_SELECT:return function(t){const{id:i,value:e,props:s}=t;return{name:i,expression:s.expression,params:[{name:i,dataType:l.TEXT,value:e}]}}(t);case b.MULTI_LIST:return function(t){const{id:i,value:e,props:s}=t,r=(null!==(o=null!==(a=null==(n=e)?void 0:n.elements)&&void 0!==a?a:null==n?void 0:n.members)&&void 0!==o?o:n).filter((t=>null==t?void 0:t.check)).map((({id:t})=>Number.isNaN(+t)?String(t):Number(t)));var n,a,o;if(r.length>0)return{name:i,expression:s.expression,params:[{name:i,dataType:l.TEXT,value:JSON.stringify(r)}]}}(t);case b.PERIOD:return function(t){const{id:i,value:e,props:s}=t;let{end:r,start:n}=e;"string"==typeof r&&(r=new Date(r)),"string"==typeof n&&(n=new Date(n));const a=[];let o;return r&&n?(o=s.expression.fullfill,a.push({name:`${i}.START`,dataType:l.DATE,value:v(l.DATE,n)},{name:`${i}.END`,dataType:l.DATE,value:v(l.DATE,r)})):n?(o=s.expression.onlystart,a.push({name:i,dataType:l.DATE,value:v(l.DATE,n)})):(o=s.expression.onlyend,a.push({name:i,dataType:l.DATE,value:v(l.DATE,r)})),{name:i,expression:o,params:a}}(t);case b.SEARCH:return function(t){const{id:i,value:e,props:s}=t;return{name:i,expression:s.expression,params:[{name:i,dataType:l.TEXT,value:v(l.TEXT,e.value)}]}}(t);case b.TEXT:return function(t){let{id:i,value:e,props:s}=t;const r=s.expression;var a,o;return n.isEmpty(s.likeAs)||(a=e,e="CONTANIS"===(o=s.likeAs)?`%${a}%`:"STARTS_WITH"===o?`${a}%`:"ENDS_WITH"===o?`%${a}`:a),{name:i,expression:r,params:[{name:i,dataType:l.TEXT,value:v(l.TEXT,e)}]}}(t);case b.NUMBER:return function(t){const{id:i,value:e,props:s}=t;if(s.variation===g.INTERVAL){const{start:t,end:r}=null!=e?e:{start:0,end:0};if(t&&r)return{name:i,expression:s.intervalExpression.fullfill,params:[{name:`${i}.START`,dataType:l.NUMBER,value:v(l.NUMBER,t)},{name:`${i}.END`,dataType:l.NUMBER,value:v(l.NUMBER,r)}]};if(t)return{name:i,expression:s.intervalExpression.onlystart,params:[{name:i,dataType:l.NUMBER,value:v(l.NUMBER,t)}]};if(r)return{name:i,expression:s.intervalExpression.onlyend,params:[{name:i,dataType:l.NUMBER,value:v(l.NUMBER,r)}]}}return{name:i,expression:s.expression,params:[{name:i,dataType:l.NUMBER,value:v(l.NUMBER,e)}]}}(t);case b.PERSONALIZED:return function(t){const{id:i,groupedItems:e=[]}=t,s=e.filter((t=>!!t.visible)).map((t=>{var i;const e=t.props.expression,s=((null===(i=t.props.personalizedFilter)||void 0===i?void 0:i.parameters)||[]).map(((i,e)=>{const s=Array.from(t.value||0),r=i.dataType;let n=e>=0&&e<s.length?s[e]:null;return null!=n&&"object"==typeof n&&"value"in n&&(n=n.value),null==n&&r===l.BOOLEAN&&(n=!1),{name:i.name,dataType:r,value:"string"==typeof n?n:v(r,n)}}));return{expression:e,name:t.id,params:s}}));return{name:i,expression:s.map((t=>`(${t.expression})`)).join(` ${k.AND} `),params:s.flatMap((t=>t.params))}}(t);case b.CHECK_BOX_LIST:return function(t){var i;const{id:e,value:s,props:r}=t,l=Object.entries(null!=s?s:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t));return{name:e,expression:y(null===(i=r.options)||void 0===i?void 0:i.filter((t=>l.includes(t.name)))),params:[]}}(t);default:return}})(t);i&&e.push(i)})),e}isActiveFilter(t){return t.type===b.DEFAULT_FILTER||this.filterActiveFilter(t)&&(t.groupedItems||null!=t.value)}registryFilterProvider(){this.dataUnit.addFilterProvider(this),this.filterConfig&&this.doLoadData()}itemFocused(t){this._element.querySelectorAll("snk-filter-item,snk-filter-list").forEach((i=>{i.id===t?"snk-filter-item"===i.tagName.toLowerCase()&&i.getClientRects()[0].x<0&&i.scrollIntoView({behavior:"auto",inline:"nearest"}):i.hideDetail()}))}filterActiveFilter(t){return t.visible||t.removalBlocked}filterPersonalizedItems(t){return t.type===b.PERSONALIZED}getPersonalizedFilterVariableItems(){return this.filterConfig.filter(this.filterPersonalizedItems).map((t=>{const i=`filter-${t.id}`;return e("snk-filter-item",{key:t.id,id:i,config:Object.assign({},t),onFocusin:()=>this.itemFocused(i),onVisibleChanged:t=>this.scrollerLocked=t.detail,onFilterChange:t=>this.updateFilter(t.detail),getMessage:(t,i)=>this.getMessage(t,i),showChips:!1})}))}getFilterItems(){const t=[],i=[];this.filterConfig.sort(((t,i)=>this._filtersComparator(t,i))).filter(this.filterActiveFilter).forEach(((s,r)=>{const l=`filter-${(s=a.copy(s)).id}`,n=e("snk-filter-item",{onVisibleChanged:t=>this.scrollerLocked=t.detail,onFilterChange:t=>this.updateFilter(t.detail),onFocusin:()=>this.itemFocused(l),id:l,config:s,class:r>0?"ez-padding-left--medium":"",getMessage:(t,i)=>this.getMessage(t,i),key:s.id});return s.fixed||s.hardFixed?t.push(n):i.push(n),n}));const s=[];return s.push(...t),t.length>0&&i.length>0&&s.push(e("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-filter-bar__divider"})),s.push(...i),s}calculateUpdateSequence(t){t&&(this._updateSequence=this._updateSequence.filter((i=>t.id!==i)),this._updateSequence.push(t.id))}normalizeItem(t){const i=Object.assign({},t);return["props","value","hardFixed","fixed"].forEach((t=>{null==i[t]&&delete i[t]})),""===t.value&&delete t.value,i}updateFilter(t){this.filterConfig=this.filterConfig.map((i=>(t=this.normalizeItem(t),i.id===t.id?(a.objectToString(i)!=a.objectToString(t)&&this.calculateUpdateSequence(t),t):i))).sort(((t,i)=>this._filtersComparator(t,i)))}loadPermitions(){this._application.isUserSup().then((t=>this.allowDefault=t))}addFilterBarLegacyConfigName(){this.filterBarLegacyConfigName&&this.configName&&p.addFilterBarLegacyConfig(this.configName,this.filterBarLegacyConfigName)}async loadConfigFromStorage(t){try{let i;t&&await p.deleteFilterBarConfigCache(this.configName,this.resourceID),i=this.customFilterBarConfig?await this.customFilterBarConfig(this.configName,this.resourceID,{contextURI:this.dataUnit.name}):await p.loadFilterBarConfig(this.configName,this.resourceID,{contextURI:this.dataUnit.name}),this.filterConfig=i.map((t=>this.normalizeItem(t))),this.filterConfig.sort(((t,i)=>this._filtersComparator(t,i)))}catch(t){throw new h(this.getMessage("snkFilterBar.failToLoadConfig"),t)}}attachDataUnit(){if(null==this.dataUnit){let t=this._element.parentElement;for(;t;)if("SNK-DATA-UNIT"===t.tagName.toUpperCase()){const i=t;this.dataUnit=i.dataUnit,this.dataUnit?this.registryFilterProvider():i.addEventListener("dataUnitReady",(t=>{this.dataUnit=t.detail,this.registryFilterProvider()}));break}t=t.parentElement}else this.registryFilterProvider()}filterChangeListener(t){this.updateFilter(t.detail)}async showFilterModal(){let t=a.copy(this.filterConfig);t=t.sort(((t,i)=>t.originOrder-i.originOrder)),this._filterModalFactory=new w({filterConfig:t,configName:this.configName,onComplete:t=>{this.filterConfig=t.map(this.normalizeItem).sort(((t,i)=>this._filtersComparator(t,i)))},disablePersonalizedFilter:this.disablePersonalizedFilter,getMessage:(t,i)=>this.getMessage(t,i),onAddPersonalizedFilter:()=>this.addPersonalizedFilter(),onEditPersonalizedFilter:t=>this.editPersonalizedFilter(t),onDeletePersonalizedFilter:(t,i)=>this.deletePersonalizedFilter(t,b.PERSONALIZED,i)}),await this._filterModalFactory.showModal()}addPersonalizedFilter(){this._filterModalFactory.closeModal(),this.personalizedFilterId=void 0,this.showPersonalizedFilter=!0,window.requestAnimationFrame((()=>{this._elPersonalizedFilter.createPersonalizedFilter()}))}editPersonalizedFilter(t){this._filterModalFactory.closeModal(),this.showPersonalizedFilter=!0,this.personalizedFilterId=t}deletePersonalizedFilter(t,i,e){i===b.PERSONALIZED&&p.removePersonalizedFilter(t,this.resourceID,e)}handleHidePersonalizedFilter(t){t?this.loadConfigFromStorage().then((()=>{this.hidePersonalizedFilter()})):this.hidePersonalizedFilter()}hidePersonalizedFilter(){this.personalizedFilterId=void 0,this.showPersonalizedFilter=!1}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__"),this._application&&(this.loadPermitions(),this.addFilterBarLegacyConfigName(),this.loadConfigFromStorage()),this.attachDataUnit()}componentDidRender(){this.processPendingFilter()}render(){if(this.dataUnit&&this.filterConfig&&0!==this.filterConfig.length)return this.showPersonalizedFilter?e("snk-personalized-filter",{class:"filter-bar__personalized-filter",filterId:this.personalizedFilterId,ref:t=>this._elPersonalizedFilter=t,onEzCancel:()=>this.handleHidePersonalizedFilter(!1),onEzAfterSave:()=>this.handleHidePersonalizedFilter(!0),entityUri:this.dataUnit.name,configName:this.configName,resourceID:this.resourceID}):"regular"!==this.mode?e(s,{"data-mode":this.mode},this.getPersonalizedFilterVariableItems(),"button"===this.mode&&e("ez-button",{class:"ez-margin-left--medium",size:"small",label:this.getMessage("snkFilterBar.filters",void 0,"Filtros"),onClick:this.showFilterModal.bind(this)})):e(s,null,e("div",null,e("span",{class:"snk-filter-bar__title",title:this.title,"data-tooltip":this.title,"data-flow":"bottom"},this.title)),e("ez-scroller",{class:"snk-filter-bar__scroller",direction:f.HORIZONTAL,activeShadow:!0,locked:this.scrollerLocked},e("section",{class:"snk-filter-bar__filter-item-container"},this.getFilterItems())),e("ez-button",{class:"ez-padding-left--medium",size:"small",label:this.getMessage("snkFilterBar.filters",void 0,"Filtros"),onClick:this.showFilterModal.bind(this)},e("ez-icon",{slot:"leftIcon",iconName:"plus",class:"ez-padding-right--small"})))}get _element(){return r(this)}static get watchers(){return{filterConfig:["observeFilterConfig"]}}};C.style='.sc-snk-filter-bar-h{display:grid;grid-template-columns:1fr minmax(100px, 100%) 1fr 1fr;--snk-personalized-filter--z-index:var(--elevation--20, 20);--snk-personalized-filter--background-color:var(--background--xlight, #fff)}.snk-filter-bar__title.sc-snk-filter-bar{max-width:260px;display:inline-block;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:16px;font-family:var(--font-pattern, Arial);font-weight:var(--text-weight--large, 600);color:var(--color--title-primary, #2B3A54);margin-top:8px}[data-mode="hidden"].sc-snk-filter-bar-h{width:0px;height:0px}[data-mode="button"].sc-snk-filter-bar-h{grid-template-columns:1fr;width:fit-content}.snk-filter__popover-container.sc-snk-filter-bar{display:flex;cursor:auto}.filter-bar__personalized-filter.sc-snk-filter-bar{display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;overflow:auto;z-index:var(--snk-personalized-filter--z-index);background-color:var(--snk-personalized-filter--background-color)}.snk-filter__popover.sc-snk-filter-bar{display:flex;flex-direction:column;position:absolute;width:fit-content;height:fit-content;min-width:265px;background-color:var(--background--xlight, #fff);border-radius:var(--border--radius-medium, 12px);box-shadow:var(--shadow, 0px 0px 16px 0px #000)}.snk-filter-item__editor-header.sc-snk-filter-bar{flex-grow:1;font-weight:var(--text-weight--medium, 400);color:var(--color--title-primary, #2B3A54)}.snk-filter__popover-rule.sc-snk-filter-bar{border-style:solid;border-color:var(--color--disable-secondary, #F2F5F8);border-radius:1px;border-width:1px;width:100%}.editor__ez-check.sc-snk-filter-bar{--ez-check__label--padding-left:0}.snk-filter-item__editor-header-button.sc-snk-filter-bar{cursor:pointer;background-color:transparent;border:none;padding:3px;outline-color:var(--color--primary)}.snk-filter-bar__divider.sc-snk-filter-bar{margin-bottom:var(--space--small)}.snk-filter-bar__scroller.sc-snk-filter-bar{height:calc(100% + var(--space-extra-small, 3px))}.snk-filter-bar__filter-item-container.sc-snk-filter-bar{display:flex;align-items:start}.snk-filter-bar__scroller.sc-snk-filter-bar .sc-snk-filter-bar:first-child{margin-left:var(--space-extra-small, 3px)}.snk-filter-bar__filter-list-items-container.sc-snk-filter-bar{overflow-y:auto;max-height:360px;margin-top:var(--space--small, 6px)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar{cursor:pointer;border-radius:var(--border--radius-small, 6px);border:none;background-color:transparent}.snk-filter-bar__filter-list-item__label.sc-snk-filter-bar{color:var(--title--primary)}.snk-filter-bar__filter-list-item__label--secondary.sc-snk-filter-bar{color:var(--text--primary)}.snk-filter-bar__filter-list-item__icon.sc-snk-filter-bar{--ez-icon--color:var(--title--primary)}.snk-filter-bar__filter-list-item__icon--secondary.sc-snk-filter-bar{--ez-icon--color:var(--text--secondary)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar:focus-visible{outline:none;background-color:var(--background--medium)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar:hover{background-color:var(--background--medium)}.snk-filter-bar__filter-list-items-container--empty.sc-snk-filter-bar{width:100%;height:100px;display:flex;justify-content:center;align-self:center;align-items:center}.snk-filter-bar__filter-list-items-button--active.sc-snk-filter-bar{position:relative}.snk-filter-bar__filter-list-items-button--active.sc-snk-filter-bar::after{display:flex;position:absolute;content:"";width:8px;height:8px;top:7px;left:17px;background-color:var(--icon--alert--color, #008561);border-radius:50%}.snk-filter-bar__filter-modal-item.sc-snk-filter-bar{--modal-item-border-width:2px;display:flex;flex-direction:row;margin-left:var(--modal-item-border-width);border-radius:var(--border--radius-medium, 12px);background-color:var(--background--medium, #f0f3f7);border:none;width:100%}.snk-filter-bar__filter-modal-item.sc-snk-filter-bar:focus-visible{outline:var(--color--primary) solid var(--modal-item-border-width)}.snk-filter-bar__filter-modal-item__check.sc-snk-filter-bar{width:auto}.snk-filter-bar__filter-modal-item__label.sc-snk-filter-bar{font-weight:var(--text-weight--medium)}.snk-filter-bar__filter-modal-content.sc-snk-filter-bar{display:grid;grid-template-rows:auto auto 1fr auto;width:99%;height:100%}';const $=class{constructor(e){t(this,e),this.visibleChanged=i(this,"visibleChanged",7),this.filterChange=i(this,"filterChange",3),this.innerClickCheck=(t,i)=>i.id!=c.MODAL_ELEMENT_ID||(this.detailIsVisible=!1,!1),this.detailIsVisible=void 0,this.config=void 0,this.getMessage=void 0,this.showChips=!0}observeDetailIsVisible(t){this.visibleChanged.emit(t)}async showUp(t=!1){return new Promise((i=>{this._filterItemElement.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}),t&&(this._closeCallback=i,window.requestAnimationFrame((()=>{this._floatingID=c.float(this._popover,this._popoverContainer,this.getFloatOptions()),this._popover.show(),this.detailIsVisible=!0})))}))}updatePosition(){null!=this._floatingID&&c.updateFloatPosition(this._popover,this._popoverContainer,this.getFloatOptions())}getFloatOptions(){return{autoClose:!0,innerClickTest:this.innerClickCheck,backClickListener:()=>this.onDetailCloseCallback(),left:this.getOffsetLeft(),top:this.getOffsetTop(),useOverlay:!0,overlayClassName:"ez-scrim ez-scrim--light",isFixed:!0}}getOffsetLeft(){const t=getComputedStyle(this._filterItemElement).getPropertyValue("padding-left"),i=this._filterItemElement.getBoundingClientRect(),e=430-(document.body.clientWidth-i.left);return`calc(${i.x}px + ${t} - ${e>0?e:0}px)`}getOffsetTop(){const t=this._filterItemElement.getBoundingClientRect();return t.y+t.height+"px"}controlScrollPage(){window.removeEventListener("scroll",this.updatePosition.bind(this)),window.addEventListener("scroll",this.updatePosition.bind(this))}getConfigChanges(){var t;const i=this.config;(null===(t=i.groupedItems)||void 0===t?void 0:t.length)&&(i.visible=!1,i.groupedItems=i.groupedItems.map((t=>Object.assign(Object.assign({},t),{visible:!1}))));const e=i.type===b.MULTI_LIST&&Array.isArray(i.value)?i.value.map((t=>Object.assign(Object.assign({},t),{check:!1}))):void 0;return Object.assign(Object.assign({},i),{value:e})}async hideDetail(){this.detailIsVisible&&null!=this._floatingID&&c.close(this._floatingID)}onDetailCloseCallback(){this._floatingID=void 0,this.detailIsVisible=!1,this._closeCallback&&(this._closeCallback(),this._closeCallback=void 0)}clickListener(t){if([this._chipElement,this._leftIconElement,this._rightIconElement].includes(t.target)){if(t.target===this._rightIconElement&&this.canClearFilter()){const t=this.getConfigChanges();this.filterChange.emit(t)}else this.detailIsVisible?this.hideDetail():this.showUp(!0);t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation()}}mouseDownListener(t){this.detailIsVisible&&[this._chipElement,this._leftIconElement,this._rightIconElement].includes(t.target)&&(t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation())}getLabel(t=!1){var i,e;const{type:s,value:r,label:l,props:n,groupedItems:a=[]}=this.config;if(r||a.length){if(s===b.BINARY_SELECT){const[i,e]=n.options,s=this.getMessage("snkFilterBar.binarySelectTooltip");if(i.name===r)return t?`${s} ${String(i.label).toLowerCase()}`:i.label;if(e.name===r)return t?`${s} ${String(e.label).toLowerCase()}`:e.label}if(s===b.MULTI_SELECT)return`${l}: ${n.options.find((t=>t.value===r)).label}`;if(s===b.PERIOD){let{end:i,start:e}=r;"string"==typeof i&&(i=new Date(i),i.setMinutes(i.getMinutes()+i.getTimezoneOffset())),"string"==typeof e&&(e=new Date(e),e.setMinutes(e.getMinutes()+e.getTimezoneOffset()));const s=new Intl.DateTimeFormat("pt-BR");if(i&&e){const s=e.getFullYear()===i.getFullYear(),r=Object.assign({day:"2-digit",month:"2-digit"},(!s||t)&&{year:"2-digit"}),n=u.formatDate(e,r),a=u.formatDate(i,r);return t?this.getMessage("snkFilterBar.fullPeriodTooltip",{LABEL:l,START_LABEL:n,END_LABEL:a}):`${l}: ${n} → ${a}`}return e?`${l}: ${this.getMessage("snkFilterBar.onlyStartToltip")} ${s.format(e)}`:i?`${l}: ${this.getMessage("snkFilterBar.onlyEndToltip")} ${s.format(i)}`:l}if(s===b.SEARCH)return`${l}: ${r.value} - ${r.label}`;if(s===b.PERSONALIZED){const t=this.calculateActiveCount(a);return t<=0?l:`${l}: ${this.getMessage("snkFilterBar.personalizedCount",{activeCount:t})}`}if(s===b.MULTI_LIST){const e=(null!==(i=r.elements)&&void 0!==i?i:r).filter((t=>null==t?void 0:t.check));return this.getLabelFromCheckedOptions(e,l,t)}if(s===b.CHECK_BOX_LIST){const i=Object.entries(null!=r?r:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t)),s=(null!==(e=n.options)&&void 0!==e?e:[]).filter((t=>i.includes(t.name)));return this.getLabelFromCheckedOptions(s,l,t)}if(s===b.NUMBER&&n.variation===g.INTERVAL){const{start:t,end:i}=r;if(t&&i)return this.getMessage("snkFilterBar.fullIntervalTooltip",{LABEL:l,START_LABEL:t,END_LABEL:i});if(t)return`${l}: ${this.getMessage("snkFilterBar.onlyStartToltip")} ${Number(t)}`;if(i)return`${l}: ${this.getMessage("snkFilterBar.onlyEndToltip")} ${Number(i)}`}return`${l}: ${r}`}return l}getLabelFromCheckedOptions(t,i,e){const s=t.length;return 0===s?`${i}`:s>1?e?`${i}: ${t.map((t=>t.label)).join(",")}`:`${i}: ${s} ${this.getMessage("snkFilterBar.multiListToltip")}`:`${i}: ${t[0].label}`}calculateActiveCount(t){return t.reduce(((t,i)=>i.visible?t+1:t),0)}componentDidLoad(){this._filterItemElement&&(o.addIDInfo(this._filterItemElement),this._idSnkFilterDetail=`filterDetail_${this.config.id}`),this.controlScrollPage()}componentDidRender(){null==this._floatingID&&this._popover&&this._popover.remove()}filterChangeListener(){this.hideDetail()}canClearFilter(){const{value:t,groupedItems:i=[]}=this.config;return null!=t&&this.config.type===b.MULTI_LIST?t.some((t=>t.check)):void 0!==t||i.some((t=>t.visible))}getRightIconName(){return this.canClearFilter()?"close":this.detailIsVisible?"chevron-up":"chevron-down"}getLeftIconName(){switch(this.config.type){case b.PERIOD:return"calendar";case b.PERSONALIZED:return"tune"}}hasActiveElements(t){var i,e,s;return(null===(s=null===(e=null!==(i=null==t?void 0:t.elements)&&void 0!==i?i:t)||void 0===e?void 0:e.filter((t=>null==t?void 0:t.check)))||void 0===s?void 0:s.length)>0}hasActiveValue(t){return t.type!==b.MULTI_LIST&&void 0!==t.value||this.hasActiveElements(t.value)}getEnabledChip(){if(this.config.type===b.PERSONALIZED){const{groupedItems:t=[]}=this.config;return t.some((t=>t.visible))}return this.hasActiveValue(this.config)}render(){const t=this.getLeftIconName();return e(s,null,this.showChips&&e("ez-chip",{id:this.config.id,ref:t=>this._chipElement=t,label:this.getLabel(),value:this.getEnabledChip()},t&&e("ez-icon",{ref:t=>this._leftIconElement=t,iconName:t,class:"ez-padding-right--small",slot:"leftIcon"}),e("ez-icon",{ref:t=>this._rightIconElement=t,iconName:this.getRightIconName(),class:"ez-padding-left--small",slot:"rightIcon",id:"removeFilter"})),e("section",{class:"ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container",ref:t=>this._popoverContainer=t},e("snk-filter-detail",{config:this.config,getMessage:this.getMessage,class:"sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--16",ref:t=>this._popover=t,key:this.config.id,"data-element-id":this._idSnkFilterDetail,showHardFixed:this.showChips})))}get _filterItemElement(){return r(this)}static get watchers(){return{detailIsVisible:["observeDetailIsVisible"]}}},I="__SHOWMORE__",L=class{constructor(e){t(this,e),this.snkItemSelected=i(this,"snkItemSelected",7),this._preselection=-1,this.innerClickCheck=(t,i)=>i.id!=c.MODAL_ELEMENT_ID||(this._detailIsVisible=!1,!1),this._filterArgument=void 0,this._showAll=void 0,this.label=void 0,this.iconName=void 0,this.items=void 0,this.getMessage=void 0,this.emptyText=void 0,this.findFilterText=void 0,this.buttonClass=void 0}showDetail(){this._preselection=-1,this._floatingID=c.float(this._popover,this._popoverContainer,{autoClose:!0,innerClickTest:this.innerClickCheck,backClickListener:()=>this.onListCloseCallback(),useOverlay:!0}),this._detailIsVisible=!0,this._showAll=!1,this._filterArgument="",this._filterInput.setFocus()}async hideDetail(){null!=this._floatingID&&c.close(this._floatingID)}onListCloseCallback(){this._floatingID=void 0,this._detailIsVisible=!1}buttonClick(){this._detailIsVisible?this.hideDetail():this.showDetail()}componentDidLoad(){this._element&&o.addIDInfo(this._element)}componentDidRender(){null==this._floatingID&&this._popover&&this._popover.remove()}buildIdElement(t,i){if(!t)return;const e={id:i};t.removeAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME),o.addIDInfoIfNotExists(t,"filterItemList",e)}buildItemElement(t){const i=++this._selectableItemsCount;return e("button",{ref:i=>i&&this.buildIdElement(i,t.label),id:`filter-item${i}`,onFocusin:()=>this._preselection=i,class:"ez-col ez-col--sd-12 ez-align--middle ez-padding--small sc-snk-filter-bar snk-filter-bar__filter-list-item",onClick:()=>this.itemSelected(t.name),name:t.label,key:i},t.iconName?e("ez-icon",{iconName:t.iconName,size:"small",class:`ez-padding-right--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__icon ${t.iconClass||""}`}):void 0,e("div",{class:`ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__label ${t.labelClass||""}`},t.label))}itemSelected(t){t===I?this._showAll=!0:(this.hideDetail(),this.snkItemSelected.emit(t))}getFilterItems(){const t=this.items?m.applyStringFilter(this._filterArgument,this.items.filter((t=>"FILTER"===t.kind))):[];return 0===t.length?e("div",{class:"ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-items-container--empty"},this.emptyText):(!this._filterArgument&&!this._showAll&&t.length>6&&(t.splice(5),t.push({kind:"INTERNAL",label:"Mostrar mais",iconName:"dots-horizontal",name:I,iconClass:"snk-filter-bar__filter-list-item__icon--secondary",labelClass:"snk-filter-bar__filter-list-item__label--secondary"})),this._selectableItemsCount=0,e("div",{class:"sc-snk-filter-bar snk-filter-bar__filter-list-items-container"},t.map((t=>this.buildItemElement(t)))))}getFooterItems(){return this.items.filter((t=>"FOOTER"===t.kind))}keyDownHandler(t){switch(t.key){case"ArrowDown":this.changePreselection(this._preselection+1),t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault();break;case"ArrowUp":this.changePreselection(this._preselection-1),t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault()}}changePreselection(t){if(t<0&&(t=this._selectableItemsCount),this._preselection=t>this._selectableItemsCount?0:t,0===this._preselection)this._filterInput.setFocus();else{const t=this._element.querySelector(`#filter-item${this._preselection}`);t&&t.focus()}}render(){return e(s,{class:"ez-flex ez-flex--column"},e("ez-button",{class:this.buttonClass,label:this.label,onClick:()=>this.buttonClick(),mode:this.iconName?"icon":void 0,iconName:this.iconName,size:"small"},e("slot",{name:"leftIcon"})),e("section",{class:"ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container",ref:t=>this._popoverContainer=t},e("div",{class:"sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--4",ref:t=>this._popover=t},e("ez-filter-input",{ref:t=>this._filterInput=t,"data-element-id":"serachFilters",mode:"slim",label:this.findFilterText,value:this._filterArgument,onEzChange:t=>this._filterArgument=t.detail,onFocus:()=>this._preselection=0}),this.getFilterItems(),e("hr",{class:"sc-snk-filter-bar snk-filter__popover-rule"}),this.items?this.getFooterItems().map((t=>this.buildItemElement(t))):void 0)))}get _element(){return r(this)}},T=class{constructor(i){t(this,i),this.getMessage=void 0,this.configName=void 0,this.filters=void 0,this.applyFilters=void 0,this.closeModal=void 0,this.addPersonalizedFilter=void 0,this.editPersonalizedFilter=void 0,this.deletePersonalizedFilter=void 0,this.filtersToDelete=[],this.disablePersonalizedFilter=void 0}deletePersonalizedFilterListener(t){this.filtersToDelete.push(t.detail)}getCustomMessage(t,i){var e;return null===(e=this.getMessage)||void 0===e?void 0:e.call(this,`snkFilterBar.filterModal.${t}`,i)}handleClearAll(){const{customFilters:t,quickFilters:i,otherFilters:e,multiListFilters:s}=this.filters.reduce(((t,i)=>i.type===b.MULTI_LIST?(t.multiListFilters.push(i),t):i.filterType===z.QUICK_FILTER?(t.quickFilters.push(i),t):i.filterType===z.CUSTOM_FILTER?(t.customFilters.push(i),t):i.filterType===z.OTHER_FILTERS?(t.otherFilters.push(i),t):t),{quickFilters:[],customFilters:[],otherFilters:[],multiListFilters:[]});this.handleClearFilterList(i),this.handleClearCustomFilters(t),this.handleClearOthersFilters(e),s.forEach((t=>this.handleClearSigleFilter(t)))}handleClearOthersFilters(t){this.filters=this.filters.map((i=>t.includes(i)?Object.assign(Object.assign({},i),{value:void 0}):i))}handleClearCustomFilters(t){this.filters.forEach(((i,e)=>{i.filterType===z.CUSTOM_FILTER&&(this.filters[e]=this.clearAllCustomFilter(t).shift())}))}clearAllCustomFilter(t){return t.map((t=>{const i=Object.assign({},t);return delete i.value,i.visible=!1,i.groupedItems&&(i.groupedItems=this.clearAllCustomFilter(i.groupedItems)),i}))}handleClose(){if(a.objectToString(this.filters)!==a.objectToString(this._originalFilterConfig))return _.confirm(this.getCustomMessage("validations.notSaved.title"),this.getCustomMessage("validations.notSaved.message")).then((t=>{t&&this.closeModal()}));this.closeModal()}handleApplyFilters(){const t=this.filters.find((t=>t.filterType===z.CUSTOM_FILTER));this.isValidCustomFilter(t)&&this.applyFilters(this.filters),this.filtersToDelete.length>0&&(this.filtersToDelete.forEach((t=>{this.deletePersonalizedFilter(t,this.configName)})),this.filtersToDelete=[])}isValidCustomFilter(t){return!!F.validateVariableValues(t)||(_.alert(this.getCustomMessage("validations.notFullFilled.title"),this.getCustomMessage("validations.notFullFilled.message")),!1)}modalActionListener(t){switch(t.detail){case x.CANCEL:this.handleClearAll();break;case x.OK:this.handleApplyFilters();break;case x.CLOSE:this.handleClose()}}handleFilterChange(t){this.filters=this.filters.map((i=>i.id===t.id?t:i))}handleClearFilterList(t){this.filters=this.filters.map((i=>t.includes(i)?Object.assign(Object.assign({},i),{value:void 0}):i))}handleClearSigleFilter(t){if(b.MULTI_LIST===t.type){let i=a.copy(t);this.uncheckFilterValues(i.value);const e=a.copy(this.filters),s=e.findIndex((i=>i.id===t.id));return e.splice(s,1,i),void(this.filters=a.copy(e))}if(b.CHECK_BOX_LIST===t.type){const i=a.copy(this.filters);return i.find((i=>i.id===t.id)).value=void 0,void(this.filters=a.copy(i))}this.filters.find((i=>i.id===t.id)).value=void 0}uncheckFilterValues(t){return t.forEach((t=>{t&&(t.check=!1)})),t}renderFilterItem(t,i){return e("snk-filter-modal-item",{class:i?"ez-col ez-col--sd-12":"ez-col ez-col--sd-6 ez-padding--small",filterItem:t,configName:this.configName,onFilterChange:t=>this.handleFilterChange(t.detail),onEditPersonalizedFilter:t=>this.editPersonalizedFilter(t.detail),onAddPersonalizedFilter:()=>this.addPersonalizedFilter()})}isDefaultFilterNumberVariation(t){var i;return t.type===b.NUMBER&&(!t.props.variation||(null===(i=t.props)||void 0===i?void 0:i.variation)===g.DEFAULT)}mountFiltersLines(t){let i=0,e=!1;const s={};for(let r=0;r<t.length;r++){s[i]=s[i]||[];const l=t[r],n=r===t.length-1,a=l.type===b.TEXT||this.isDefaultFilterNumberVariation(l),o=!n&&(t[r+1].type===b.TEXT||this.isDefaultFilterNumberVariation(t[r+1]));a&&o||e?(s[i].push(l),e=s[i].length<2,2===s[i].length&&++i):(s[i]=s[i]||[],s[i].push(l),++i)}return Object.values(s)}renderFilterLine(t){const i=1===t.length;return t.map((t=>this.renderFilterItem(t,i)))}getIformedFiltersCount(t){let i=0;return t.forEach((t=>{var e,s,r,l,n,a;b.MULTI_LIST!==t.type?b.CHECK_BOX_LIST!==t.type?null==t.groupedItems?t.value&&i++:i=t.groupedItems.filter((t=>t.visible)).length:i+=Object.entries(null!==(a=t.value)&&void 0!==a?a:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t)).length:i+=null!==(n=null===(l=null===(r=null!==(s=null===(e=t.value)||void 0===e?void 0:e.elements)&&void 0!==s?s:t.value)||void 0===r?void 0:r.filter((t=>null==t?void 0:t.check)))||void 0===l?void 0:l.length)&&void 0!==n?n:0})),i}renderCollapsibleFilterBox(t,i,s,r=!0){if(!i.length)return null;const l=this.getIformedFiltersCount(i),n=this.mountFiltersLines(i);return e("ez-collapsible-box",{class:"snk-filter-modal__collapsible-box",headerSize:"medium",value:!0,label:t},!!l&&e("ez-badge",{class:"ez-badge--primary-subtle",slot:"rightSlot",label:null==l?void 0:l.toString()}),e("div",{class:"ez-row snk-filter-modal__rendered-items"},n.map(this.renderFilterLine.bind(this))),r&&e("div",{class:"ez-flex ez-flex--justify-end grow"},e("ez-button",{class:"ez-button--tertiary",size:"medium",label:"Limpar",onClick:()=>s?this.handleClearSigleFilter(i[0]):this.handleClearFilterList(i)})))}componentWillRender(){this._modalTitle=this.getCustomMessage("title"),this._okButtonLabel=this.getCustomMessage("okButtonLabel"),this._cancelButtonLabel=this.getCustomMessage("cancelButtonLabel")}componentDidLoad(){this._originalFilterConfig||(this._originalFilterConfig=this.filters)}render(){const t=this.filters.filter((t=>t.filterType===z.CUSTOM_FILTER)),i=this.filters.filter((t=>t.filterType===z.QUICK_FILTER)),s=this.filters.filter((t=>t.filterType===z.OTHER_FILTERS));return e("ez-modal-container",{class:"snk-filter-modal__container",modalTitle:this._modalTitle,cancelButtonLabel:this._cancelButtonLabel,okButtonLabel:this._okButtonLabel,onEzModalAction:this.modalActionListener.bind(this)},e("div",{class:"snk-filter-modal__content ez-col--sd-12"},!this.disablePersonalizedFilter&&this.renderCollapsibleFilterBox(this.getCustomMessage("customFilters"),t,!1,!1),this.renderCollapsibleFilterBox(this.getCustomMessage("quickFilters"),i,!1),s.map((t=>this.renderCollapsibleFilterBox(t.label,[t],!0)))))}};T.style="ez-modal{--ez-modal-content-padding:24px 12px}.snk-filter-modal__container{width:344px;max-width:344px;min-width:344px;overflow:hidden}.snk-filter-modal__content{display:flex;flex-direction:column;gap:var(--space--medium, 12px);padding-right:var(--space--3xs, 4px)}.snk-filter-modal__collapsible-box{border:var(--border--small, 1px solid) var(--color--strokes, #DCE0E8);border-radius:var(--border--radius-medium);padding:var(--space--medium, 12px) var(--space--small, 6px)}.snk-filter-modal__rendered-items{max-height:760px;overflow-x:clip;overflow-y:auto}.snk-filter-modal__rendered-items::-webkit-scrollbar{width:var(--space--small);min-width:var(--space--small);max-width:var(--space--small)}";export{C as snk_filter_bar,$ as snk_filter_item,L as snk_filter_list,T as snk_filter_modal}
@@ -1 +1 @@
1
- import{r as t,c as i,h as e}from"./p-d2d301a6.js";import{ApplicationContext as a,DataType as s,Action as n,UserInterface as o,StringUtils as r,DataUnit as h}from"@sankhyalabs/core";import{D as l}from"./p-f3434fc4.js";import"./p-8a9638ae.js";import"./p-30cf616e.js";import{S as d}from"./p-21749402.js";import{P as c,b as u,D as m,I as v}from"./p-47bce500.js";import"./p-ff1990ad.js";import"./p-06421fdb.js";import{d as A}from"./p-b0ef4383.js";import{A as O}from"./p-ca5ec380.js";import{T as p}from"./p-7e7a7473.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-6dc031de.js";class w{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:e,operation:a}){var s,n;const o="INSERT"==a,r=o?e:i;if(!o&&(null==e?void 0:e.DESCRICAO)&&(null==e?void 0:e.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(d.DESCRIPTION_CANNOT_BE_CHANGED);const h={anexo:{codata:o?null==e?void 0:e.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(n=null===(s=e.CAMINHO_ARQUIVO)||void 0===s?void 0:s[0])||void 0===n?void 0:n.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,a)=>{l.get().callServiceBroker("Attach.save",JSON.stringify(h)).then((a=>{var s;return i([Object.assign(Object.assign(Object.assign({},a),e),{__owner__dataunit__name__:null!==(s=this.dataUnitName)&&void 0!==s?s:t})])})).catch((t=>a(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const e=await l.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(e)}async getDownloadKey(t){var i,e,a;if("S"==t.EHARQUIVOREPOSITORIO){const a={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},s=await l.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(a));return Promise.resolve({chave:{valor:null===(e=null===(i=null==s?void 0:s.responseBody)||void 0===i?void 0:i.chave)||void 0===e?void 0:e.valor}})}const s={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},n=await l.get().callServiceBroker("Attach.view",JSON.stringify(s));return(null==n?void 0:n.chaveAnexo)?Promise.resolve({chave:{valor:null===(a=null==n?void 0:n.chaveAnexo)||void 0===a?void 0:a.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const I="AnexoSistemaSP.salvar",_="AnexoSistemaSP.excluir",S="AnexoSistemaSP.baixar";class k{constructor(t,i){var e;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(d.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(d.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(e=window.workspace)||void 0===e?void 0:e.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,e;let{updatingFields:a}=t;a=Object.assign(Object.assign({},a),{NOMEARQUIVO:null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(a);const t=a.LINK?null:a.NOMEARQUIVO,i={serviceName:I,requestBody:{params:{resourceID:this.resourceID,description:a.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:a.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:a.TIPOACESSO,typeApres:a.TIPOAPRES}}},s=await l.get().callServiceBroker(I,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},s),a),{ARQUIVOOULINK:a.LINK?a.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,e,a;let{updatingFields:s,record:n}=t;const o=t=>void 0!==s[t]?s[t]:n[t],r=o("NOMEARQUIVO"),h=null===(e=null===(i=s.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.downloadURL;s=Object.assign(Object.assign({},s),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:n.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const d=s.LINK?null:s.NOMEARQUIVO;try{this.validateFields(s);const t={serviceName:I,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==n?void 0:n.NUATTACH,description:s.DESCRICAO,fileSelect:h?1:0,keySession:null===(a=null==d?void 0:d.properties)||void 0===a?void 0:a.fileNameTmp,keyAttach:s.CHAVEARQUIVO,nameAttach:null==d?void 0:d.name,link:s.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:s.TIPOACESSO,typeApres:s.TIPOAPRES}}},i=await l.get().callServiceBroker(I,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),s),{ARQUIVOOULINK:s.LINK?s.LINK:null==d?void 0:d.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:_,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{l.get().callServiceBroker(_,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:S,requestBody:{paramsDown:{nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{l.get().callServiceBroker(S,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}}class y{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var a;const s=Array.isArray(t)?t[0]:{};((null===(a=null==s?void 0:s.record)||void 0===a?void 0:a.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(s).then((t=>{e(t)})).catch((t=>t.message===d.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===d.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{const{records:s}=t.getSelectionInfo(),n=s[0];e.delete(n).then((()=>(c.removeRecords(t,[n]),a(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:s.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const b=a.getContextValue("__SNK__APPLICATION__"),f=t=>{var i,e;return null===(e=null===(i=null==b?void 0:b.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},E={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},N={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:f("snkAttach.attachMetadata.lblCode"),dataType:s.TEXT},{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),dataType:s.TEXT,readOnly:!1},{name:"ARQUIVO",label:f("snkAttach.attachMetadata.lblFileOrLink"),dataType:s.TEXT},{name:"USUARIO",label:f("snkAttach.attachMetadata.lblUser"),dataType:s.TEXT},{name:"DTALTER",label:f("snkAttach.attachMetadata.lblDate"),dataType:s.TEXT},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFileUpload"),dataType:s.OBJECT,userInterface:o.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:f("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class g{constructor(t){this.getMessage=t,this._records=[],this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){return Promise.resolve(N)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},e=await this._application.getDataFetcher(),{anexos:{anexo:a=[]}}=await e.callServiceBroker("Attach.load",JSON.stringify(t)),s=[];a.forEach((t=>{s.push(Object.assign({__record__id__:r.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=s}return u(this._records,t,i)}saveLoader(t,i){return new Promise((e=>{const a=Array.isArray(t)?t[0]:{};i.save(a).then(e).catch((t=>t.message===d.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),e([])):t.message===d.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===d.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(O.REMOVE).then((async s=>{s&&(await e.delete(t),a(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const C=a.getContextValue("__SNK__APPLICATION__"),P=t=>{var i,e;return null===(e=null===(i=null==C?void 0:C.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},T={DOWNLOAD:{hint:P("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:P("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},L=()=>{const t=[p.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,e)=>{if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();e.splice(e.indexOf(p.REFRESH),1);const{selectedRecord:a}=i||{},s=(null==a?void 0:a.LINK)?T.LINK:T.DOWNLOAD;e.splice(e.indexOf(p.DIVIDER)+1,0,p.REMOVE,s,p.DIVIDER);const n=Array.from(new Set(e.filter((t=>t!==p.CLONE))));return n.splice(n.indexOf(s)+1,0,p.DIVIDER),n},isEnabled:(i,e,a)=>{const s=void 0!==(null==e?void 0:e.selectedRecord);return!(t.includes(a)&&!s)}}},R={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},x=class{constructor(e){t(this,e),this.back=i(this,"back",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.back.emit()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.back.emit();this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.back.emit()}))},this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0}async registerKeyWatcher(t,i){var e;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof k&&(this._currentFetcher.registerKey=t),await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new k(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,e,a,s;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(e=this.registerKey)||void 0===e?void 0:e.split("_").length)>1)return;await(null===(a=this._currentDataUnit)||void 0===a?void 0:a.loadMetadata()),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var e;let a=!1;(null===(e=null==t?void 0:t.ARQUIVO)||void 0===e?void 0:e.endsWith(".pdf"))||(a=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${a?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;this._currentDataUnit=(new m).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},R)),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm()}async loadAttach(){var t,i;this._currentFetcher=new w,this._currentDataUnit=new h(v.IN_MEMORY_DATA_UNIT_NAME),this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===n.METADATA_LOADED&&(this.crudConfig=Object.assign({},E),null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},E),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm())}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new y(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new w,this._currentDataUnitBuilder=new g(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this._currentDataUnit.disableField(e)}))}async componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),await this.initAttach()}componentWillRender(){this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}render(){var t,i;return this._currentDataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:L(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this)},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary ez-padding-bottom--medium"},this.getMessage("snkAttach.description")))))))):null}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};x.style=".snk-attach__header.sc-snk-attach,.snk-attach__crud-section.sc-snk-attach{padding:0 var(--space--lg)}.snk-attach__file-info.sc-snk-attach{padding:var(--space--small);max-width:50%}.snk-attach__main.sc-snk-attach{height:85%}.ez-box__container.sc-snk-attach{height:100%}";export{x as snk_attach}
1
+ import{r as t,c as i,h as e}from"./p-d2d301a6.js";import{ApplicationContext as a,DataType as s,Action as n,UserInterface as o,StringUtils as r,DataUnit as h}from"@sankhyalabs/core";import{D as l}from"./p-f3434fc4.js";import"./p-8a9638ae.js";import"./p-30cf616e.js";import{S as d}from"./p-21749402.js";import{P as c,b as u,D as m,I as v}from"./p-47bce500.js";import"./p-ff1990ad.js";import"./p-06421fdb.js";import{V as A}from"./p-95ce311a.js";import{A as O}from"./p-ca5ec380.js";import{T as p}from"./p-7e7a7473.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-6dc031de.js";class w{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:e,operation:a}){var s,n;const o="INSERT"==a,r=o?e:i;if(!o&&(null==e?void 0:e.DESCRICAO)&&(null==e?void 0:e.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(d.DESCRIPTION_CANNOT_BE_CHANGED);const h={anexo:{codata:o?null==e?void 0:e.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(n=null===(s=e.CAMINHO_ARQUIVO)||void 0===s?void 0:s[0])||void 0===n?void 0:n.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,a)=>{l.get().callServiceBroker("Attach.save",JSON.stringify(h)).then((a=>{var s;return i([Object.assign(Object.assign(Object.assign({},a),e),{__owner__dataunit__name__:null!==(s=this.dataUnitName)&&void 0!==s?s:t})])})).catch((t=>a(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const e=await l.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(e)}async getDownloadKey(t){var i,e,a;if("S"==t.EHARQUIVOREPOSITORIO){const a={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},s=await l.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(a));return Promise.resolve({chave:{valor:null===(e=null===(i=null==s?void 0:s.responseBody)||void 0===i?void 0:i.chave)||void 0===e?void 0:e.valor}})}const s={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},n=await l.get().callServiceBroker("Attach.view",JSON.stringify(s));return(null==n?void 0:n.chaveAnexo)?Promise.resolve({chave:{valor:null===(a=null==n?void 0:n.chaveAnexo)||void 0===a?void 0:a.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const I="AnexoSistemaSP.salvar",_="AnexoSistemaSP.excluir",S="AnexoSistemaSP.baixar";class k{constructor(t,i){var e;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(d.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(d.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(e=window.workspace)||void 0===e?void 0:e.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,e;let{updatingFields:a}=t;a=Object.assign(Object.assign({},a),{NOMEARQUIVO:null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(a);const t=a.LINK?null:a.NOMEARQUIVO,i={serviceName:I,requestBody:{params:{resourceID:this.resourceID,description:a.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:a.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:a.TIPOACESSO,typeApres:a.TIPOAPRES}}},s=await l.get().callServiceBroker(I,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},s),a),{ARQUIVOOULINK:a.LINK?a.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,e,a;let{updatingFields:s,record:n}=t;const o=t=>void 0!==s[t]?s[t]:n[t],r=o("NOMEARQUIVO"),h=null===(e=null===(i=s.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.downloadURL;s=Object.assign(Object.assign({},s),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:n.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const d=s.LINK?null:s.NOMEARQUIVO;try{this.validateFields(s);const t={serviceName:I,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==n?void 0:n.NUATTACH,description:s.DESCRICAO,fileSelect:h?1:0,keySession:null===(a=null==d?void 0:d.properties)||void 0===a?void 0:a.fileNameTmp,keyAttach:s.CHAVEARQUIVO,nameAttach:null==d?void 0:d.name,link:s.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:s.TIPOACESSO,typeApres:s.TIPOAPRES}}},i=await l.get().callServiceBroker(I,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),s),{ARQUIVOOULINK:s.LINK?s.LINK:null==d?void 0:d.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:_,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{l.get().callServiceBroker(_,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:S,requestBody:{paramsDown:{nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{l.get().callServiceBroker(S,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}}class y{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var a;const s=Array.isArray(t)?t[0]:{};((null===(a=null==s?void 0:s.record)||void 0===a?void 0:a.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(s).then((t=>{e(t)})).catch((t=>t.message===d.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===d.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{const{records:s}=t.getSelectionInfo(),n=s[0];e.delete(n).then((()=>(c.removeRecords(t,[n]),a(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:s.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const b=a.getContextValue("__SNK__APPLICATION__"),f=t=>{var i,e;return null===(e=null===(i=null==b?void 0:b.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},E={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},N={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:f("snkAttach.attachMetadata.lblCode"),dataType:s.TEXT},{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),dataType:s.TEXT,readOnly:!1},{name:"ARQUIVO",label:f("snkAttach.attachMetadata.lblFileOrLink"),dataType:s.TEXT},{name:"USUARIO",label:f("snkAttach.attachMetadata.lblUser"),dataType:s.TEXT},{name:"DTALTER",label:f("snkAttach.attachMetadata.lblDate"),dataType:s.TEXT},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFileUpload"),dataType:s.OBJECT,userInterface:o.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:f("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class g{constructor(t){this.getMessage=t,this._records=[],this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){return Promise.resolve(N)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},e=await this._application.getDataFetcher(),{anexos:{anexo:a=[]}}=await e.callServiceBroker("Attach.load",JSON.stringify(t)),s=[];a.forEach((t=>{s.push(Object.assign({__record__id__:r.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=s}return u(this._records,t,i)}saveLoader(t,i){return new Promise((e=>{const a=Array.isArray(t)?t[0]:{};i.save(a).then(e).catch((t=>t.message===d.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),e([])):t.message===d.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===d.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(O.REMOVE).then((async s=>{s&&(await e.delete(t),a(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const C=a.getContextValue("__SNK__APPLICATION__"),P=t=>{var i,e;return null===(e=null===(i=null==C?void 0:C.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},T={DOWNLOAD:{hint:P("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:P("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},L=()=>{const t=[p.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,e)=>{if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();e.splice(e.indexOf(p.REFRESH),1);const{selectedRecord:a}=i||{},s=(null==a?void 0:a.LINK)?T.LINK:T.DOWNLOAD;e.splice(e.indexOf(p.DIVIDER)+1,0,p.REMOVE,s,p.DIVIDER);const n=Array.from(new Set(e.filter((t=>t!==p.CLONE))));return n.splice(n.indexOf(s)+1,0,p.DIVIDER),n},isEnabled:(i,e,a)=>{const s=void 0!==(null==e?void 0:e.selectedRecord);return!(t.includes(a)&&!s)}}},R={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},x=class{constructor(e){t(this,e),this.back=i(this,"back",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.back.emit()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.back.emit();this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.back.emit()}))},this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0}async registerKeyWatcher(t,i){var e;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof k&&(this._currentFetcher.registerKey=t),await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new k(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,e,a,s;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(e=this.registerKey)||void 0===e?void 0:e.split("_").length)>1)return;await(null===(a=this._currentDataUnit)||void 0===a?void 0:a.loadMetadata()),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var e;let a=!1;(null===(e=null==t?void 0:t.ARQUIVO)||void 0===e?void 0:e.endsWith(".pdf"))||(a=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${a?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;this._currentDataUnit=(new m).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},R)),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm()}async loadAttach(){var t,i;this._currentFetcher=new w,this._currentDataUnit=new h(v.IN_MEMORY_DATA_UNIT_NAME),this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===n.METADATA_LOADED&&(this.crudConfig=Object.assign({},E),null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},E),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm())}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new y(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new w,this._currentDataUnitBuilder=new g(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this._currentDataUnit.disableField(e)}))}async componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),await this.initAttach()}componentWillRender(){this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}render(){var t,i;return this._currentDataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:L(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this)},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary ez-padding-bottom--medium"},this.getMessage("snkAttach.description")))))))):null}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};x.style=".snk-attach__header.sc-snk-attach,.snk-attach__crud-section.sc-snk-attach{padding:0 var(--space--lg)}.snk-attach__file-info.sc-snk-attach{padding:var(--space--small);max-width:50%}.snk-attach__main.sc-snk-attach{height:85%}.ez-box__container.sc-snk-attach{height:100%}";export{x as snk_attach}
@@ -0,0 +1 @@
1
+ import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as n,StringUtils as o,ApplicationContext as h,ObjectUtils as a,DataType as r,JSUtils as d,FloatingManager as l,ElementIDUtils as u}from"@sankhyalabs/core";import{CSSVarsUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{V as m,S as v}from"./p-95ce311a.js";import{T as f}from"./p-7e7a7473.js";import"./p-f3434fc4.js";import"./p-8a9638ae.js";import{C as g,S as p,R as C,b as S,a as b}from"./p-9f9b99d9.js";import{D as k,P as y}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as w}from"./p-47bce500.js";import"./p-ff1990ad.js";import{F as E}from"./p-06421fdb.js";import{T as _,b as I,o as T}from"./p-23736d75.js";import{C as F}from"./p-4d9549cf.js";import{S as R}from"./p-fadc8339.js";import{g as D}from"./p-7dd49d15.js";import{s as O}from"./p-6dc031de.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const z=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],M=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class P extends g{getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return D(this.dataUnit)}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[k.EXPORT_BY_EMAIL,k.EXPORT_PDF_TO_EMAIL,k.EXPORT_XLS_TO_EMAIL,k.EXPORT_PAGE_TO_PDF,k.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,o=i[e||s];if(null==o)return"";if(null!=e)return o.label;if(this.dataUnit.getField(s).userInterface===n.SEARCH)return o.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(o,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,o)}}const L=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new p,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new E,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new _({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[f.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[f.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":this.getFinishEditionButtonsCallback.bind(this)}),this._showPopUpGridConfig=!1,this._showFormConfig=!1,this._currentViewMode=m.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${o.generateUUID()}`,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=v.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this._enableContinuousInsert=!0,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){o.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},n),{[t]:s})),this._fieldsProps=e}getFinishEditionButtonsCallback(){const i=["CANCEL","SAVE"];return this.enableGridInsert&&this._currentViewMode!==m.ATTACHMENT&&i.push(this._currentViewMode===m.GRID?f.FORM_MODE:f.GRID_MODE),i}getButtons(i,t,s){let e=i?M:z;return s&&(e=e.filter((i=>i!==f.REFRESH))),this.addConfigButton(this.resolveInMemoryBtns(e).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(f.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===v.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===f.CONFIGURATOR?this._snkConfigurator.open():t===f.GRID_MODE?this.goToView(m.GRID):t===f.FORM_MODE&&this.goToView(m.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==v.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){a.objectToString(t)!=a.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===m.GRID?this.openGridConfig():i===m.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){var i,t;if(this.formLegacyConfigName){const s=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.formConfigUnavaliable.title",void 0),e=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkSimpleCrud.formConfigUnavaliable.message",void 0);await this.application.alert(s,e)}else this._showFormConfig=!0}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&F.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{F.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let t=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=t)return this._formConfigManager.setConfig(t),void this.setFormConfig(t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new C,this._continuousInsertUtils=new S(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidLoad(){c.applyVarsGrid(this._element,this._grid)}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new w(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:r[i.getAttribute("dataType")]||r.TEXT,userInterface:n[i.getAttribute("userInterface")]||n.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!n.includes(i.name)&&n.push(i.name)})),n.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,n,o;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(f.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(f.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(f.FORM_MODE),(null===(o=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===o?void 0:o.length)>1&&h.push(f.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(m.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=I(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=I(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){a.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getActionsList(){var i,t;const s=[{value:o.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===m.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(this.enableGridInsert&&s.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return s;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return this.actionsList?s.concat(this.actionsList):s}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${y.PRIMARY}`:`snkGridTopTaskbar.regular${y.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===m.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await T(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){i.stopPropagation(),this.configName&&F.saveGridConfig(i.detail,this.configName,this.resolveResourceID())}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new P(this.dataUnit,this._grid);O.set("exporterProviders",Object.assign(Object.assign({},O.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,b.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}closeFormConfig(){this._showFormConfig=!1}getPageSize(){return this.mode===v.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}handleShowFormConfig(){return this._showFormConfig&&!this.formLegacyConfigName}resolveResourceID(){return o.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){const i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields});this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(m.FORM)}render(){var i;if(null==this.dataUnit)return;const t=s("snk-taskbar",{class:this._currentViewMode===m.FORM&&"ez-box ez-box--shadow ez-padding--small",dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:y.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}));return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===m.GRID&&!this.enableGridInsert,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:"ez-box ez-box--shadow simple-crud__container-section"},this._currentViewMode===m.FORM&&t,s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(m.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(w.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert},this._currentViewMode===m.GRID&&t,s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large "+(this.handleShowFormConfig()?"simple-crud__form--hidden":""),dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),this.handleShowFormConfig()&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,configManager:this._formConfigManager,onConfigClose:()=>this.closeFormConfig()})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};L.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{L as snk_simple_crud}
@@ -1 +1 @@
1
- import{r as t,h as i,H as s,g as e,c as n}from"./p-d2d301a6.js";import{ApplicationContext as o,StringUtils as r,ErrorException as a,WarningException as l,ObjectUtils as c,DateUtils as d,ArrayUtils as h,ElementIDUtils as u}from"@sankhyalabs/core";import{D as g}from"./p-f3434fc4.js";import{P as f}from"./p-eaad0aa8.js";import"./p-8a9638ae.js";import"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-47bce500.js";import"./p-ff1990ad.js";import"./p-06421fdb.js";import{g as m}from"./p-7dd49d15.js";import{R as p}from"./p-688dcb4c.js";import{ApplicationUtils as v,DialogType as b}from"@sankhyalabs/ezui/dist/collection/utils";import{CheckMode as k}from"@sankhyalabs/ezui/dist/collection/components/ez-check/CheckMode";import{C as _}from"./p-4d9549cf.js";import{O as w}from"./p-b0ef4383.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";class y{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.javaCall)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecJava})}))}async callExecJava(t){const i={requestBody:{javaCall:t}};await g.get().callServiceBroker("ActionButtonsSP.executeJava",JSON.stringify(i))}}class C{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.runScript)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecScript})}))}async callExecScript(t){const i={runScript:t};await g.get().callServiceBroker("ActionButtonsSP.executeScript",i)}}class x{constructor(){this._application=o.getContextValue("__SNK__APPLICATION__")}async execute(t,i){const s=t.resourceID;if(!s)return;let e=await this.buildLaunchObject(t,i);return this._application.openApp(s,e),null}buildLaunchObject(t,i){return new Promise((s=>{let e=t.actionConfig.params.param;if(e&&e.length>0){let n={},o=[];e.forEach((s=>{const e=s.localField;let l=i.getFieldValue(e);if(!l){let s=i.getField(e).label;throw s=r.isEmpty(i.getField(e).label)?e:s,new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField",{description:t.description,localFieldLabel:s}))}l=r.isEmpty(l.toString())?void 0:l.toString(),n[s.targetField]=l,o.push({fieldName:s.targetField,value:l})})),n.ACTION_PARAMETERS=o,n.call_time=Date.now(),s(n)}s(null)}))}}class S{execute(t){var i,s,e;const n=null===(i=t.actionConfig.dbCall)||void 0===i?void 0:i.name,o=null===(s=t.actionConfig.dbCall)||void 0===s?void 0:s.rootEntity,r={actionID:t.actionID,refreshType:null===(e=t.actionConfig.dbCall)||void 0===e?void 0:e.refreshType,procName:n,rootEntity:o};return new Promise((t=>{t({execSource:r,callback:this.callExecProcedure})}))}async callExecProcedure(t){const i={requestBody:{stpCall:t}};await g.get().callServiceBroker("ActionButtonsSP.executeSTP",JSON.stringify(i))}}var z,A;!function(t){t.LAUNCH_SCREEN="LC",t.JAVASCRIPT="SC",t.JAVA="RJ",t.PROCEDURE="SP",t.EMBEDDED="EB"}(z||(z={}));class O{constructor(t){this.actionType=t,this._application=o.getContextValue("__SNK__APPLICATION__")}get executor(){switch(this.actionType){case z.LAUNCH_SCREEN:return new x;case z.JAVASCRIPT:return new C;case z.JAVA:return new y;case z.PROCEDURE:return new S;default:throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType",{actionType:this.actionType}))}}}!function(t){t.NONE="NONE",t.PARENT="PARENT",t.MASTER="MASTER",t.ALL="ALL"}(A||(A={}));const P="__MASTER_ROW__";class N{constructor(t,i,s){var e;this._lastValuesCache={},this._actionsExecuteInterface=t,this._dataUnit=i,this._selectedRows=(null===(e=null==i?void 0:i.getSelectionInfo())||void 0===e?void 0:e.isAllRecords())?[]:null==i?void 0:i.getSelectionInfo().records,this._application=o.getContextValue("__SNK__APPLICATION__"),this._appResourceId=s}getPrimaryKeys(){return m(this._dataUnit).map((({name:t})=>t))}apply(t,i){this._application.closePopUp(),this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:s,callback:e})=>{this.resolvePromptParams(t,s,i).then((()=>{this.actionExecute(s,e)}))}))}async execute(t){var i;if(!t.actionConfig)throw new l(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction",{description:t.description}));if(null===(i=t.actionConfig.params)||void 0===i?void 0:i.promptParam){const i=t.actionConfig.params.promptParam;let s=!1;for(let t=0;t<i.length;t++)if(!s&&"true"===i[t].saveLast){s=!0;break}s&&(t.actionConfig.params.promptParam=await this.loadSavedValuesIntoParams(t));const e=document.createElement("snk-actions-form");window.document.body.appendChild(e),e.action=c.copy(t),e.applyParameters=t=>{this.apply(t,s)},e.openPopup()}else t.type!=z.LAUNCH_SCREEN?this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:t,callback:i})=>{this.actionExecute(t,i)})):this._actionsExecuteInterface.execute(t,this._dataUnit)}loadSavedValuesIntoParams(t){return this.loadLastValues(t).then((i=>{let s=t.actionConfig.params.promptParam;return i&&i.param.forEach((t=>{s=s.map((i=>i.name!==t.paramName?i:Object.assign(Object.assign({},i),"B"===i.paramType?{value:"S"===t.$}:{value:t.$})))})),s}))}actionExecute(t,i){t.virtualPage=this.buildVirtualPage(),this.prepareAndExecute(t,i),this.recordsReloader(t.refreshType)}resolvePromptParams(t,i,s){return new Promise((e=>{let n=[];t.actionConfig.params.promptParam.forEach((t=>{n.push(this.buildPromptParam(t))})),this.putParamsOnExecSource(n,i),s&&this.saveLastValues(t,n),e()}))}buildPromptParam(t){let i,s,e=t.paramType,n=!1,o=t.value;switch(e){case f.DATE:e="D";break;case f.DATETIME:e="H";break;case f.DECIMAL:e="F",i={"sk-precision":Number(t.precision)};break;case f.BOOLEAN:e="S",n=!0,o=t.value?"S":"N";break;case f.ENTITY:i={"sk-entity-name":t.entityName,"sk-allow-show-hierarchical-mode":t.hierarchyEntity,"sk-data-type":"S"},t.hierarchyEntity&&t.entityPK&&(s=t.entityPK),o=t.value?Number(t.value):null;break;case f.OPTIONS:e="O";let r=t.options.split(";").map((function(t,i){let s,e;if(t.indexOf("=")>-1){let i=t.split("=");s=i[0],e=i[1]}else s=i+1,e=t;return{data:s,value:e}}));i={"sk-options":r}}return{description:t.label,required:"true"==t.required,fieldName:t.name,fieldNameOri:t.name,entityPK:s,paramType:t.paramType,type:e,isCheckbox:n,saveLast:t.saveLast,fieldProp:i,value:o,isGeneratedName:t.isGeneratedName}}putParamsOnExecSource(t,i){i.params={param:[]},t.forEach((t=>{if(t.isGeneratedName&&t.value)throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName",void 0));r.isEmpty(t.value)||i.params.param.push({type:this.getParamDataType(t.paramType),paramName:t.fieldName,$:this.getParamValue(t)})}))}getParamDataType(t){let i;switch(t){case"D":i="F";break;case"DT":case"DH":i="D";break;case"B":case"ENTITY":case"SO":i="S";break;default:i=t}return i}getParamValue(t){let i=t.value;return i?("DT"==t.paramType?i=d.formatDate(i):"DH"==t.paramType&&(i=d.formatDateTime(i)),i):i}async loadLastValues(t){const i=await this.buildResourceId(t.actionID);return new Promise(((t,s)=>{if(this._lastValuesCache[i])t(this._lastValuesCache[i]);else{const e={config:{chave:i,tipo:"T"}};g.get().callServiceBroker("SystemUtilsSP.getConf",e).then((s=>{var e,n;let o;(null===(n=null===(e=s.config)||void 0===e?void 0:e.data)||void 0===n?void 0:n.params)&&(o=s.config.data.params,Array.isArray(o.param)||(o.param=[o.param])),this._lastValuesCache[i]=o,t(o)})).catch((t=>{s(t)}))}}))}async saveLastValues(t,i){if(this._application){let s={params:{param:[]}};i.forEach((t=>{"true"==t.saveLast&&s.params.param.push({paramName:t.fieldName,$:t.value})}));const e=await this.buildResourceId(t.actionID);this._lastValuesCache[e]=s.params,this._application.saveConfig(e,s)}}async buildResourceId(t){return this._appResourceId+".actionconfig."+t}prepareAndExecute(t,i){this.addRows(t),i(t)}addRows(t){const i=this.getPrimaryKeys(),s={row:[]},e=this._selectedRows;for(const t in e){const n=e[t],o={};n.hasOwnProperty(P)&&(o.master="S",o.entityName=n.__ENTITY_NAME__,delete n[P],delete n.__ENTITY_NAME__),o.field||(o.field=[]);for(const t of i)o.field.push({fieldName:t,$:n[t]});s.row.push(o)}s.row.length>0&&(t.rows=s)}recordsReloader(t){switch(t){case A.NONE:break;case A.PARENT:case A.MASTER:case A.ALL:this._dataUnit.loadData();break;default:this._dataUnit.reloadCurrentRecord()}}buildVirtualPage(){var t,i,s,e;if(null===(i=null===(t=this._dataUnit)||void 0===t?void 0:t.getSelectionInfo())||void 0===i?void 0:i.isAllRecords())return{filters:{filters:null===(s=this._dataUnit)||void 0===s?void 0:s.getAppliedFilters()},orders:{orders:null===(e=this._dataUnit)||void 0===e?void 0:e.getSort()}}}}class D{async clientConfirm(t,i){return new Promise((s=>{const e=o.getContextValue("__SNK__APPLICATION__");let n="";t.content.event.hasOwnProperty("stpCall")?(i.requestBody=t.content.event.stpCall,n=z.PROCEDURE):t.content.event.hasOwnProperty("runScript")?(i.requestBody=t.content.event.runScript,n=z.JAVASCRIPT):t.content.event.hasOwnProperty("javaCall")&&(i.requestBody=t.content.event.javaCall,n=z.JAVA);let r={type:"S",sequence:t.content.event.sequence};i.requestBody.params?Array.isArray(i.requestBody.params.param)||(i.requestBody.params.param=[i.requestBody.params.param]):i.requestBody.params={param:[]},i.requestBody.params.param.push(r);const a=t.content.event.title.$,l=t.content.event.message.$;let c;switch(n){case z.JAVASCRIPT:c={runScript:i.requestBody};break;case z.PROCEDURE:c={requestBody:{stpCall:i.requestBody}};break;case z.JAVA:c={requestBody:{javaCall:i.requestBody}}}if("S"==t.content.event.showNoOption){r.paramName="__ESCOLHA_SIMNAO__";const t=document.createElement("snk-client-confirm");window.document.body.appendChild(t),t.titleMessage=a,t.message=l,t.accept=async()=>{r.$="S",await i.reCall(c),s()},t.cancel=async()=>{r.$="N",await i.reCall(c),s()},t.openPopup()}else e.confirm(a,l,null,"warn",{labelCancel:"Cancelar",labelConfirm:"Sim"}).then((async t=>{t&&(r.paramName="__CONFIRMACAO__",r.$="S",await i.reCall(c),s())}))}))}}const I=class{constructor(i){t(this,i),this.CLIENT_EVENT_CONFIRM_NAME="br.com.sankhya.actionbutton.clientconfirm",this.handleClick=t=>{const i=this._actions.find((i=>i.actionID==t.detail.id)),s=new O(i.type).executor;new N(s,this._dataUnit,this._resourceID).execute(Object.assign({},i)),this._showDropdown=!1},this._items=[],this._showDropdown=!1,this._actions=[],this._isOrderActions=!1}async getActions(){let t={param:{entityName:this._entityName,resourceID:this._resourceID}};return g.get().callServiceBroker("ActionButtonsSP.getActions",t).then((t=>{var i;(null===(i=t.actions)||void 0===i?void 0:i.action)&&(this._actions=this._isOrderActions?h.sortAlphabetically(t.actions.action,"description"):t.actions.action)}))}controlDropdown(){this._showDropdown=!this._showDropdown}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this._items)||void 0===t?void 0:t.length)>0}positionDropdown(){var t;const i=null===(t=this._ezButton)||void 0===t?void 0:t.getBoundingClientRect();i&&this._dropdownParent&&(this._dropdownParent.style.top=i.y+i.height+5+"px",this._dropdownParent.style.left=i.x+"px")}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest(".snk-actions-button")||(this._showDropdown=!1))}setEvents(){document.removeEventListener("click",this.closeDropdown.bind(this)),document.addEventListener("click",this.closeDropdown.bind(this)),document.removeEventListener("scroll",this.positionDropdown.bind(this)),document.addEventListener("scroll",this.positionDropdown.bind(this))}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),this._isOrderActions=await this._application.getBooleanParam("global.ordenar.acoes.personalizadas");const t=this._element.parentElement;this._dataUnit=null==t?void 0:t.dataUnit,this._resourceID=null==t?void 0:t.resourceID,this._entityName=this._dataUnit.name.split("/")[2],null==this._resourceID&&(this._resourceID=await p.getResourceID()),this.setEvents(),this.getActions().then((()=>{this.loadItems()}))}async componentDidLoad(){if(this._element&&(u.addIDInfo(this._element),this.positionDropdown(),!await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))){const t=new D;this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME,t.clientConfirm)}}componentDidUpdate(){this.positionDropdown()}loadItems(){this._actions&&0!=this._actions.length&&this._actions.forEach((t=>{this._items.push({id:t.actionID,label:t.description})}))}getElementID(t){return{[u.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:u.getInternalIDInfo(t)}}render(){return i(s,null,this._actions&&this._actions.length>0&&i("div",{class:`ez-padding-left--medium snk-actions-button\n ${this.canShowDropdown()?" ez-elevation--16":""}\n `},i("ez-button",Object.assign({ref:t=>this._ezButton=t,iconName:"acao",size:"small",mode:"icon",title:this._application.messagesBuilder.getMessage("snkActionsButton.title.actions",void 0),onClick:()=>this.controlDropdown()},this.getElementID("button"))),i("div",Object.assign({ref:t=>this._dropdownParent=t,class:(this.canShowDropdown()?"snk-actions-button__dropdown--show":"snk-actions-button__dropdown")+"\n "},this.getElementID("dropdown")),this.canShowDropdown()&&i("ez-dropdown",Object.assign({items:this._items,onEzClick:t=>this.handleClick(t)},this.getElementID("dropdown"))))),this.canShowDropdown()&&i("div",Object.assign({class:"ez-scrim ez-scrim--light"},this.getElementID("ezScrim"))))}get _element(){return e(this)}};I.style=".sc-snk-actions-button-h{display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";const E=class{constructor(i){t(this,i),this.configChange=n(this,"configChange",7),this.configCancel=n(this,"configCancel",7),this._orderListItems=[],this._orderPriorityList=[],this._columListItems=[],this._selectedIndex=-1,this._dataChanged=!1,this._componenteInternalKey=Date.now(),this.selectedIndex=0,this.columns=void 0,this.config=void 0,this.configName=void 0,this.resourceID=void 0}getMessage(t,i){return o.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage(t,i)}getSortableColumns(){let t=[];return this.columns.filter((t=>{var i;return r.getBooleanValue(null===(i=null==t?void 0:t.props)||void 0===i?void 0:i.get("sortable"),!0)})).forEach((i=>{var s;let e=null===(s=this.config)||void 0===s?void 0:s.columns.find((t=>t.name===i.name)),n={name:i.name,label:i.label};e&&(n.orderIndex=e.orderIndex,n.ascending=e.ascending),i.hidden||t.push(n)})),t}createOrderList(){let t=this.getSortableColumns();t.sort(((t,i)=>0!=t.orderIndex||0!=i.orderIndex||null==t.ascending&&null==i.ascending?null!=t.ascending&&null!=i.ascending?t.orderIndex-i.orderIndex:null!=t.ascending||null!=i.ascending?null!=t.ascending?-1:null!=i.ascending?1:0:t.orderIndex-i.orderIndex:null!=t.ascending?-1:null!=i.ascending?1:0)),this._orderListItems=t}createColumnList(){let t={group:this.getMessage("snkGridConfig.group.visible"),items:[]},i={group:this.getMessage("snkGridConfig.group.hidden"),items:[],sort:w.asc.value};this.columns.forEach((s=>{let e={label:s.label};s.hidden?i.items.push(e):t.items.push(e)})),this._columListItems=[t,i]}createColumnListSlotDataElementId(t){return`configItem_${r.replaceAccentuatedChars(r.toCamelCase(t.label))}`}buildColumnListSlot(t,s){const e=this.createColumnListSlotDataElementId(t);return i("div",null,i("ez-check",{mode:k.SWITCH,id:k.SWITCH+((null==t?void 0:t.label)||"")+((null==s?void 0:s.group)||""),value:s.group===this.getMessage("snkGridConfig.group.visible"),"data-element-id":e,onEzChange:i=>{this.switchColumnGroup(i,t)}}))}createOrderListSlotDataElementId(t){return`${this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME)}_configItem_${r.toCamelCase(t.label)}`}buildOrderListSlot(t){const s=this.createOrderListSlotDataElementId(t);let e=w.none.value;return null!=(null==t?void 0:t.ascending)&&(e=1==t.ascending?w.asc.value:w.desc.value),i("div",null,i("snk-select-box",{selectedOption:e,key:"snk-select-box-"+this._componenteInternalKey+"-"+t,"data-element-id":s,onEzChange:i=>{i.stopPropagation(),this.updateOrder(i.detail,t.label)}}))}updateOrder(t,i){var s;this._dataChanged=!0;let e,n=[...this.columns],o=n.find((t=>t.label===i));o&&(o.sort=t.value===w.none.value?void 0:t.value),(null===(s=this._orderPriorityList)||void 0===s?void 0:s.length)>0?(this._orderPriorityList.find((t=>t.label===o.label)).sort=t,this._orderPriorityList.filter((t=>t.sort)).forEach(((t,i)=>{t.label===o.label&&(o.sortIndex=i)}))):(e=n.filter((t=>t.sort&&!0!==t.hidden)).map(((t,i)=>({label:t.label,orderIndex:i}))),e.forEach((t=>{n.find((i=>i.label===t.label)).sortIndex=t.orderIndex}))),this.columns=n}switchColumnGroup(t,i){t.stopPropagation();let s=[...this._columListItems];if(this._dataChanged=!0,!0===t.detail){let t=s.find((t=>t.group===this.getMessage("snkGridConfig.group.hidden"))),e=t.items.findIndex((t=>t.label===i.label));e>=0&&t.items.splice(e,1),s.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))).items.push(i),this._columListItems=s,this.createOrderList()}else if(!1===t.detail){let t=s.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))),e=t.items.findIndex((t=>t.label===i.label));e>=0&&t.items.splice(e,1),s.find((t=>t.group===this.getMessage("snkGridConfig.group.hidden"))).items.push(i),this._columListItems=s,this.createOrderList()}}finish(){if(!this._dataChanged)return void this.closeConfig();let t=[];this._columListItems.forEach((i=>{i.items.forEach((s=>{const e=this.columns.find((t=>t.label===s.label));let n=Object.assign({},e);n.hidden=i.group===this.getMessage("snkGridConfig.group.hidden"),t.push(n)}))})),this.columns=t,this._dataChanged=!1,this.closeConfig(),this.save()}saveGridConfigOnStorage(t){_.saveGridConfig(t,this.configName,this.resourceID).then((t=>{this.configChange.emit(t),this._orderList.clearHistory(),v.info(this.getMessage("snkGridConfig.info.successfullyConfigSaved"),{iconName:"check"})}))}reOrderPriorityColumns(t,i){let s=[];s=t.filter((t=>t.sort&&!0!==t.hidden)).map((t=>({label:t.label,orderIndex:0})));let e=0,n=[];return i.forEach((t=>{let i=s.find((i=>i.label===t.label));i&&(i.orderIndex=e,n.push(i),e++)})),n.length>0&&(s=n),s}save(){var t;let i;i=this.config?this.config:this.createConfigFromState(this.columns);let s,e=[];(null===(t=this._orderPriorityList)||void 0===t?void 0:t.length)>0&&(s=this.reOrderPriorityColumns(this.columns,this._orderPriorityList)),this.columns.forEach((t=>{let n=i.columns.find((i=>t.name===i.name));!0===t.hidden&&n||(n?n.width=t.width:!1===t.hidden&&(n={name:t.name,width:t.width,orderIndex:0}),n&&(t.sort?(n.ascending=t.sort.toUpperCase()===w.asc.value,s?function(t,i){if(s){let e=s.find((i=>i.label===t.label));e&&(i.orderIndex=e.orderIndex)}}(t,n):n.orderIndex=t.sortIndex):(delete n.ascending,n.orderIndex=0),e.push(n)))})),i.columns=e,this.saveGridConfigOnStorage(i)}createConfigFromState(t){let i={columns:[]};return t.forEach((t=>{if(!t.hidden){let s={name:t.name};t.width&&(s.width=t.width),t.sort?(s.ascending=t.sort.toUpperCase()===w.asc.value,s.orderIndex=t.sortIndex):s.orderIndex=0,s&&i.columns.push(s)}})),i}async locateColumn(t,i){var s;const e="Enter"===t.key;if(!(i=i||(null===(s=t.currentTarget)||void 0===s?void 0:s.value)))return void this.removeSelection();const n=await this.getMatchedIndexes(i),o=this.getNewSelectedIndex(n,e);this._selectedIndex=o,1===this.selectedIndex?this.updateOrderListSelection(o):this.updateColumnListSelection(o)}async getMatchedIndexes(t){const i=[];return 1===this.selectedIndex?(await this._orderList.getList()).forEach(((s,e)=>{this.compareWords(s,t)&&i.push(e)})):this.columns.forEach(((s,e)=>{this.compareWords(s,t)&&i.push(e)})),i}getNewSelectedIndex(t,i){if(0===t.length)return-1;if(i)for(const i of t)if(i>this._selectedIndex)return i;return t[0]}updateOrderListSelection(t){-1!==t?this._orderList.getList().then((i=>{const s=i[t];s?this._orderList.setSelection(s,!0):this._orderList.removeSelection()})):this._orderList.removeSelection()}updateColumnListSelection(t){if(-1===t)return void this._columnList.removeSelection();const i=this.columns[t];if(i){const t=this._columListItems.map((t=>t.items)).flat().find((t=>t.label===i.label));t?this._columnList.setSelection(t,!0):this._columnList.removeSelection()}else this._columnList.removeSelection()}removeSelection(){1===this.selectedIndex?this._orderList.removeSelection():this._columnList.removeSelection()}compareWords(t,i){var s,e;const n=null===(s=r.replaceAccentuatedChars(null==t?void 0:t.label))||void 0===s?void 0:s.toUpperCase(),o=null===(e=r.replaceAccentuatedChars(i))||void 0===e?void 0:e.toUpperCase();return!r.isEmpty(n)&&!r.isEmpty(o)&&n.includes(o)}getColumnNames(){const t=[];return t.push(this.getMessage("snkGridConfig.tab.columns")),t.push(this.getMessage("snkGridConfig.tab.lineOrdering")),t.join(",")}closeConfig(){if(this._orderList.scrollToTop(),this._columnList.scrollToTop(),this._searchElement.value="",this._dataChanged){let t={canClose:!1,labelCancel:this.getMessage("snkGridConfig.confirm.cancel"),labelConfirm:this.getMessage("snkGridConfig.confirm.save"),btnConfirmDanger:!1};v.confirm(this.getMessage("snkGridConfig.confirm.alert"),this.getMessage("snkGridConfig.confirm.msgCancel"),null,b.WARN,t).then((t=>{t?this.finish():(this._dataChanged=!1,this.configCancel.emit(),this._orderList.clearHistory(),this._componenteInternalKey=Date.now())}))}else this.configCancel.emit(),this._orderList.clearHistory()}handleTabChange(t){null!=(null==t?void 0:t.index)&&(this.selectedIndex!==t.index&&(0===t.index?this._orderList.scrollToTop():1===t.index&&this._columnList.scrollToTop(),this._searchElement.value=""),1===t.index&&this.createOrderList(),this.selectedIndex=t.index)}handleColumnListChange(t){var i;if(t.detail){let s=null===(i=t.detail.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))))||void 0===i?void 0:i.items;s&&(this._dataChanged=!0,this._orderListItems=s)}}handleOrderListChange(t){if(t.detail){let i=t.detail;i&&(this._dataChanged=!0,this._orderPriorityList=i)}}componentWillRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.createColumnList()}componentDidRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.locateColumn(new KeyboardEvent("arrow-right",{key:"ArrowRight"}),this._searchElement.value)}componentDidLoad(){u.addIDInfo(this._element)}render(){return i(s,null,i("div",{class:"grid-config__header"},i("div",{class:"title-container"},i("div",{class:""},i("label",{class:"title"},this.getMessage("snkGridConfig.gridConfiguration")),i("label",{class:"subtitle"},this.getMessage("snkGridConfig.columnVisibilityOrder"))),i("div",{class:"button-close"},i("ez-button",{mode:"icon",iconName:"close",size:"medium",onClick:()=>this.closeConfig()}))),i("div",{class:"tabselector-container"},i("ez-tabselector",{selectedIndex:this.selectedIndex,onEzChange:t=>{this.handleTabChange(t.detail)},tabs:this.getColumnNames()})),i("div",null,i("ez-text-input",{"data-element-id":"searchColums",ref:t=>this._searchElement=t,label:this.getMessage("snkGridConfig.findColumn"),onKeyUp:t=>this.locateColumn(t)},i("ez-icon",{slot:"leftIcon",size:"medium",iconName:"search"})))),i("div",{class:"grid-config__main"},i("ez-list",{ref:t=>this._columnList=t,class:0===this.selectedIndex?"":"hidden",dataSource:this._columListItems,onEzChange:t=>this.handleColumnListChange(t),ezDraggable:!0,ezSelectable:!0,itemSlotBuilder:(t,i)=>this.buildColumnListSlot(t,i),useGroups:!0,"data-element-id":"configCols"}),i("div",{class:1===this.selectedIndex?"group-name":"hidden"},this.getMessage("snkGridConfig.info.sortingSequence")),i("ez-list",{ref:t=>this._orderList=t,class:1===this.selectedIndex?"height-calc":"hidden",dataSource:this._orderListItems,ezSelectable:!0,onEzChange:t=>this.handleOrderListChange(t),ezDraggable:!0,itemSlotBuilder:t=>this.buildOrderListSlot(t),"data-element-id":"configDataOrder"})),i("div",{class:"grid-config__footer"},i("ez-button",{class:"padding-right--medium",label:this.getMessage("snkGridConfig.cancel"),onClick:()=>this.closeConfig()}),i("ez-button",{label:this.getMessage("snkGridConfig.complete"),class:"ez-button--primary",onClick:()=>this.finish()})))}static get assetsDirs(){return["../assets"]}get _element(){return e(this)}};E.style='.sc-snk-grid-config-h{--snk-grid-config__footer--padding-top:var(--space--medium, 12px);--snk-grid-config__main--padding-right:var(--space--medium, 12px);--snk-grid-config__tabselector-container--padding:var(--space--medium, 12px);--snk-grid-config__button-close--padding-left:var(--space--medium, 12px);--snk-grid-config__title--color:var(--title--primary, #2B3A54);--snk-grid-config__title--font-family:var(--font-pattern, "Roboto");--snk-grid-config__title--font-size:var(--title--large, 20px);--snk-grid-config__title--font-weight:var(--text-weight--extra-large, 700);--snk-grid-config__subtitle--font-family:var(--font-pattern, "Roboto");--snk-grid-config__subtitle--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-family:var(--font-pattern, "Roboto");--snk-grid-config__group--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-weight:var(--text-weight--large, 600);--snk-grid-config__group--padding-bottom:var(--space-small, 6px);--snk-grid-config__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-grid-config__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-grid-config__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-grid-config__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-grid-config__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-grid-config__scrollbar--width:var(--space--medium, 12px);display:grid;grid-template-rows:auto 1fr auto;max-height:100%;width:100%}@media screen and (min-width: 480px){.sc-snk-grid-config-h{width:359px;max-width:359px}}.padding-right--medium.sc-snk-grid-config{padding-right:var(--space--medium)}ez-list.sc-snk-grid-config{height:100%}.height-calc.sc-snk-grid-config{max-height:calc(100% - 24px)}.grid-config__footer.sc-snk-grid-config{display:flex;justify-content:flex-end;width:100%;padding-top:var(--snk-grid-config__footer--padding-top)}.hidden.sc-snk-grid-config{display:none}.tabselector-container.sc-snk-grid-config{padding:var(--snk-grid-config__tabselector-container--padding) 0}.button-close.sc-snk-grid-config{padding-left:var(--snk-grid-config__button-close--padding-left)}.title-container.sc-snk-grid-config{display:flex;justify-content:space-between;align-items:center;width:100%}.title.sc-snk-grid-config{display:flex;margin:0;line-height:normal;letter-spacing:0em;text-align:left;color:var(--snk-grid-config__title--color);font-size:var(--snk-grid-config__title--font-size);font-family:var(--snk-grid-config__title--font-family);font-weight:var(--snk-grid-config__title--font-weight)}.subtitle.sc-snk-grid-config{color:var(--text--primary);font-size:var(--snk-grid-config__subtitle--font-size);font-family:var(--snk-grid-config__subtitle--font-family)}.grid-config__main.sc-snk-grid-config{overflow-y:auto;scrollbar-width:thin;scrollbar-color:var(--snk-grid-config__scrollbar--color-clicked) var(--snk-grid-config__scrollbar--color-background);padding-right:var(--snk-grid-config__main--padding-right)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar{width:var(--snk-grid-config__scrollbar--width);max-width:var(--snk-grid-config__scrollbar--width);min-width:var(--snk-grid-config__scrollbar--width);background-color:var(--snk-grid-config__scrollbar--color-background)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-track{background-color:var(--snk-grid-config__scrollbar--color-background);border-radius:var(--snk-grid-config__scrollbar--border-radius)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb{background-color:var(--snk-grid-config__scrollbar--color-default);border-radius:var(--snk-grid-config__scrollbar--border-radius)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:vertical:hover,.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-grid-config__scrollbar--color-hover)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:vertical:active,.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-grid-config__scrollbar--color-clicked)}.group-name.sc-snk-grid-config{font-family:var(--snk-grid-config__group--font-family);font-size:var(--snk-grid-config__group--font-size);font-weight:var(--snk-grid-config__group--font-weight);padding-bottom:var(--snk-grid-config__group--padding-bottom)}';const j=class{constructor(i){t(this,i),this.ezChange=n(this,"ezChange",7),this.selectedOption=w.none}render(){return i("ez-combo-box",{class:"grid-config-combo ez-input--inverted",label:"",suppressSearch:!0,value:this.selectedOption,enabled:!0,canShowError:!1,suppressEmptyOption:!0},Object.keys(w).map((t=>i("option",{value:w[t].value},w[t].label))))}static get assetsDirs(){return["../assets"]}};j.style="ez-combo-box{width:100px}.grid-config-combo{--ez-text-input--height:28px;--ez-text-input__input--background-color:#fff;--ez-text-input__input--border-color:#dce0e8}";const L=class{constructor(i){t(this,i),this.taskbarActionSelected=n(this,"taskbarActionSelected",7),this.taskbarActionsOpened=n(this,"taskbarActionsOpened",7),this.taskbarActionsButtonDisconnected=n(this,"taskbarActionsButtonDisconnected",7),this._showDropdown=!1,this.title=void 0,this.enabled=void 0,this.actions=void 0}async handleKeyDown(t){"Escape"!==t.key&&"Esc"!==t.key||await this.hideActions()}async handleClose(){await this.hideActions()}async showActions(){this._showDropdown=!0,requestAnimationFrame((()=>{this._element.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}))}async hideActions(){this._showDropdown=!1}async isOpened(){return this._showDropdown}controlDropdown(){this._showDropdown=!this._showDropdown}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this.actions)||void 0===t?void 0:t.length)>0}onSelectAction(t){const i=this.actions.map((t=>Object.assign(Object.assign({},t),{id:t.value}))),s=this.getSelectedAction(t.id,i);this.taskbarActionSelected.emit(s),s.disableCloseOnSelect||(this._showDropdown=!1)}getSelectedAction(t,i){let s=null;for(const e of i){if(e.id===t){s=e;break}if((null==e?void 0:e.children)&&(s=this.getSelectedAction(t,e.children),s))break}return s}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._element,e);return"string"==typeof n?i("div",{innerHTML:n}):n}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._element,t))}))}componentDidLoad(){this.initializeEagerItems()}componentDidRender(){this._showDropdown&&this.taskbarActionsOpened.emit(this._element)}disconnectedCallback(){this.taskbarActionsButtonDisconnected.emit()}render(){return i(s,null,i("div",{class:this.canShowDropdown()?" ez-elevation--16":""},i("ez-button",{title:this.title,mode:"icon",iconName:"dots-vertical",size:"small",enabled:this.enabled,onClick:()=>this.controlDropdown()}),this.canShowDropdown()&&i("ez-dropdown",{items:this.loadItems(),onEzClick:t=>this.onSelectAction(t.detail),onEzOutsideClick:()=>this._showDropdown=!1,itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)})))}get _element(){return e(this)}};L.style=".sc-taskbar-actions-button-h{display:flex;width:fit-content;height:fit-content}";export{I as snk_actions_button,E as snk_grid_config,j as snk_select_box,L as taskbar_actions_button}
1
+ import{r as t,h as i,H as s,g as e,c as n}from"./p-d2d301a6.js";import{ApplicationContext as o,StringUtils as r,ErrorException as a,WarningException as l,ObjectUtils as c,DateUtils as d,ArrayUtils as h,ElementIDUtils as u}from"@sankhyalabs/core";import{D as g}from"./p-f3434fc4.js";import{P as f}from"./p-eaad0aa8.js";import"./p-8a9638ae.js";import"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-47bce500.js";import"./p-ff1990ad.js";import"./p-06421fdb.js";import{g as m}from"./p-7dd49d15.js";import{R as p}from"./p-688dcb4c.js";import{ApplicationUtils as v,DialogType as b}from"@sankhyalabs/ezui/dist/collection/utils";import{CheckMode as k}from"@sankhyalabs/ezui/dist/collection/components/ez-check/CheckMode";import{C as _}from"./p-4d9549cf.js";import{O as w}from"./p-95ce311a.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";class y{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.javaCall)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecJava})}))}async callExecJava(t){const i={requestBody:{javaCall:t}};await g.get().callServiceBroker("ActionButtonsSP.executeJava",JSON.stringify(i))}}class C{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.runScript)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecScript})}))}async callExecScript(t){const i={runScript:t};await g.get().callServiceBroker("ActionButtonsSP.executeScript",i)}}class x{constructor(){this._application=o.getContextValue("__SNK__APPLICATION__")}async execute(t,i){const s=t.resourceID;if(!s)return;let e=await this.buildLaunchObject(t,i);return this._application.openApp(s,e),null}buildLaunchObject(t,i){return new Promise((s=>{let e=t.actionConfig.params.param;if(e&&e.length>0){let n={},o=[];e.forEach((s=>{const e=s.localField;let l=i.getFieldValue(e);if(!l){let s=i.getField(e).label;throw s=r.isEmpty(i.getField(e).label)?e:s,new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField",{description:t.description,localFieldLabel:s}))}l=r.isEmpty(l.toString())?void 0:l.toString(),n[s.targetField]=l,o.push({fieldName:s.targetField,value:l})})),n.ACTION_PARAMETERS=o,n.call_time=Date.now(),s(n)}s(null)}))}}class S{execute(t){var i,s,e;const n=null===(i=t.actionConfig.dbCall)||void 0===i?void 0:i.name,o=null===(s=t.actionConfig.dbCall)||void 0===s?void 0:s.rootEntity,r={actionID:t.actionID,refreshType:null===(e=t.actionConfig.dbCall)||void 0===e?void 0:e.refreshType,procName:n,rootEntity:o};return new Promise((t=>{t({execSource:r,callback:this.callExecProcedure})}))}async callExecProcedure(t){const i={requestBody:{stpCall:t}};await g.get().callServiceBroker("ActionButtonsSP.executeSTP",JSON.stringify(i))}}var z,A;!function(t){t.LAUNCH_SCREEN="LC",t.JAVASCRIPT="SC",t.JAVA="RJ",t.PROCEDURE="SP",t.EMBEDDED="EB"}(z||(z={}));class O{constructor(t){this.actionType=t,this._application=o.getContextValue("__SNK__APPLICATION__")}get executor(){switch(this.actionType){case z.LAUNCH_SCREEN:return new x;case z.JAVASCRIPT:return new C;case z.JAVA:return new y;case z.PROCEDURE:return new S;default:throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType",{actionType:this.actionType}))}}}!function(t){t.NONE="NONE",t.PARENT="PARENT",t.MASTER="MASTER",t.ALL="ALL"}(A||(A={}));const P="__MASTER_ROW__";class N{constructor(t,i,s){var e;this._lastValuesCache={},this._actionsExecuteInterface=t,this._dataUnit=i,this._selectedRows=(null===(e=null==i?void 0:i.getSelectionInfo())||void 0===e?void 0:e.isAllRecords())?[]:null==i?void 0:i.getSelectionInfo().records,this._application=o.getContextValue("__SNK__APPLICATION__"),this._appResourceId=s}getPrimaryKeys(){return m(this._dataUnit).map((({name:t})=>t))}apply(t,i){this._application.closePopUp(),this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:s,callback:e})=>{this.resolvePromptParams(t,s,i).then((()=>{this.actionExecute(s,e)}))}))}async execute(t){var i;if(!t.actionConfig)throw new l(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction",{description:t.description}));if(null===(i=t.actionConfig.params)||void 0===i?void 0:i.promptParam){const i=t.actionConfig.params.promptParam;let s=!1;for(let t=0;t<i.length;t++)if(!s&&"true"===i[t].saveLast){s=!0;break}s&&(t.actionConfig.params.promptParam=await this.loadSavedValuesIntoParams(t));const e=document.createElement("snk-actions-form");window.document.body.appendChild(e),e.action=c.copy(t),e.applyParameters=t=>{this.apply(t,s)},e.openPopup()}else t.type!=z.LAUNCH_SCREEN?this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:t,callback:i})=>{this.actionExecute(t,i)})):this._actionsExecuteInterface.execute(t,this._dataUnit)}loadSavedValuesIntoParams(t){return this.loadLastValues(t).then((i=>{let s=t.actionConfig.params.promptParam;return i&&i.param.forEach((t=>{s=s.map((i=>i.name!==t.paramName?i:Object.assign(Object.assign({},i),"B"===i.paramType?{value:"S"===t.$}:{value:t.$})))})),s}))}actionExecute(t,i){t.virtualPage=this.buildVirtualPage(),this.prepareAndExecute(t,i),this.recordsReloader(t.refreshType)}resolvePromptParams(t,i,s){return new Promise((e=>{let n=[];t.actionConfig.params.promptParam.forEach((t=>{n.push(this.buildPromptParam(t))})),this.putParamsOnExecSource(n,i),s&&this.saveLastValues(t,n),e()}))}buildPromptParam(t){let i,s,e=t.paramType,n=!1,o=t.value;switch(e){case f.DATE:e="D";break;case f.DATETIME:e="H";break;case f.DECIMAL:e="F",i={"sk-precision":Number(t.precision)};break;case f.BOOLEAN:e="S",n=!0,o=t.value?"S":"N";break;case f.ENTITY:i={"sk-entity-name":t.entityName,"sk-allow-show-hierarchical-mode":t.hierarchyEntity,"sk-data-type":"S"},t.hierarchyEntity&&t.entityPK&&(s=t.entityPK),o=t.value?Number(t.value):null;break;case f.OPTIONS:e="O";let r=t.options.split(";").map((function(t,i){let s,e;if(t.indexOf("=")>-1){let i=t.split("=");s=i[0],e=i[1]}else s=i+1,e=t;return{data:s,value:e}}));i={"sk-options":r}}return{description:t.label,required:"true"==t.required,fieldName:t.name,fieldNameOri:t.name,entityPK:s,paramType:t.paramType,type:e,isCheckbox:n,saveLast:t.saveLast,fieldProp:i,value:o,isGeneratedName:t.isGeneratedName}}putParamsOnExecSource(t,i){i.params={param:[]},t.forEach((t=>{if(t.isGeneratedName&&t.value)throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName",void 0));r.isEmpty(t.value)||i.params.param.push({type:this.getParamDataType(t.paramType),paramName:t.fieldName,$:this.getParamValue(t)})}))}getParamDataType(t){let i;switch(t){case"D":i="F";break;case"DT":case"DH":i="D";break;case"B":case"ENTITY":case"SO":i="S";break;default:i=t}return i}getParamValue(t){let i=t.value;return i?("DT"==t.paramType?i=d.formatDate(i):"DH"==t.paramType&&(i=d.formatDateTime(i)),i):i}async loadLastValues(t){const i=await this.buildResourceId(t.actionID);return new Promise(((t,s)=>{if(this._lastValuesCache[i])t(this._lastValuesCache[i]);else{const e={config:{chave:i,tipo:"T"}};g.get().callServiceBroker("SystemUtilsSP.getConf",e).then((s=>{var e,n;let o;(null===(n=null===(e=s.config)||void 0===e?void 0:e.data)||void 0===n?void 0:n.params)&&(o=s.config.data.params,Array.isArray(o.param)||(o.param=[o.param])),this._lastValuesCache[i]=o,t(o)})).catch((t=>{s(t)}))}}))}async saveLastValues(t,i){if(this._application){let s={params:{param:[]}};i.forEach((t=>{"true"==t.saveLast&&s.params.param.push({paramName:t.fieldName,$:t.value})}));const e=await this.buildResourceId(t.actionID);this._lastValuesCache[e]=s.params,this._application.saveConfig(e,s)}}async buildResourceId(t){return this._appResourceId+".actionconfig."+t}prepareAndExecute(t,i){this.addRows(t),i(t)}addRows(t){const i=this.getPrimaryKeys(),s={row:[]},e=this._selectedRows;for(const t in e){const n=e[t],o={};n.hasOwnProperty(P)&&(o.master="S",o.entityName=n.__ENTITY_NAME__,delete n[P],delete n.__ENTITY_NAME__),o.field||(o.field=[]);for(const t of i)o.field.push({fieldName:t,$:n[t]});s.row.push(o)}s.row.length>0&&(t.rows=s)}recordsReloader(t){switch(t){case A.NONE:break;case A.PARENT:case A.MASTER:case A.ALL:this._dataUnit.loadData();break;default:this._dataUnit.reloadCurrentRecord()}}buildVirtualPage(){var t,i,s,e;if(null===(i=null===(t=this._dataUnit)||void 0===t?void 0:t.getSelectionInfo())||void 0===i?void 0:i.isAllRecords())return{filters:{filters:null===(s=this._dataUnit)||void 0===s?void 0:s.getAppliedFilters()},orders:{orders:null===(e=this._dataUnit)||void 0===e?void 0:e.getSort()}}}}class D{async clientConfirm(t,i){return new Promise((s=>{const e=o.getContextValue("__SNK__APPLICATION__");let n="";t.content.event.hasOwnProperty("stpCall")?(i.requestBody=t.content.event.stpCall,n=z.PROCEDURE):t.content.event.hasOwnProperty("runScript")?(i.requestBody=t.content.event.runScript,n=z.JAVASCRIPT):t.content.event.hasOwnProperty("javaCall")&&(i.requestBody=t.content.event.javaCall,n=z.JAVA);let r={type:"S",sequence:t.content.event.sequence};i.requestBody.params?Array.isArray(i.requestBody.params.param)||(i.requestBody.params.param=[i.requestBody.params.param]):i.requestBody.params={param:[]},i.requestBody.params.param.push(r);const a=t.content.event.title.$,l=t.content.event.message.$;let c;switch(n){case z.JAVASCRIPT:c={runScript:i.requestBody};break;case z.PROCEDURE:c={requestBody:{stpCall:i.requestBody}};break;case z.JAVA:c={requestBody:{javaCall:i.requestBody}}}if("S"==t.content.event.showNoOption){r.paramName="__ESCOLHA_SIMNAO__";const t=document.createElement("snk-client-confirm");window.document.body.appendChild(t),t.titleMessage=a,t.message=l,t.accept=async()=>{r.$="S",await i.reCall(c),s()},t.cancel=async()=>{r.$="N",await i.reCall(c),s()},t.openPopup()}else e.confirm(a,l,null,"warn",{labelCancel:"Cancelar",labelConfirm:"Sim"}).then((async t=>{t&&(r.paramName="__CONFIRMACAO__",r.$="S",await i.reCall(c),s())}))}))}}const I=class{constructor(i){t(this,i),this.CLIENT_EVENT_CONFIRM_NAME="br.com.sankhya.actionbutton.clientconfirm",this.handleClick=t=>{const i=this._actions.find((i=>i.actionID==t.detail.id)),s=new O(i.type).executor;new N(s,this._dataUnit,this._resourceID).execute(Object.assign({},i)),this._showDropdown=!1},this._items=[],this._showDropdown=!1,this._actions=[],this._isOrderActions=!1}async getActions(){let t={param:{entityName:this._entityName,resourceID:this._resourceID}};return g.get().callServiceBroker("ActionButtonsSP.getActions",t).then((t=>{var i;(null===(i=t.actions)||void 0===i?void 0:i.action)&&(this._actions=this._isOrderActions?h.sortAlphabetically(t.actions.action,"description"):t.actions.action)}))}controlDropdown(){this._showDropdown=!this._showDropdown}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this._items)||void 0===t?void 0:t.length)>0}positionDropdown(){var t;const i=null===(t=this._ezButton)||void 0===t?void 0:t.getBoundingClientRect();i&&this._dropdownParent&&(this._dropdownParent.style.top=i.y+i.height+5+"px",this._dropdownParent.style.left=i.x+"px")}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest(".snk-actions-button")||(this._showDropdown=!1))}setEvents(){document.removeEventListener("click",this.closeDropdown.bind(this)),document.addEventListener("click",this.closeDropdown.bind(this)),document.removeEventListener("scroll",this.positionDropdown.bind(this)),document.addEventListener("scroll",this.positionDropdown.bind(this))}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),this._isOrderActions=await this._application.getBooleanParam("global.ordenar.acoes.personalizadas");const t=this._element.parentElement;this._dataUnit=null==t?void 0:t.dataUnit,this._resourceID=null==t?void 0:t.resourceID,this._entityName=this._dataUnit.name.split("/")[2],null==this._resourceID&&(this._resourceID=await p.getResourceID()),this.setEvents(),this.getActions().then((()=>{this.loadItems()}))}async componentDidLoad(){if(this._element&&(u.addIDInfo(this._element),this.positionDropdown(),!await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))){const t=new D;this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME,t.clientConfirm)}}componentDidUpdate(){this.positionDropdown()}loadItems(){this._actions&&0!=this._actions.length&&this._actions.forEach((t=>{this._items.push({id:t.actionID,label:t.description})}))}getElementID(t){return{[u.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:u.getInternalIDInfo(t)}}render(){return i(s,null,this._actions&&this._actions.length>0&&i("div",{class:`ez-padding-left--medium snk-actions-button\n ${this.canShowDropdown()?" ez-elevation--16":""}\n `},i("ez-button",Object.assign({ref:t=>this._ezButton=t,iconName:"acao",size:"small",mode:"icon",title:this._application.messagesBuilder.getMessage("snkActionsButton.title.actions",void 0),onClick:()=>this.controlDropdown()},this.getElementID("button"))),i("div",Object.assign({ref:t=>this._dropdownParent=t,class:(this.canShowDropdown()?"snk-actions-button__dropdown--show":"snk-actions-button__dropdown")+"\n "},this.getElementID("dropdown")),this.canShowDropdown()&&i("ez-dropdown",Object.assign({items:this._items,onEzClick:t=>this.handleClick(t)},this.getElementID("dropdown"))))),this.canShowDropdown()&&i("div",Object.assign({class:"ez-scrim ez-scrim--light"},this.getElementID("ezScrim"))))}get _element(){return e(this)}};I.style=".sc-snk-actions-button-h{display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";const E=class{constructor(i){t(this,i),this.configChange=n(this,"configChange",7),this.configCancel=n(this,"configCancel",7),this._orderListItems=[],this._orderPriorityList=[],this._columListItems=[],this._selectedIndex=-1,this._dataChanged=!1,this._componenteInternalKey=Date.now(),this.selectedIndex=0,this.columns=void 0,this.config=void 0,this.configName=void 0,this.resourceID=void 0}getMessage(t,i){return o.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage(t,i)}getSortableColumns(){let t=[];return this.columns.filter((t=>{var i;return r.getBooleanValue(null===(i=null==t?void 0:t.props)||void 0===i?void 0:i.get("sortable"),!0)})).forEach((i=>{var s;let e=null===(s=this.config)||void 0===s?void 0:s.columns.find((t=>t.name===i.name)),n={name:i.name,label:i.label};e&&(n.orderIndex=e.orderIndex,n.ascending=e.ascending),i.hidden||t.push(n)})),t}createOrderList(){let t=this.getSortableColumns();t.sort(((t,i)=>0!=t.orderIndex||0!=i.orderIndex||null==t.ascending&&null==i.ascending?null!=t.ascending&&null!=i.ascending?t.orderIndex-i.orderIndex:null!=t.ascending||null!=i.ascending?null!=t.ascending?-1:null!=i.ascending?1:0:t.orderIndex-i.orderIndex:null!=t.ascending?-1:null!=i.ascending?1:0)),this._orderListItems=t}createColumnList(){let t={group:this.getMessage("snkGridConfig.group.visible"),items:[]},i={group:this.getMessage("snkGridConfig.group.hidden"),items:[],sort:w.asc.value};this.columns.forEach((s=>{let e={label:s.label};s.hidden?i.items.push(e):t.items.push(e)})),this._columListItems=[t,i]}createColumnListSlotDataElementId(t){return`configItem_${r.replaceAccentuatedChars(r.toCamelCase(t.label))}`}buildColumnListSlot(t,s){const e=this.createColumnListSlotDataElementId(t);return i("div",null,i("ez-check",{mode:k.SWITCH,id:k.SWITCH+((null==t?void 0:t.label)||"")+((null==s?void 0:s.group)||""),value:s.group===this.getMessage("snkGridConfig.group.visible"),"data-element-id":e,onEzChange:i=>{this.switchColumnGroup(i,t)}}))}createOrderListSlotDataElementId(t){return`${this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME)}_configItem_${r.toCamelCase(t.label)}`}buildOrderListSlot(t){const s=this.createOrderListSlotDataElementId(t);let e=w.none.value;return null!=(null==t?void 0:t.ascending)&&(e=1==t.ascending?w.asc.value:w.desc.value),i("div",null,i("snk-select-box",{selectedOption:e,key:"snk-select-box-"+this._componenteInternalKey+"-"+t,"data-element-id":s,onEzChange:i=>{i.stopPropagation(),this.updateOrder(i.detail,t.label)}}))}updateOrder(t,i){var s;this._dataChanged=!0;let e,n=[...this.columns],o=n.find((t=>t.label===i));o&&(o.sort=t.value===w.none.value?void 0:t.value),(null===(s=this._orderPriorityList)||void 0===s?void 0:s.length)>0?(this._orderPriorityList.find((t=>t.label===o.label)).sort=t,this._orderPriorityList.filter((t=>t.sort)).forEach(((t,i)=>{t.label===o.label&&(o.sortIndex=i)}))):(e=n.filter((t=>t.sort&&!0!==t.hidden)).map(((t,i)=>({label:t.label,orderIndex:i}))),e.forEach((t=>{n.find((i=>i.label===t.label)).sortIndex=t.orderIndex}))),this.columns=n}switchColumnGroup(t,i){t.stopPropagation();let s=[...this._columListItems];if(this._dataChanged=!0,!0===t.detail){let t=s.find((t=>t.group===this.getMessage("snkGridConfig.group.hidden"))),e=t.items.findIndex((t=>t.label===i.label));e>=0&&t.items.splice(e,1),s.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))).items.push(i),this._columListItems=s,this.createOrderList()}else if(!1===t.detail){let t=s.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))),e=t.items.findIndex((t=>t.label===i.label));e>=0&&t.items.splice(e,1),s.find((t=>t.group===this.getMessage("snkGridConfig.group.hidden"))).items.push(i),this._columListItems=s,this.createOrderList()}}finish(){if(!this._dataChanged)return void this.closeConfig();let t=[];this._columListItems.forEach((i=>{i.items.forEach((s=>{const e=this.columns.find((t=>t.label===s.label));let n=Object.assign({},e);n.hidden=i.group===this.getMessage("snkGridConfig.group.hidden"),t.push(n)}))})),this.columns=t,this._dataChanged=!1,this.closeConfig(),this.save()}saveGridConfigOnStorage(t){_.saveGridConfig(t,this.configName,this.resourceID).then((t=>{this.configChange.emit(t),this._orderList.clearHistory(),v.info(this.getMessage("snkGridConfig.info.successfullyConfigSaved"),{iconName:"check"})}))}reOrderPriorityColumns(t,i){let s=[];s=t.filter((t=>t.sort&&!0!==t.hidden)).map((t=>({label:t.label,orderIndex:0})));let e=0,n=[];return i.forEach((t=>{let i=s.find((i=>i.label===t.label));i&&(i.orderIndex=e,n.push(i),e++)})),n.length>0&&(s=n),s}save(){var t;let i;i=this.config?this.config:this.createConfigFromState(this.columns);let s,e=[];(null===(t=this._orderPriorityList)||void 0===t?void 0:t.length)>0&&(s=this.reOrderPriorityColumns(this.columns,this._orderPriorityList)),this.columns.forEach((t=>{let n=i.columns.find((i=>t.name===i.name));!0===t.hidden&&n||(n?n.width=t.width:!1===t.hidden&&(n={name:t.name,width:t.width,orderIndex:0}),n&&(t.sort?(n.ascending=t.sort.toUpperCase()===w.asc.value,s?function(t,i){if(s){let e=s.find((i=>i.label===t.label));e&&(i.orderIndex=e.orderIndex)}}(t,n):n.orderIndex=t.sortIndex):(delete n.ascending,n.orderIndex=0),e.push(n)))})),i.columns=e,this.saveGridConfigOnStorage(i)}createConfigFromState(t){let i={columns:[]};return t.forEach((t=>{if(!t.hidden){let s={name:t.name};t.width&&(s.width=t.width),t.sort?(s.ascending=t.sort.toUpperCase()===w.asc.value,s.orderIndex=t.sortIndex):s.orderIndex=0,s&&i.columns.push(s)}})),i}async locateColumn(t,i){var s;const e="Enter"===t.key;if(!(i=i||(null===(s=t.currentTarget)||void 0===s?void 0:s.value)))return void this.removeSelection();const n=await this.getMatchedIndexes(i),o=this.getNewSelectedIndex(n,e);this._selectedIndex=o,1===this.selectedIndex?this.updateOrderListSelection(o):this.updateColumnListSelection(o)}async getMatchedIndexes(t){const i=[];return 1===this.selectedIndex?(await this._orderList.getList()).forEach(((s,e)=>{this.compareWords(s,t)&&i.push(e)})):this.columns.forEach(((s,e)=>{this.compareWords(s,t)&&i.push(e)})),i}getNewSelectedIndex(t,i){if(0===t.length)return-1;if(i)for(const i of t)if(i>this._selectedIndex)return i;return t[0]}updateOrderListSelection(t){-1!==t?this._orderList.getList().then((i=>{const s=i[t];s?this._orderList.setSelection(s,!0):this._orderList.removeSelection()})):this._orderList.removeSelection()}updateColumnListSelection(t){if(-1===t)return void this._columnList.removeSelection();const i=this.columns[t];if(i){const t=this._columListItems.map((t=>t.items)).flat().find((t=>t.label===i.label));t?this._columnList.setSelection(t,!0):this._columnList.removeSelection()}else this._columnList.removeSelection()}removeSelection(){1===this.selectedIndex?this._orderList.removeSelection():this._columnList.removeSelection()}compareWords(t,i){var s,e;const n=null===(s=r.replaceAccentuatedChars(null==t?void 0:t.label))||void 0===s?void 0:s.toUpperCase(),o=null===(e=r.replaceAccentuatedChars(i))||void 0===e?void 0:e.toUpperCase();return!r.isEmpty(n)&&!r.isEmpty(o)&&n.includes(o)}getColumnNames(){const t=[];return t.push(this.getMessage("snkGridConfig.tab.columns")),t.push(this.getMessage("snkGridConfig.tab.lineOrdering")),t.join(",")}closeConfig(){if(this._orderList.scrollToTop(),this._columnList.scrollToTop(),this._searchElement.value="",this._dataChanged){let t={canClose:!1,labelCancel:this.getMessage("snkGridConfig.confirm.cancel"),labelConfirm:this.getMessage("snkGridConfig.confirm.save"),btnConfirmDanger:!1};v.confirm(this.getMessage("snkGridConfig.confirm.alert"),this.getMessage("snkGridConfig.confirm.msgCancel"),null,b.WARN,t).then((t=>{t?this.finish():(this._dataChanged=!1,this.configCancel.emit(),this._orderList.clearHistory(),this._componenteInternalKey=Date.now())}))}else this.configCancel.emit(),this._orderList.clearHistory()}handleTabChange(t){null!=(null==t?void 0:t.index)&&(this.selectedIndex!==t.index&&(0===t.index?this._orderList.scrollToTop():1===t.index&&this._columnList.scrollToTop(),this._searchElement.value=""),1===t.index&&this.createOrderList(),this.selectedIndex=t.index)}handleColumnListChange(t){var i;if(t.detail){let s=null===(i=t.detail.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))))||void 0===i?void 0:i.items;s&&(this._dataChanged=!0,this._orderListItems=s)}}handleOrderListChange(t){if(t.detail){let i=t.detail;i&&(this._dataChanged=!0,this._orderPriorityList=i)}}componentWillRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.createColumnList()}componentDidRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.locateColumn(new KeyboardEvent("arrow-right",{key:"ArrowRight"}),this._searchElement.value)}componentDidLoad(){u.addIDInfo(this._element)}render(){return i(s,null,i("div",{class:"grid-config__header"},i("div",{class:"title-container"},i("div",{class:""},i("label",{class:"title"},this.getMessage("snkGridConfig.gridConfiguration")),i("label",{class:"subtitle"},this.getMessage("snkGridConfig.columnVisibilityOrder"))),i("div",{class:"button-close"},i("ez-button",{mode:"icon",iconName:"close",size:"medium",onClick:()=>this.closeConfig()}))),i("div",{class:"tabselector-container"},i("ez-tabselector",{selectedIndex:this.selectedIndex,onEzChange:t=>{this.handleTabChange(t.detail)},tabs:this.getColumnNames()})),i("div",null,i("ez-text-input",{"data-element-id":"searchColums",ref:t=>this._searchElement=t,label:this.getMessage("snkGridConfig.findColumn"),onKeyUp:t=>this.locateColumn(t)},i("ez-icon",{slot:"leftIcon",size:"medium",iconName:"search"})))),i("div",{class:"grid-config__main"},i("ez-list",{ref:t=>this._columnList=t,class:0===this.selectedIndex?"":"hidden",dataSource:this._columListItems,onEzChange:t=>this.handleColumnListChange(t),ezDraggable:!0,ezSelectable:!0,itemSlotBuilder:(t,i)=>this.buildColumnListSlot(t,i),useGroups:!0,"data-element-id":"configCols"}),i("div",{class:1===this.selectedIndex?"group-name":"hidden"},this.getMessage("snkGridConfig.info.sortingSequence")),i("ez-list",{ref:t=>this._orderList=t,class:1===this.selectedIndex?"height-calc":"hidden",dataSource:this._orderListItems,ezSelectable:!0,onEzChange:t=>this.handleOrderListChange(t),ezDraggable:!0,itemSlotBuilder:t=>this.buildOrderListSlot(t),"data-element-id":"configDataOrder"})),i("div",{class:"grid-config__footer"},i("ez-button",{class:"padding-right--medium",label:this.getMessage("snkGridConfig.cancel"),onClick:()=>this.closeConfig()}),i("ez-button",{label:this.getMessage("snkGridConfig.complete"),class:"ez-button--primary",onClick:()=>this.finish()})))}static get assetsDirs(){return["../assets"]}get _element(){return e(this)}};E.style='.sc-snk-grid-config-h{--snk-grid-config__footer--padding-top:var(--space--medium, 12px);--snk-grid-config__main--padding-right:var(--space--medium, 12px);--snk-grid-config__tabselector-container--padding:var(--space--medium, 12px);--snk-grid-config__button-close--padding-left:var(--space--medium, 12px);--snk-grid-config__title--color:var(--title--primary, #2B3A54);--snk-grid-config__title--font-family:var(--font-pattern, "Roboto");--snk-grid-config__title--font-size:var(--title--large, 20px);--snk-grid-config__title--font-weight:var(--text-weight--extra-large, 700);--snk-grid-config__subtitle--font-family:var(--font-pattern, "Roboto");--snk-grid-config__subtitle--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-family:var(--font-pattern, "Roboto");--snk-grid-config__group--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-weight:var(--text-weight--large, 600);--snk-grid-config__group--padding-bottom:var(--space-small, 6px);--snk-grid-config__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-grid-config__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-grid-config__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-grid-config__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-grid-config__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-grid-config__scrollbar--width:var(--space--medium, 12px);display:grid;grid-template-rows:auto 1fr auto;max-height:100%;width:100%}@media screen and (min-width: 480px){.sc-snk-grid-config-h{width:359px;max-width:359px}}.padding-right--medium.sc-snk-grid-config{padding-right:var(--space--medium)}ez-list.sc-snk-grid-config{height:100%}.height-calc.sc-snk-grid-config{max-height:calc(100% - 24px)}.grid-config__footer.sc-snk-grid-config{display:flex;justify-content:flex-end;width:100%;padding-top:var(--snk-grid-config__footer--padding-top)}.hidden.sc-snk-grid-config{display:none}.tabselector-container.sc-snk-grid-config{padding:var(--snk-grid-config__tabselector-container--padding) 0}.button-close.sc-snk-grid-config{padding-left:var(--snk-grid-config__button-close--padding-left)}.title-container.sc-snk-grid-config{display:flex;justify-content:space-between;align-items:center;width:100%}.title.sc-snk-grid-config{display:flex;margin:0;line-height:normal;letter-spacing:0em;text-align:left;color:var(--snk-grid-config__title--color);font-size:var(--snk-grid-config__title--font-size);font-family:var(--snk-grid-config__title--font-family);font-weight:var(--snk-grid-config__title--font-weight)}.subtitle.sc-snk-grid-config{color:var(--text--primary);font-size:var(--snk-grid-config__subtitle--font-size);font-family:var(--snk-grid-config__subtitle--font-family)}.grid-config__main.sc-snk-grid-config{overflow-y:auto;scrollbar-width:thin;scrollbar-color:var(--snk-grid-config__scrollbar--color-clicked) var(--snk-grid-config__scrollbar--color-background);padding-right:var(--snk-grid-config__main--padding-right)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar{width:var(--snk-grid-config__scrollbar--width);max-width:var(--snk-grid-config__scrollbar--width);min-width:var(--snk-grid-config__scrollbar--width);background-color:var(--snk-grid-config__scrollbar--color-background)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-track{background-color:var(--snk-grid-config__scrollbar--color-background);border-radius:var(--snk-grid-config__scrollbar--border-radius)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb{background-color:var(--snk-grid-config__scrollbar--color-default);border-radius:var(--snk-grid-config__scrollbar--border-radius)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:vertical:hover,.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-grid-config__scrollbar--color-hover)}.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:vertical:active,.grid-config__main.sc-snk-grid-config::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-grid-config__scrollbar--color-clicked)}.group-name.sc-snk-grid-config{font-family:var(--snk-grid-config__group--font-family);font-size:var(--snk-grid-config__group--font-size);font-weight:var(--snk-grid-config__group--font-weight);padding-bottom:var(--snk-grid-config__group--padding-bottom)}';const j=class{constructor(i){t(this,i),this.ezChange=n(this,"ezChange",7),this.selectedOption=w.none}render(){return i("ez-combo-box",{class:"grid-config-combo ez-input--inverted",label:"",suppressSearch:!0,value:this.selectedOption,enabled:!0,canShowError:!1,suppressEmptyOption:!0},Object.keys(w).map((t=>i("option",{value:w[t].value},w[t].label))))}static get assetsDirs(){return["../assets"]}};j.style="ez-combo-box{width:100px}.grid-config-combo{--ez-text-input--height:28px;--ez-text-input__input--background-color:#fff;--ez-text-input__input--border-color:#dce0e8}";const L=class{constructor(i){t(this,i),this.taskbarActionSelected=n(this,"taskbarActionSelected",7),this.taskbarActionsOpened=n(this,"taskbarActionsOpened",7),this.taskbarActionsButtonDisconnected=n(this,"taskbarActionsButtonDisconnected",7),this._showDropdown=!1,this.title=void 0,this.enabled=void 0,this.actions=void 0}async handleKeyDown(t){"Escape"!==t.key&&"Esc"!==t.key||await this.hideActions()}async handleClose(){await this.hideActions()}async showActions(){this._showDropdown=!0,requestAnimationFrame((()=>{this._element.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}))}async hideActions(){this._showDropdown=!1}async isOpened(){return this._showDropdown}controlDropdown(){this._showDropdown=!this._showDropdown}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this.actions)||void 0===t?void 0:t.length)>0}onSelectAction(t){const i=this.actions.map((t=>Object.assign(Object.assign({},t),{id:t.value}))),s=this.getSelectedAction(t.id,i);this.taskbarActionSelected.emit(s),s.disableCloseOnSelect||(this._showDropdown=!1)}getSelectedAction(t,i){let s=null;for(const e of i){if(e.id===t){s=e;break}if((null==e?void 0:e.children)&&(s=this.getSelectedAction(t,e.children),s))break}return s}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._element,e);return"string"==typeof n?i("div",{innerHTML:n}):n}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._element,t))}))}componentDidLoad(){this.initializeEagerItems()}componentDidRender(){this._showDropdown&&this.taskbarActionsOpened.emit(this._element)}disconnectedCallback(){this.taskbarActionsButtonDisconnected.emit()}render(){return i(s,null,i("div",{class:this.canShowDropdown()?" ez-elevation--16":""},i("ez-button",{title:this.title,mode:"icon",iconName:"dots-vertical",size:"small",enabled:this.enabled,onClick:()=>this.controlDropdown()}),this.canShowDropdown()&&i("ez-dropdown",{items:this.loadItems(),onEzClick:t=>this.onSelectAction(t.detail),onEzOutsideClick:()=>this._showDropdown=!1,itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)})))}get _element(){return e(this)}};L.style=".sc-taskbar-actions-button-h{display:flex;width:fit-content;height:fit-content}";export{I as snk_actions_button,E as snk_grid_config,j as snk_select_box,L as taskbar_actions_button}