@sankhyalabs/sankhyablocks 8.16.0-dev.41 → 8.16.0-dev.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/dist/cjs/{ConfigStorage-ecc0ed20.js → ConfigStorage-f079f5fd.js} +2 -2
  2. package/dist/cjs/{ContinuousInsertUtils-37c7cbcf.js → ContinuousInsertUtils-64e47516.js} +4 -4
  3. package/dist/cjs/{DataFetcher-cadeef8e.js → DataFetcher-e059eb72.js} +7 -5
  4. package/dist/cjs/{SnkFormConfigManager-f1c92f79.js → SnkFormConfigManager-63369164.js} +2 -2
  5. package/dist/cjs/{auth-fetcher-d68841bc.js → auth-fetcher-4f853233.js} +1 -1
  6. package/dist/cjs/{dataunit-fetcher-a36ae041.js → dataunit-fetcher-228016f4.js} +1 -1
  7. package/dist/cjs/{form-config-fetcher-ed497282.js → form-config-fetcher-39397ac5.js} +1 -1
  8. package/dist/cjs/{pesquisa-fetcher-490a86c3.js → pesquisa-fetcher-a9bfeb22.js} +1 -1
  9. package/dist/cjs/snk-actions-button_4.cjs.entry.js +5 -5
  10. package/dist/cjs/snk-application.cjs.entry.js +101 -59
  11. package/dist/cjs/snk-attach.cjs.entry.js +5 -5
  12. package/dist/cjs/snk-config-options_3.cjs.entry.js +4 -4
  13. package/dist/cjs/snk-crud.cjs.entry.js +5 -5
  14. package/dist/cjs/snk-data-exporter.cjs.entry.js +5 -5
  15. package/dist/cjs/{snk-data-unit-b460f1da.js → snk-data-unit-3d4d0e2a.js} +1 -1
  16. package/dist/cjs/snk-data-unit.cjs.entry.js +3 -3
  17. package/dist/cjs/snk-detail-view.cjs.entry.js +7 -7
  18. package/dist/cjs/snk-filter-bar_4.cjs.entry.js +3 -3
  19. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
  20. package/dist/cjs/snk-grid.cjs.entry.js +6 -6
  21. package/dist/cjs/{snk-guides-viewer-de0a5c57.js → snk-guides-viewer-eee43c8b.js} +8 -5
  22. package/dist/cjs/snk-guides-viewer.cjs.entry.js +7 -7
  23. package/dist/cjs/snk-personalized-filter.cjs.entry.js +3 -3
  24. package/dist/cjs/snk-simple-crud.cjs.entry.js +7 -7
  25. package/dist/collection/components/snk-application/request-listener/DebouncedRequestListener.js +28 -0
  26. package/dist/collection/components/snk-application/request-listener/RequestListenerFactory.js +16 -0
  27. package/dist/collection/components/snk-application/request-listener/RequestListenerLoadingBar.js +52 -0
  28. package/dist/collection/components/snk-application/snk-application.js +3 -53
  29. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +3 -0
  30. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +8 -6
  31. package/dist/components/DataFetcher.js +7 -5
  32. package/dist/components/snk-application2.js +95 -53
  33. package/dist/components/snk-detail-view2.js +3 -0
  34. package/dist/esm/{ConfigStorage-7b36d041.js → ConfigStorage-6514d66e.js} +2 -2
  35. package/dist/esm/{ContinuousInsertUtils-881c41a9.js → ContinuousInsertUtils-b62906f9.js} +4 -4
  36. package/dist/esm/{DataFetcher-a9c598f2.js → DataFetcher-5034df59.js} +7 -5
  37. package/dist/esm/{SnkFormConfigManager-f1a0fc92.js → SnkFormConfigManager-b409c745.js} +2 -2
  38. package/dist/esm/{auth-fetcher-749d880f.js → auth-fetcher-ca5d3a49.js} +1 -1
  39. package/dist/esm/{dataunit-fetcher-fd58c640.js → dataunit-fetcher-56cb648b.js} +1 -1
  40. package/dist/esm/{form-config-fetcher-adbe5d34.js → form-config-fetcher-a7d3e277.js} +1 -1
  41. package/dist/esm/{pesquisa-fetcher-50fc7e6b.js → pesquisa-fetcher-6bc2e41a.js} +1 -1
  42. package/dist/esm/snk-actions-button_4.entry.js +5 -5
  43. package/dist/esm/snk-application.entry.js +101 -59
  44. package/dist/esm/snk-attach.entry.js +5 -5
  45. package/dist/esm/snk-config-options_3.entry.js +4 -4
  46. package/dist/esm/snk-crud.entry.js +5 -5
  47. package/dist/esm/snk-data-exporter.entry.js +5 -5
  48. package/dist/esm/{snk-data-unit-590225b5.js → snk-data-unit-618e0b80.js} +1 -1
  49. package/dist/esm/snk-data-unit.entry.js +3 -3
  50. package/dist/esm/snk-detail-view.entry.js +7 -7
  51. package/dist/esm/snk-filter-bar_4.entry.js +3 -3
  52. package/dist/esm/snk-filter-modal-item.entry.js +3 -3
  53. package/dist/esm/snk-grid.entry.js +6 -6
  54. package/dist/esm/{snk-guides-viewer-2f4dcdc5.js → snk-guides-viewer-e8ca764a.js} +8 -5
  55. package/dist/esm/snk-guides-viewer.entry.js +7 -7
  56. package/dist/esm/snk-personalized-filter.entry.js +3 -3
  57. package/dist/esm/snk-simple-crud.entry.js +7 -7
  58. package/dist/sankhyablocks/{p-f3434fc4.js → p-00278e07.js} +1 -1
  59. package/dist/sankhyablocks/{p-fadc8339.js → p-0e206e62.js} +1 -1
  60. package/dist/sankhyablocks/{p-242d010e.entry.js → p-0e250436.entry.js} +1 -1
  61. package/dist/sankhyablocks/{p-06421fdb.js → p-126c58ea.js} +1 -1
  62. package/dist/sankhyablocks/{p-6114ee36.entry.js → p-1dbd5c18.entry.js} +1 -1
  63. package/dist/sankhyablocks/{p-fa6c5826.entry.js → p-30ebcbe0.entry.js} +1 -1
  64. package/dist/sankhyablocks/{p-8a9638ae.js → p-341465ce.js} +2 -2
  65. package/dist/sankhyablocks/{p-052213ba.entry.js → p-3858a2e4.entry.js} +1 -1
  66. package/dist/sankhyablocks/p-42130213.entry.js +1 -0
  67. package/dist/sankhyablocks/{p-cefb0ee1.entry.js → p-43353d86.entry.js} +1 -1
  68. package/dist/sankhyablocks/{p-47bce500.js → p-47d24ac8.js} +1 -1
  69. package/dist/sankhyablocks/{p-275de842.entry.js → p-563b7c28.entry.js} +1 -1
  70. package/dist/sankhyablocks/{p-72c10005.entry.js → p-9c3138f5.entry.js} +1 -1
  71. package/dist/sankhyablocks/{p-4d9549cf.js → p-9ffd9fc7.js} +1 -1
  72. package/dist/sankhyablocks/{p-0b6cd238.entry.js → p-a2c790ac.entry.js} +1 -1
  73. package/dist/sankhyablocks/{p-fd13b4d2.js → p-a75e9dcc.js} +1 -1
  74. package/dist/sankhyablocks/{p-212213d9.entry.js → p-aa003d4e.entry.js} +1 -1
  75. package/dist/sankhyablocks/p-aaf94476.js +1 -0
  76. package/dist/sankhyablocks/{p-583517ba.entry.js → p-c1adf0dd.entry.js} +1 -1
  77. package/dist/sankhyablocks/p-da87e42c.entry.js +11 -0
  78. package/dist/sankhyablocks/{p-7bd9683d.js → p-e3a285a2.js} +1 -1
  79. package/dist/sankhyablocks/{p-cfa1b199.js → p-e4391e16.js} +1 -1
  80. package/dist/sankhyablocks/{p-5e51e833.entry.js → p-f0aaad2b.entry.js} +1 -1
  81. package/dist/sankhyablocks/{p-fb34e0cf.entry.js → p-fca0e5cc.entry.js} +1 -1
  82. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  83. package/dist/types/components/snk-application/request-listener/DebouncedRequestListener.d.ts +11 -0
  84. package/dist/types/components/snk-application/request-listener/RequestListenerFactory.d.ts +12 -0
  85. package/dist/types/components/snk-application/request-listener/RequestListenerLoadingBar.d.ts +13 -0
  86. package/dist/types/components/snk-application/snk-application.d.ts +3 -12
  87. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -0
  88. package/package.json +1 -1
  89. package/dist/sankhyablocks/p-ab1645fb.entry.js +0 -1
  90. package/dist/sankhyablocks/p-ca5ec380.js +0 -1
  91. package/dist/sankhyablocks/p-dbe6174a.entry.js +0 -11
@@ -1,4 +1,4 @@
1
- import{d as e,D as t}from"./p-f3434fc4.js";import{ObjectUtils as r}from"@sankhyalabs/core";class s{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchResource",e.gql`query($name: String!) {
1
+ import{d as e,D as t}from"./p-00278e07.js";import{ObjectUtils as r}from"@sankhyalabs/core";class s{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchResource",e.gql`query($name: String!) {
2
2
  $queryAlias$: fetchResource(name: $name){
3
3
  resource
4
4
  }
@@ -1 +1 @@
1
- import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-4d9549cf.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-23736d75.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as v,a as E,R as f,b as p}from"./p-cfa1b199.js";import{SelectionMode as R}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-f3434fc4.js";import"./p-8a9638ae.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 O}from"./p-7dd49d15.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class b extends k{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}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 O(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}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__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const C=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new v,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async findColumn(){await g(this._moreOptions,this._columnSearch)}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){this.hasToBlockEvent(i)&&(i.preventDefault(),i.stopPropagation(),await this._dataUnit.cancelEdition())}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?h.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,E.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new b(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),E.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new f,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new p(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(h.CLONE,"ATTACH",h.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===R.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(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=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?h.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};C.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding)}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}";export{C as snk_grid}
1
+ import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-9ffd9fc7.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-23736d75.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as v,a as E,R as f,b as p}from"./p-e4391e16.js";import{SelectionMode as R}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-00278e07.js";import"./p-341465ce.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-47d24ac8.js";import"./p-ff1990ad.js";import"./p-126c58ea.js";import{g as O}from"./p-7dd49d15.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class b extends k{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}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 O(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}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__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const C=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new v,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async findColumn(){await g(this._moreOptions,this._columnSearch)}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){this.hasToBlockEvent(i)&&(i.preventDefault(),i.stopPropagation(),await this._dataUnit.cancelEdition())}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?h.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,E.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new b(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),E.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new f,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new p(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(h.CLONE,"ATTACH",h.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===R.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(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=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?h.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};C.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding)}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}";export{C as snk_grid}
@@ -1 +1 @@
1
- import{r as i,c as t,h as o,H as n,g as s}from"./p-d2d301a6.js";import{UserInterface as e,ObjectUtils as l,StringUtils as a,ApplicationContext as r,ElementIDUtils as d,ArrayUtils as h}from"@sankhyalabs/core";import{DataType as c,getConvertedValue as f}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{CheckMode as u,ApplicationUtils as g,DialogType as m}from"@sankhyalabs/ezui/dist/collection/utils";import{c as v,D as b,d as p,C as z,a as _,b as k,A as C}from"./p-95ce311a.js";import{S as x}from"./p-fadc8339.js";import{R as y}from"./p-688dcb4c.js";import{S as F}from"./p-fa816fb2.js";import{U as w}from"./p-06421fdb.js";import{buildFormConfigFromDataUnit as D}from"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-4d9549cf.js";import"./p-ff1990ad.js";import"./p-f3434fc4.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const E=class{constructor(o){i(this,o),this.configOptionsChanged=t(this,"configOptionsChanged",7),this._defaultType=void 0,this.fieldConfig={},this.idConfig=void 0,this.dataUnit=void 0,this.messagesBuilder=void 0}onConfigDefault(i){null!=i&&(this._defaultType=i,this.fieldConfig.defaultValue={type:this._defaultType},this.configOptionsChanged.emit(this.fieldConfig))}buildOptions(){var i,t,o;let n=null===(o=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(t=this.fieldConfig)||void 0===t?void 0:t.name))||void 0===o?void 0:o.userInterface;return n===e.SEARCH&&(n=e.INTEGERNUMBER),v.UserInterface[n]}enabledValueDefault(){var i,t,o;const n=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(t=this.fieldConfig)||void 0===t?void 0:t.name),s=null===(o=null==n?void 0:n.properties)||void 0===o?void 0:o.allowDefault,l=v.UserInterface.hasOwnProperty(null==n?void 0:n.userInterface)||(null==n?void 0:n.userInterface)===e.SEARCH;return!(null!=s&&"true"!==s||!l)}isAllowDefault(){var i,t;const o=null===(t=null===(i=this._fieldProperties)||void 0===i?void 0:i.properties)||void 0===t?void 0:t.allowDefault;return null==o||"true"===o}loadDefaultValue(){var i;null==this.fieldConfig?(this._defaultType=b.fixed,this.fieldConfig={defaultValue:{type:this._defaultType}}):null==(null===(i=this.fieldConfig.defaultValue)||void 0===i?void 0:i.type)?(this._defaultType=b.fixed,this.fieldConfig.defaultValue={type:this._defaultType}):this._defaultType=this.fieldConfig.defaultValue.type}getFieldProperties(i){var t;if(null!=i)return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}getDefaultType(){var i;return null!==(i=this.fieldConfig.defaultValue.type)&&void 0!==i?i:b.fixed}getEnabledByProperty(i,t){const o=this._fieldProperties;if(null==o)return!0;const n=o.properties||{};return n.hasOwnProperty(t)?"S"!==n[t]:!0!==o[i]}getValueByProperty(i){const t=this._fieldProperties;return null!=t&&!0===t[i]||this.fieldConfig[i]}getValidatedValue(i){var t,o;if(null==i)return;const n=null===(t=this.dataUnit)||void 0===t?void 0:t.getField(null===(o=this.fieldConfig)||void 0===o?void 0:o.name),s=null==n?void 0:n.dataType;if(null==s)return;const e=null!=(null==i?void 0:i.waitmessage)?void 0:s!==c.OBJECT&&s!==c.DATE&&"object"==typeof i?i.value:i;return s===c.OBJECT?JSON.stringify(e):e}buildInputDefault({value:i,enabled:t,label:n,name:s,required:a,userInterface:r},d,h){let c,f=0,u=0;const g=null==r||null==p[r]?p.DEFAULT:p[r];if(r===e.OPTIONSELECTOR){const i=null==d?void 0:d.options;if("string"==typeof i){const t=l.stringToObject(i);c=Object.keys(t).map((i=>({value:i,label:t[i]})))}else c=i}else r===e.DECIMALNUMBER&&(f=Number((null==d?void 0:d.precision)||2),u=Number((null==d?void 0:d.prettyPrecision)||f));return o(g,Object.assign({value:i,enabled:t,label:n,"data-field-name":s,key:s,onEzChange:i=>this.onChange(null==i?void 0:i.detail)},this.getConditionalAttributes(r,a,c,f,u,h)))}getConditionalAttributes(i,t,o,n,s,l){switch(i){case e.SEARCH:return{suppressEmptyOption:t,optionLoader:i=>this.onSearch(i)};case e.OPTIONSELECTOR:return{suppressEmptyOption:t,options:o};case e.CHECKBOX:case e.SWITCH:return{mode:l};case e.INTEGERNUMBER:case e.DECIMALNUMBER:return{precision:n,prettyPrecision:s,onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};case e.DATE:case e.DATETIME:case e.TIME:return{onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};default:return{}}}onChange(i){this.fieldConfig.defaultValue.value=this.getValidatedValue(i),this.configOptionsChanged.emit(this.fieldConfig)}onSearch(i){if(null!=this._application&&null!=this.fieldConfig)return this._application.executeSearch(i,this.fieldConfig.name,this.dataUnit)}buildField(i,t){const{name:o,label:n,readOnly:s,required:l,defaultValue:r}=t,{userInterface:d,properties:h}=i;let c,g=a.getBooleanValue(null==h?void 0:h.allowDefault,!s);d===e.FILE&&(g=!1),g&&(c=null==r?void 0:r.value,null!=c&&(c=f(null==i?void 0:i.dataType,c)));const m={value:c,enabled:g,label:n,name:o,required:l,userInterface:d};switch(d){case e.SWITCH:return this.buildInputDefault(m,void 0,u.SWITCH);case e.CHECKBOX:return this.buildInputDefault(m,void 0,u.REGULAR);case e.OPTIONSELECTOR:case e.DECIMALNUMBER:return this.buildInputDefault(m,h);default:return this.buildInputDefault(m)}}componentWillLoad(){var i;this.loadDefaultValue(),this._application=r.getContextValue("__SNK__APPLICATION__"),this._fieldProperties=this.getFieldProperties(null===(i=this.fieldConfig)||void 0===i?void 0:i.name)}componentDidLoad(){d.addIDInfo(this._element,this.fieldConfig.name)}render(){var i,t;return o(n,null,o("div",{id:this.idConfig},o("div",{class:"ez-row ez-padding--medium"},o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-text-input",{label:this.getMessage("snkConfigOptions.label.nameField"),value:null===(i=this.fieldConfig)||void 0===i?void 0:i.label,onEzChange:i=>{this.fieldConfig.label=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.typeValueDefault"),suppressEmptyOption:!0,enabled:this.enabledValueDefault(),onEzChange:i=>{var t;return this.onConfigDefault(null===(t=i.detail)||void 0===t?void 0:t.value)},value:this.getDefaultType()},o("option",{value:b.fixed},this.getMessage("snkConfigOptions.options.valueFixed")),o("option",{value:b.variable},this.getMessage("snkConfigOptions.options.variable")))),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},this._defaultType===b.variable?o("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.valueDefault"),enabled:this.isAllowDefault(),onEzChange:i=>{var t;this.fieldConfig.defaultValue.value=null===(t=i.detail)||void 0===t?void 0:t.value,this.configOptionsChanged.emit(this.fieldConfig)},value:this.fieldConfig.defaultValue.value,options:this.buildOptions()}):(null===(t=this._fieldProperties)||void 0===t?void 0:t.userInterface)&&this.buildField(this._fieldProperties,this.fieldConfig))),o("div",{class:"ez-row ez-padding--medium config-options__switch-row"},o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.clearDuplicate"),value:this.fieldConfig.cleanOnCopy,onEzChange:i=>{this.fieldConfig.cleanOnCopy=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.requiredField"),enabled:this.getEnabledByProperty("required","systemRequired"),value:this.getValueByProperty("required"),onEzChange:i=>{this.fieldConfig.required=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.protectedField"),enabled:this.getEnabledByProperty("readOnly","systemReadOnly"),value:this.getValueByProperty("readOnly"),onEzChange:i=>{this.fieldConfig.readOnly=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})))))}get _element(){return s(this)}};E.style=".sc-snk-config-options-h{--snk-config-options--border:2px solid var(--color--secondary-200, #D2D3DA);width:100%;border-radius:15px;border:var(--snk-config-options--border)}.config-options__switch-row.sc-snk-config-options{margin-top:-30px}";const T=class{constructor(o){i(this,o),this.exit=t(this,"exit",7),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this._customEditors=new Map,this._dataUnit=void 0,this._dataState=void 0,this._showFormConfig=!1,this._configManager=void 0,this.configName=void 0,this.recordsValidator=void 0,this.messagesBuilder=void 0,this.formLegacyConfigName=void 0,this.resourceID=void 0}async showConfig(){this._showFormConfig=!0}async hideConfig(){this._showFormConfig=!1}async addCustomEditor(i,t){if(this._form)return void this._form.addCustomEditor(i,t);const o=new Map(this._customEditors);o.set(i,t),this._customEditors=o}async setFieldProp(i,t,o){await this._form.setFieldProp(i,t,o)}closeConfig(){this.hideConfig()}dataunitReady(){d.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}setCustomEditors(){if(this._form)for(const[i,t]of this._customEditors)this._form.addCustomEditor(i,t),this._customEditors.delete(i)}async componentDidRender(){this.setCustomEditors()}async componentWillLoad(){let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.dataunitReady():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail})),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this));break}i=i.parentElement}null==this.resourceID&&(this.resourceID=await y.getResourceID()),this._configManager=new x(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const o=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of o||[]){if(!i)continue;const o=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(o||0===o)&&(await this.setFieldProp(i,"precision",o),await this.setFieldProp(i,"prettyPrecision",o))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return o("section",null,o("div",{class:"ez-row"},o("div",{class:"ez-col ez-col--sd-12"},o("ez-form",{ref:i=>this._form=i,key:"ezForm"+this._snkDataUnit.entityName,"data-element-id":"embedded",dataUnit:this._dataUnit,config:this._configManager.getConfig(this._dataUnit),recordsValidator:this.recordsValidator,class:this._showFormConfig?"snk-form__form--hidden":""}),this._showFormConfig&&o("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return s(this)}};T.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const O="EZ-COLLAPSIBLE-BOX",S="fieldsWithoutGroupContainer",A="fieldsAvailableContainer",L="addNewGroupContainer",I=class{constructor(o){i(this,o),this.configChange=t(this,"configChange",7),this.configClose=t(this,"configClose",7),this._listEnabledFields=[],this._renderTimer=500,this._tabSelected=1,this._labelNewGroup="Novo grupo",this._mouseOnFieldConfig=!1,this._mouseOnConfigOptions=!1,this._editingTitleGroup=!1,this._newGroupBoxes=[],this._currentGroupBoxes=[],this._formFieldsStyle="ez-col ez-col--sd-12 ez-col--tb-4 ez-padding-right--small ez-padding-bottom--medium sc-snk-form-config",this._fieldsAvailableStyle="ez-col ez-col--sd-12 ez-col--tb-12 ez-margin-bottom--medium ez-margin-right--medium sc-snk-form-config",this._fieldFloatingStyle="form-config__field-config--dragged",this._sortableTimer=100,this._formConfigOptions=[],this._fieldConfigSelected=void 0,this._layoutFormConfig=void 0,this._fieldsAvailable=void 0,this._formConfig={},this._formConfigChanged=!1,this._optionFormConfigSelected=void 0,this._optionFormConfigChanged=!1,this._tempGroups=[],this.dataUnit=void 0,this.configManager=void 0,this.messagesBuilder=void 0,this.ignoreReadOnlyFormFields=void 0}observeConfigManager(){this.loadConfig(this._sortableTimer)}loadFields(i=0){this._layoutFormConfig=[],i>0?setTimeout((()=>{this.buildFields()}),i):this.buildFields()}buildFields(){this.buildFormConfig(),this.buildAvailableFields()}loadFormConfig(i){var t;this._formConfig=this.getConfig(),this.loadFields(i),this.controlFieldConfig(),null!=(null===(t=this._filterFieldsAvailable)||void 0===t?void 0:t.value)&&(this._filterFieldsAvailable.value="")}getConfig(){let i=this.configManager.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=D(this.dataUnit)),l.copy(i)}cancelChangeConfig(){!0===this._formConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._formConfigChanged=!1,this.resetChangeConfig())})):this.resetChangeConfig()}cancelChangeOptionConfig(){!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._optionFormConfigChanged=!1,this.resetChangeOptionConfig())})):this.resetChangeOptionConfig()}resetChangeConfig(){this.loadFormConfig(this._sortableTimer),this.clearTempGroups()}resetChangeOptionConfig(){this._formConfigChanged=!1,this.loadConfig(this._sortableTimer),this.clearTempGroups()}getTabsToSave(){return this._layoutFormConfig.map(((i,t)=>({label:i.tab,order:t,visible:i.visible})))}getFieldsToSave(){const i=[];return this._formContainer.querySelectorAll("snk-field-config").forEach((t=>{const o=t.fieldConfig;if(null==o)return;const n={cleanOnCopy:o.cleanOnCopy||!1,group:o.group,label:o.label,name:o.name,required:o.required,readOnly:o.readOnly,tab:o.tab};null!=o.defaultValue&&(n.defaultValue=null==o.defaultValue.type?{type:b.fixed,value:o.defaultValue}:o.defaultValue),i.push(n)})),i}isDefaultConfiguration(){var i;return(null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin)===w.DEFAULT&&!0===this._optionFormConfigChanged&&!1===this._formConfigChanged}buildConfigToSave(){let i={};const t=this.isDefaultConfiguration();if(i=t?this.getConfig():l.copy(this._formConfig),!1===t){const t=this.getTabsToSave();(null==t?void 0:t.length)>0&&(i.tabs=t);const o=this.getFieldsToSave();(null==o?void 0:o.length)>0&&(i.fields=o)}return i.defaultConfiguration=t,i}saveConfig(){var i;(null===(i=this._tempGroups)||void 0===i?void 0:i.length)>0?g.alert(this.getMessage("snkFormConfig.confirm.title"),this.getMessage("snkFormConfig.confirm.group")):(this._formConfigChanged=!1,this._optionFormConfigChanged=!1,this.configManager.saveConfig(this.buildConfigToSave()).then((i=>{var t;g.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"});const o=null===(t=this._formConfigOptions)||void 0===t?void 0:t.find((i=>i.origin===w.USER));this.setFormConfig(o),this.configChange.emit(i)})))}applyOptionConfig(){if(!0===this._optionFormConfigChanged&&null!=this._optionFormConfigSelected){const i=this._optionFormConfigSelected.name||"configuração selecionada",t=this._optionFormConfigSelected.origin===w.DEFAULT?"pessoal":"padrão",o=this.getMessage("snkFormConfig.confirm.apply").replace("{0}",i).replace("{1}",t);this.openConfirmDialog(o).then((i=>{i&&this.saveConfig()}))}else this.saveConfig()}controlFieldConfig(i){var t;this._fieldConfigSelected=null!=i?(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===(null==i?void 0:i.name)?void 0:i:void 0}getFieldConfigStyle(i){var t;return this._formFieldsStyle+((null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name?" form-config__field-config--selected":"")}getFieldsByGroup(i){var t;return(null===(t=i.fields)||void 0===t?void 0:t.length)?i.fields.map((i=>{var t,n;return o("div",{key:i.name,class:this.getFieldConfigStyle(i),"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},o("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},modeInsertion:!1,fieldConfig:i,dataUnit:this.dataUnit,isConfigActive:(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name,id:i.name,key:i.name}),(null===(n=this._fieldConfigSelected)||void 0===n?void 0:n.name)===i.name&&o("div",{class:"ez-flex form-config__config-options"},o("snk-config-options",{idConfig:i.name,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,fieldConfig:this._fieldConfigSelected,"data-element-id":this._element.getAttribute(d.DATA_ELEMENT_ID_ATTRIBUTE_NAME),onConfigOptionsChanged:i=>this.handleconfigOptionsChanged(i.detail)})))})):o("div",{class:"form-config__add-group-container"},o("div",{class:"form-config__add-group-content"},o("div",{class:"form-config__add-group-label"},o("label",{class:"ez-text ez-text--center ez-text--medium ez-text--primary ez-text--bold"},this.getMessage("snkFormConfig.form.labelDropField")))))}handleconfigOptionsChanged(i){var t;null===(t=this._formConfig.fields)||void 0===t||t.forEach((()=>{})),this._formConfigChanged=!0}closeFormConfig(){!0===this._formConfigChanged||!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.exit")).then((i=>{i&&(this._formConfigChanged=!1,this.configClose.emit())})):this.configClose.emit()}openConfirmDialog(i="",t=this.getMessage("snkFormConfig.confirm.title")){return g.confirm(t,i)}controlMoveField(i){const t=null==i?void 0:i.target;null!=(null==t?void 0:t.closest('[data-draggable-element="field"]'))&&(this._mouseOnFieldConfig=!0,null!=(null==t?void 0:t.closest(".form-config__config-options"))||null!=(null==t?void 0:t.closest(".field-config__options"))?this._mouseOnConfigOptions=!0:!1===["minus","settings-inverted","chevron-up"].includes(null==t?void 0:t.iconName)&&this.controlFieldConfig())}controlStartDraggingField(i){var t,o,n;if(this._mouseOnConfigOptions)null==i||i.cancel(),this._mouseOnConfigOptions=!1;else{const s=null===(n=null===(o=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===o?void 0:o.data)||void 0===n?void 0:n.sourceContainer;null!=s&&s.classList.add(this._fieldFloatingStyle)}}controlSortedDraggingField(i){var t,o,n,s,e,l,a,r;const d=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.oldContainer,h=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.newContainer,c=null===(e=null===(s=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.source,f=null===(r=null===(a=null===(l=null==i?void 0:i.data)||void 0===l?void 0:l.dragEvent)||void 0===a?void 0:a.data)||void 0===r?void 0:r.originalSource;null!=d&&null!=h&&null!=c&&null!=f&&(h.tagName!==O&&h.id!==S||d.id!==A?d.tagName!==O&&d.id!==S||h.id!==A||(c.className=this._fieldsAvailableStyle,c.querySelector("snk-field-config").modeInsertion=!0,f.className=this._fieldsAvailableStyle,f.querySelector("snk-field-config").modeInsertion=!0):(c.className=this._formFieldsStyle,c.querySelector("snk-field-config").modeInsertion=!1,f.className=this._formFieldsStyle,f.querySelector("snk-field-config").modeInsertion=!1))}isCancelDragAvailableField(i,t,o){var n,s;return null!=i&&null!=t&&null!=o&&(null===(n=o.data)||void 0===n?void 0:n.newIndex)!==(null===(s=o.data)||void 0===s?void 0:s.oldIndex)&&i.id===A&&t.id===i.id&&(o.cancel(),this._fieldsAvailable=[],setTimeout((()=>{this.buildAvailableFields()}),this._sortableTimer),!0)}isRemoveField(i,t,o){if(null==i||null==t||null==o)return!1;if((t.tagName===O||t.id===S)&&i.id===A){const i={detail:{field:o,type:C.remove}};return setTimeout((()=>{this.handleFieldConfigChange(i)}),this._renderTimer),!0}return!1}isAddOrMoveField(i,t,o,n){var s;return null!=i&&null!=t&&null!=o&&null!=n&&(n.newIndex!==n.oldIndex||t.dataset.groupName!==i.dataset.groupName||i.id===S&&t.id===A)&&(this.isFieldAvailable(i,t)&&(o.tab=null===(s=this._tabConfig)||void 0===s?void 0:s.selectedTab),o.group=i.dataset.groupName,setTimeout((()=>{i.id.includes(L)&&this.clearTempGroups(!0),this.updateFieldsToSave(t.dataset.groupName!==i.dataset.groupName||i.id===S&&t.id===A?this._sortableTimer:0)}),this._renderTimer),!0)}isFieldAvailable(i,t){return null!=i&&null!=t&&(i.tagName===O||i.id===S)&&t.id===A}controlStopDraggingField(i){var t,o,n,s,e,l;const a=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.oldContainer,r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.newContainer;if(this.isCancelDragAvailableField(r,a,i))return;const d=null===(e=null===(s=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.originalSource,h=null===(l=null==d?void 0:d.querySelector("snk-field-config"))||void 0===l?void 0:l.fieldConfig;this.isRemoveField(r,a,h)||this.isAddOrMoveField(r,a,h,null==i?void 0:i.data)}updateFieldsToSave(i=0){const t=this.getFieldsToSave();(null==t?void 0:t.length)>0&&(this._formConfig.fields=t),this.loadFields(i),this._formConfigChanged=!0}controlSortableField(){null!=this._sortableContainer&&(this._sortableField&&this._sortableField.destroy(),this._sortableField=new F(this._sortableContainer.querySelectorAll('[data-draggable-parent="field"]'),{draggable:'[data-draggable-element="field"]',mirror:{constrainDimensions:!0},distance:z.dragStartDistance}),this._sortableField.on(_.dragStart,(i=>this.controlStartDraggingField(i))),this._sortableField.on(_.dragSorted,(i=>this.controlSortedDraggingField(i))),this._sortableField.on(_.dragStop,(i=>this.controlStopDraggingField(i))))}controlStartDraggingGroup(i){(this._mouseOnFieldConfig||this._editingTitleGroup)&&(null==i||i.cancel(),this._mouseOnFieldConfig=!1)}controlStopDraggingGroup(i){i.data.newIndex!==i.data.oldIndex&&setTimeout((()=>{this.updateFieldsToSave(this._sortableTimer)}),this._renderTimer)}controlSortableGroup(){null!=this._sortableContainer&&(this._sortableGroup&&this._sortableGroup.destroy(),this._sortableGroup=new F(this._sortableContainer.querySelectorAll('[data-draggable-parent="group"]'),{draggable:'[data-draggable-element="group"]',mirror:{constrainDimensions:!0},distance:z.dragStartDistance}),this._sortableGroup.on(_.dragStart,(i=>this.controlStartDraggingGroup(i))),this._sortableGroup.on(_.dragStop,(i=>this.controlStopDraggingGroup(i))))}loadUserConfig(){null!=this.configManager&&this.configManager.fetchUserAvailableConfigs().then((i=>{if(this._formConfigOptions=i,null==this._formConfigOptions)return;let t=null==this._formConfig||this._formConfig.defaultConfiguration;const o=i.find((i=>i.origin===(t?w.DEFAULT:w.USER)));this.setFormConfig(o)}))}setFormConfig(i){this._optionFormConfigSelected=i}controlSelectFormConfig(i){const t=null==i?void 0:i.detail,o=this._formConfigOptions.find((i=>i.origin===(null==t?void 0:t.value)));this.setFormConfig(o),this._optionFormConfigChanged=!0,this.loadConfigByUser()}changeTabOrder(i){const t=[],o=this._tabConfig.querySelectorAll(".tab-config__tab");this._tabSelected=i,o.forEach(((i,o)=>{var n;if(o){const s=null===(n=i.querySelector(".tab-config__tab-label"))||void 0===n?void 0:n.getAttribute("title");t.push({label:s,order:o-1})}})),this._layoutFormConfig.map((i=>{t.forEach((t=>{t.label===i.tab&&(t.visible=i.visible)}))})),t.length>0&&(this._formConfig.tabs=t,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}async loadConfigByUser(){if(null==this.configManager)return;if(null==this._optionFormConfigSelected)return;let i;this._optionFormConfigSelected.origin===w.DEFAULT?(i=await this.configManager.fetchDefaultConfig(),i||(i=this.configManager.getEmptyConfig())):i=this.getConfig(),null!=i&&(this._formConfig=i,this._tabSelected=1,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this.clearTempGroups())}loadConfig(i=0){this.loadFormConfig(i),this.loadUserConfig()}addNewGroup(){var i,t;const o=null===(i=this._tabConfig)||void 0===i?void 0:i.selectedTab;null==(null===(t=this._tempGroups)||void 0===t?void 0:t.find((i=>i.tab===o&&i.group.includes(this._labelNewGroup))))&&(this._tempGroups.push({tab:o,group:this.handleDuplicateGroups(this._labelNewGroup,this._tabConfig.selectedTab)}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0)}clearTempGroups(i=!1){var t;(null===(t=this._tempGroups)||void 0===t?void 0:t.length)>0&&(this._tempGroups=i?this._tempGroups.filter((i=>i.tab!==this._tabConfig.selectedTab)):[])}removeGroup(i){null!=i?this._tempGroups=this._tempGroups.filter(((t,o)=>o!==i&&t.tab===this._tabConfig.selectedTab||t.tab!==this._tabConfig.selectedTab)):this.updateFieldsToSave(this._sortableTimer)}checkGroupExists(i,t,o=!1){var n,s,e;const l=null===(n=this._tabConfig)||void 0===n?void 0:n.selectedTab,a=null===(s=this._layoutFormConfig)||void 0===s?void 0:s.find((i=>i.tab===l)),r=null===(e=null==a?void 0:a.groups)||void 0===e?void 0:e.map((i=>{var t;return null===(t=i.group)||void 0===t?void 0:t.toLowerCase()}));if(null==r?void 0:r.includes(null==i?void 0:i.toLowerCase())){const n=this.getMessage("snkFormConfig.confirm.title"),s=`\n ${this.getMessage("snkFormConfig.alert.titleGroupExists")}\n <b>${i}</b>\n ${this.getMessage("snkFormConfig.alert.inTab")}\n <b>${l===k.main?this.getMessage("snkFormConfig.form.mainArea"):l}</b>.\n <br/><br/>\n ${this.getMessage("snkFormConfig.alert.infoValidTitle")}\n `;return g.alert(n,s).then((()=>{var i,n;o?null===(i=this._newGroupBoxes[t])||void 0===i||i.applyFocusTextEdit():null===(n=this._currentGroupBoxes[l][t])||void 0===n||n.applyFocusTextEdit()})),!1}return!0}saveEditLabelTempGroup(i,t){const{newValue:o}=i.detail;null!=this._newGroupBoxes&&null!=this._newGroupBoxes[t]&&(this._newGroupBoxes[t].dataset.groupName=o)}saveEditLabelGroup(i){var t;const{value:o,newValue:n}=i.detail;null===(t=this._formConfig.fields)||void 0===t||t.forEach((i=>{i.group===o&&(i.group=n)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}renderTempGroupByTab(i){return this._tempGroups.map(((t,n)=>{if(t.tab===i)return o("ez-collapsible-box",{ref:i=>this._newGroupBoxes[n]=i,id:`${L}-${n}`,editable:!0,removable:!0,"header-size":"large",label:t.group,"icon-placement":"left","data-group-name":t.group,"data-draggable-parent":"field",class:"form-config__add-group",onEzRemove:()=>this.removeGroup(n),onEzSaveEditLabel:i=>this.saveEditLabelTempGroup(i,n),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,n,!0)},this.getFieldsByGroup(t))}))}handleDuplicateGroups(i,t){var o;const n=this._layoutFormConfig[this._tabConfig.selectedIndex].groups.map((i=>i.group));return null!=n&&(null===(o=this._layoutFormConfig)||void 0===o||o.map((o=>{o.tab===t&&o.groups.some((t=>t.group===i))&&(i+=`${this.captureHighestValueTitle(n)}`)}))),i}captureHighestValueTitle(i){let t=[];return null==i||i.map((i=>{null!=i&&t.push(i.replace(/[^0-9]/g,""))})),Math.max.apply(null,t)>0?` (${Math.max.apply(null,t)+1})`:" (1)"}getLayoutFormConfig(){var i,t;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=[],n=[];for(const i of this._formConfig.fields)if(null==n.find((t=>i.name===t.name&&i.tab===t.tab))){n.push(i);const s=this.dataUnit.getField(i.name);if(null==s?void 0:s.visible){null!=i.label&&""!==i.label||(i.label=s.label),null!=i.tab&&""!==i.tab||(i.tab=this.getMessage("snkFormConfig.form.tabGeneral"));let n=o.find((t=>t.tab===i.tab));if(null==n){let s=null;if(null!=this._formConfig.tabs){const t=this._formConfig.tabs.filter((t=>t.label===i.tab));t.length>0&&(s=t[0].visible)}const e=(null===(t=i.tab)||void 0===t?void 0:t.label)||i.tab;n=null!==s?{tab:e,groups:[],visible:s}:{tab:e,groups:[],visible:!0},o.push(n)}const e=n.groups.find((t=>t.group===i.group));if(e)e.fields.push(i);else{const t={group:i.group,fields:[i]};void 0===i.group?n.groups.unshift(t):n.groups.push(t)}}}return o}configureTabs(i){var t;return null==(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?i:(null==i&&(i=[]),this._formConfig.defaultConfiguration?i:this._formConfig.tabs.map((t=>i.find((i=>{var o,n;return(null===(o=t.label)||void 0===o?void 0:o.toLowerCase())===(null===(n=i.tab)||void 0===n?void 0:n.toLowerCase())}))||{tab:t.label,groups:[],visible:t.visible})))}configureTabMain(i){return null==i&&(i=[]),null==i.find((i=>i.tab===k.main))&&i.unshift({tab:k.main,groups:[],visible:!0}),i}updateTabs(){const i=this.getTabsToSave();(null==i?void 0:i.length)>0&&(this._formConfig.tabs=i,1===i.length&&(this._tabSelected=0))}buildFormConfig(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let t=this.getLayoutFormConfig();t=this.configureTabs(t),t=this.configureTabMain(t),this._layoutFormConfig=t,this.updateTabs()}buildAvailableFields(){var i,t;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=[],n=this.dataUnit.metadata.fields;for(const i of this._formConfig.fields)o.push(i);const s=n.filter((({name:i,visible:t})=>!0===t&&!1===o.some((({name:t})=>t===i))));this._fieldsAvailable=s,this._listEnabledFields=s,null!=(null===(t=this._filterFieldsAvailable)||void 0===t?void 0:t.value)&&this.onFilterChange(this._filterFieldsAvailable.value)}changeTabSelected(i){this._tabSelected=i.index;const t=this._formContainer.querySelector("div#tab"+i.index);this._formContainer.querySelectorAll(".form-config__tab-content").forEach((i=>i.className="form-config__hide-content sc-snk-form-config")),t&&(t.className="form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium sc-snk-form-config")}onFilterChange(i){this._fieldsAvailable=h.applyStringFilter(i,this._listEnabledFields,!0,"label")}orderFieldsAvailable(i){return h.sortAlphabetically(i)}handleLabelCounter(i){const t=[this.getMessage("snkFormConfig.availableFields.labelNoFields"),this.getMessage("snkFormConfig.availableFields.labelOneField")];return i>1?`${i} ${this.getMessage("snkFormConfig.availableFields.labelAvailableFields")}`:t[i]}controlAddFieldConfig(i){var t;if(this._formConfigChanged=!1,null==i)return;null==this._formConfig.fields&&(this._formConfig.fields=[]);const o=this._formConfig.fields.filter((t=>t.name===i.name&&t.tab&&i.tab));o.length>0?o.forEach((t=>{t.name=i.name,t.label=i.label,t.required=i.required,t.readOnly=i.readOnly,t.group=i.group})):this._formConfig.fields.push({name:i.name,label:i.label,required:i.required,readOnly:i.readOnly,group:i.group,tab:null===(t=this._tabConfig)||void 0===t?void 0:t.selectedTab}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables()}controlRemoveFieldConfig(i,t){var o;this._formConfigChanged=!1,null!=i&&(this._formConfig.fields=null===(o=this._formConfig.fields)||void 0===o?void 0:o.filter((t=>t.name!==i.name)),this.loadFields(t),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables())}resetSortables(){this.controlSortableField(),this.controlSortableGroup()}handleFieldConfigChange(i,t=0){const{field:o,type:n}=i.detail;n!==C.configuration?n!==C.remove?n!==C.add||this.controlAddFieldConfig(o):this.controlRemoveFieldConfig(o,t):this.controlFieldConfig(o)}changeTabLabel(i){var t,o;const{value:n,newValue:s}=i.detail.detail;null===(t=this._formConfig.fields)||void 0===t||t.forEach((i=>{i.tab===n&&(i.tab=s)})),null===(o=this._formConfig.tabs)||void 0===o||o.forEach((i=>{i.label===n&&(i.label=s)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleDeleteTab(i){let t={canClose:!1,labelCancel:this.getMessage("snkFormConfig.confirm.labelCancel"),labelConfirm:this.getMessage("snkFormConfig.confirm.labelDelete"),btnConfirmDanger:!1};const o=this.getMessage("snkFormConfig.confirm.title"),n=this.getMessage("snkFormConfig.confirm.deleteTab")+` <b>${i.detail.label}</b>?`;g.confirm(o,n,null,m.WARN,t).then((t=>{var o;t&&(this._formConfig.tabs=null===(o=this._formConfig.tabs)||void 0===o?void 0:o.filter((t=>t.label!==i.detail.label)),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}))}changeHideTab(i){var t;null===(t=this._formConfig.tabs)||void 0===t||t.forEach((t=>{t.label===i.detail.label&&(t.visible=!t.visible)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleCanStartDragTab(){var i,t;const o=this._layoutFormConfig.map((i=>i.tab));for(const t of o)null===(i=this._currentGroupBoxes[t])||void 0===i||i.map((i=>null==i?void 0:i.cancelEdition()));null===(t=this._newGroupBoxes)||void 0===t||t.map((i=>null==i?void 0:i.cancelEdition()))}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}componentDidRender(){this.controlSortableField(),this.controlSortableGroup()}async componentWillRender(){if(null==this.messagesBuilder){const i=r.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}componentWillLoad(){this.loadConfig()}componentDidLoad(){d.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}render(){var i,t,s,e;return o(n,null,o("div",{class:"ez-row ez-padding--medium"},o("div",{class:"ez-col ez-col--sd-7 ez-col--tb-9 ez-align--middle"},o("ez-button",{mode:"icon",title:this.getMessage("snkFormConfig.goBackTitle"),iconName:"arrow_back",class:"ez-padding--small",size:"small",onClick:()=>this.closeFormConfig(),id:"formConfigToBack"}),o("h1",{class:"ez-title ez-title--primary ez-title--extra-large ez-padding--small"},this.getMessage("snkFormConfig.title")),this._formConfigOptions&&o("ez-actions-button",{class:"form-config__actions-button ez-margin-left--medium",value:null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin,showLabel:!0,displayIcon:"chevron-down",checkOption:!0,size:"small",actions:this._formConfigOptions.map((i=>({value:i.origin,label:i.name}))),onEzAction:i=>this.controlSelectFormConfig(i),id:"selectConfig"})),o("div",{class:"ez-col ez-col--sd-5 ez-col--tb-3 ez-align--middle ez-align--right"},!0===this._formConfigChanged&&!1===this._optionFormConfigChanged&&o("div",{class:"ez-row ez-align--middle ez-align--right"},o("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeConfig()}),o("ez-button",{label:"Salvar",class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.saveConfig()},o("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"save"}))),!0===this._optionFormConfigChanged&&o("div",{class:"ez-row ez-align--middle ez-align--right"},o("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeOptionConfig()}),o("ez-button",{label:this.getMessage("snkFormConfig.applyConfig"),class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.applyOptionConfig()})))),o("div",{class:"ez-row ez-padding--medium",ref:i=>this._sortableContainer=i},o("div",{class:"form-config__tab-container ez-col ez-col--sd-9 ez-col--tb-9 ez-padding-right--medium"},(null===(t=this._layoutFormConfig)||void 0===t?void 0:t.length)>0&&o("section",{class:"ez-box__container",ref:i=>this._formContainer=i},o("snk-tab-config",{ref:i=>this._tabConfig=i,selectedIndex:this._tabSelected,messagesBuilder:this.messagesBuilder,onEzTabChange:i=>this.changeTabSelected(i.detail),onEzOrderChange:i=>this.changeTabOrder(i.detail),onEditionTitleTab:i=>this.changeTabLabel(i),onDeleteTab:i=>this.handleDeleteTab(i),onHideTab:i=>this.changeHideTab(i),onCanStartDrag:()=>this.handleCanStartDragTab(),tabItems:this._layoutFormConfig.map((i=>({tabKey:i.tab,label:i.tab,visible:i.visible})))}),this._layoutFormConfig.map(((i,t)=>o("div",{id:"tab"+t,"data-draggable-parent":"group",class:this._tabSelected===t?"form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium":"form-config__hide-content"},i.groups.map(((t,n)=>t.group?(null==this._currentGroupBoxes[i.tab]&&(this._currentGroupBoxes[i.tab]=[]),o("ez-collapsible-box",{ref:t=>this._currentGroupBoxes[i.tab][n]=t,editable:!0,removable:!0,"header-size":"large",label:t.group,"icon-placement":"left","data-group-name":t.group,"data-draggable-parent":"field","data-draggable-element":"group",onEzRemove:()=>this.removeGroup(),onEzSaveEditLabel:i=>this.saveEditLabelGroup(i),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,n)},this.getFieldsByGroup(t))):o("div",{class:"ez-flex ez-flex--column ez-size-width--full"},o("label",{class:"ez-text ez-text--secondary ez-margin-vertical--small"},this.getMessage("snkFormConfig.form.subTitleInfo")),o("div",{id:S,class:"ez-row","data-draggable-parent":"field"},this.getFieldsByGroup(t)),o("hr",{class:"ez-divider-horizontal ez-margin-vertical--medium"})))),this.renderTempGroupByTab(i.tab)))),o("div",{class:"form-config__btn-add-group ez-row"},o("div",{class:"form-config__btn-add-group-container ez-col ez-col--sd-12 ez-col--tb-12 ez-align--center"},o("ez-button",{label:this.getMessage("snkFormConfig.form.labelNewGroup"),class:"ez-padding-horizontal--small ez-button--primary",size:"small",onClick:()=>this.addNewGroup()},o("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"plus"})))))),o("div",{class:"form-config__fields-available ez-col ez-col--sd-3 ez-col--tb-3"},o("section",{class:"ez-box__container ez-col ez-col--pn-12"},o("h1",{class:"ez-title ez-title--large ez-title--primary ez-padding-bottom--medium"},this.getMessage("snkFormConfig.availableFields.title")),o("ez-filter-input",{id:"searchFields",ref:i=>this._filterFieldsAvailable=i,label:this.getMessage("snkFormConfig.availableFields.labelSearchField"),onEzChange:i=>this.onFilterChange(i.detail)}),o("span",{class:"ez-box__label-counter ez-text ez-text--medium ez-text--primary ez-margin-bottom--medium"},this.handleLabelCounter(null===(s=this._fieldsAvailable)||void 0===s?void 0:s.length)),(null===(e=this._layoutFormConfig)||void 0===e?void 0:e.length)>0&&o("div",{id:A,class:"ez-row","data-draggable-parent":"field"},this.orderFieldsAvailable(this._fieldsAvailable).map((i=>o("div",{key:i.name,class:this._fieldsAvailableStyle,"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},o("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},dataUnit:this.dataUnit,fieldConfig:i,id:i.name})))))))))}get _element(){return s(this)}static get watchers(){return{configManager:["observeConfigManager"]}}};I.style=".sc-snk-form-config-h{--snk-form-config--z-index:var(--more-visible, 2);--snk-form-config--background-color:var(--background--xlight, #fff);--snk-form-config__icon--color:var(--text--disable, #AFB6C0);--snk-form-config__label-counter--font-weight:var(--text-weight--extra-small, 200);--snk-form-config__add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__add-group-container--background-color:var(--background--medium, #d2dce9);--snk-form-config__add-group-container--padding:var(--space--small, 6px);--snk-form-config__add-group-content--border:2px dashed var(--color-strokes, #DCE0E8);--snk-form-config__add-group-content--border-radius:var(--border--radius-small, 6px);--snk-form-config__add-group-label--padding:var(--space--large, 24px);--snk-form-config__btn-add-group--padding:var(--space--large, 24px) var(--space--medium, 12px) 0;--snk-form-config__btn-add-group-container--padding:var(--space--medium, 12px);--snk-form-config__btn-add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__btn-add-group-container--border:2px solid var(--color-strokes, #DCE0E8);--snk-form-config__btn-add-group-container--background-color:var(--background--body, #fafcff);display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;z-index:var(--snk-form-config--z-index);background-color:var(--snk-form-config--background-color)}div.sc-snk-form-config:focus-visible,div.sc-snk-form-config:focus{outline:none}.form-config__header-container.sc-snk-form-config{display:flex}.form-config__field-container.sc-snk-form-config{width:32%;padding:6px}.form-config__hide-content.sc-snk-form-config{display:none}ez-icon.sc-snk-form-config .left-icon.sc-snk-form-config{--ez-icon--color:var(--snk-form-config__icon--color)}.ez-box__label-counter.sc-snk-form-config{margin-top:-7px;font-weight:var(--snk-form-config__label-counter--font-weight)}.form-config__btn-options.sc-snk-form-config{--ez-button--min-width:300px;--ez-button--background-color:var(--snk-form-config--background-color)}[data-draggable-parent].sc-snk-form-config{position:relative}.form-config__field-config--selected.sc-snk-form-config{position:static}.form-config__field-config--dragged.sc-snk-form-config .draggable-mirror.sc-snk-form-config{z-index:var(--snk-form-config--z-index)}.form-config__config-options.sc-snk-form-config{position:relative;margin-top:-3px;min-width:100%;z-index:1}.form-config__tab-container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config{position:relative;height:100%;max-height:calc(100vh - 92px)}.form-config__tab-container.sc-snk-form-config .ez-box__container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config .ez-box__container.sc-snk-form-config{align-content:flex-start;height:100%}.form-config__fields-available.sc-snk-form-config [data-draggable-parent].sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:100%;max-height:calc(100% - 122px)}.form-config__tab-content.sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:auto;max-height:calc(100% - 128px)}[data-draggable-element].sc-snk-form-config{cursor:grab}.form-config__actions-button.sc-snk-form-config{--ez-actions-button__btn-action--min-width:235px}.form-config__add-group.sc-snk-form-config{position:relative;min-height:120px;margin-bottom:10px}.form-config__add-group-container.sc-snk-form-config{position:absolute;display:flex;flex-wrap:wrap;width:100%;box-sizing:border-box;border-radius:var(--snk-form-config__add-group-container--border-radius);background-color:var(--snk-form-config__add-group-container--background-color);padding:var(--snk-form-config__add-group-container--padding)}.form-config__add-group-content.sc-snk-form-config{width:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;box-sizing:border-box;border:var(--snk-form-config__add-group-content--border);border-radius:var(--snk-form-config__add-group-content--border-radius)}.form-config__add-group-label.sc-snk-form-config{display:flex;justify-content:center;box-sizing:border-box;padding:var(--snk-form-config__add-group-label--padding)}.form-config__btn-add-group.sc-snk-form-config{position:relative;padding:var(--snk-form-config__btn-add-group--padding)}.form-config__btn-add-group-container.sc-snk-form-config{padding:var(--snk-form-config__btn-add-group-container--padding);border-radius:var(--snk-form-config__btn-add-group-container--border-radius);border:var(--snk-form-config__btn-add-group-container--border);background-color:var(--snk-form-config__btn-add-group-container--background-color)}ez-collapsible-box.draggable-mirror.sc-snk-form-config{display:table;background-color:var(--snk-form-config--background-color)}ez-collapsible-box.sc-snk-form-config{margin-bottom:10px}@media screen and (min-width: 480px){.form-config__field-config--selected.sc-snk-form-config .ez-flex.form-config__config-options.sc-snk-form-config{min-width:calc(300% + 12px)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+2) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -1)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+3) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -2)}}";export{E as snk_config_options,T as snk_form,I as snk_form_config}
1
+ import{r as i,c as t,h as o,H as n,g as s}from"./p-d2d301a6.js";import{UserInterface as e,ObjectUtils as l,StringUtils as a,ApplicationContext as r,ElementIDUtils as d,ArrayUtils as h}from"@sankhyalabs/core";import{DataType as c,getConvertedValue as f}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{CheckMode as u,ApplicationUtils as g,DialogType as m}from"@sankhyalabs/ezui/dist/collection/utils";import{c as v,D as b,d as p,C as z,a as _,b as k,A as C}from"./p-95ce311a.js";import{S as x}from"./p-0e206e62.js";import{R as y}from"./p-688dcb4c.js";import{S as F}from"./p-fa816fb2.js";import{U as w}from"./p-126c58ea.js";import{buildFormConfigFromDataUnit as D}from"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-9ffd9fc7.js";import"./p-ff1990ad.js";import"./p-00278e07.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const E=class{constructor(o){i(this,o),this.configOptionsChanged=t(this,"configOptionsChanged",7),this._defaultType=void 0,this.fieldConfig={},this.idConfig=void 0,this.dataUnit=void 0,this.messagesBuilder=void 0}onConfigDefault(i){null!=i&&(this._defaultType=i,this.fieldConfig.defaultValue={type:this._defaultType},this.configOptionsChanged.emit(this.fieldConfig))}buildOptions(){var i,t,o;let n=null===(o=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(t=this.fieldConfig)||void 0===t?void 0:t.name))||void 0===o?void 0:o.userInterface;return n===e.SEARCH&&(n=e.INTEGERNUMBER),v.UserInterface[n]}enabledValueDefault(){var i,t,o;const n=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(t=this.fieldConfig)||void 0===t?void 0:t.name),s=null===(o=null==n?void 0:n.properties)||void 0===o?void 0:o.allowDefault,l=v.UserInterface.hasOwnProperty(null==n?void 0:n.userInterface)||(null==n?void 0:n.userInterface)===e.SEARCH;return!(null!=s&&"true"!==s||!l)}isAllowDefault(){var i,t;const o=null===(t=null===(i=this._fieldProperties)||void 0===i?void 0:i.properties)||void 0===t?void 0:t.allowDefault;return null==o||"true"===o}loadDefaultValue(){var i;null==this.fieldConfig?(this._defaultType=b.fixed,this.fieldConfig={defaultValue:{type:this._defaultType}}):null==(null===(i=this.fieldConfig.defaultValue)||void 0===i?void 0:i.type)?(this._defaultType=b.fixed,this.fieldConfig.defaultValue={type:this._defaultType}):this._defaultType=this.fieldConfig.defaultValue.type}getFieldProperties(i){var t;if(null!=i)return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}getDefaultType(){var i;return null!==(i=this.fieldConfig.defaultValue.type)&&void 0!==i?i:b.fixed}getEnabledByProperty(i,t){const o=this._fieldProperties;if(null==o)return!0;const n=o.properties||{};return n.hasOwnProperty(t)?"S"!==n[t]:!0!==o[i]}getValueByProperty(i){const t=this._fieldProperties;return null!=t&&!0===t[i]||this.fieldConfig[i]}getValidatedValue(i){var t,o;if(null==i)return;const n=null===(t=this.dataUnit)||void 0===t?void 0:t.getField(null===(o=this.fieldConfig)||void 0===o?void 0:o.name),s=null==n?void 0:n.dataType;if(null==s)return;const e=null!=(null==i?void 0:i.waitmessage)?void 0:s!==c.OBJECT&&s!==c.DATE&&"object"==typeof i?i.value:i;return s===c.OBJECT?JSON.stringify(e):e}buildInputDefault({value:i,enabled:t,label:n,name:s,required:a,userInterface:r},d,h){let c,f=0,u=0;const g=null==r||null==p[r]?p.DEFAULT:p[r];if(r===e.OPTIONSELECTOR){const i=null==d?void 0:d.options;if("string"==typeof i){const t=l.stringToObject(i);c=Object.keys(t).map((i=>({value:i,label:t[i]})))}else c=i}else r===e.DECIMALNUMBER&&(f=Number((null==d?void 0:d.precision)||2),u=Number((null==d?void 0:d.prettyPrecision)||f));return o(g,Object.assign({value:i,enabled:t,label:n,"data-field-name":s,key:s,onEzChange:i=>this.onChange(null==i?void 0:i.detail)},this.getConditionalAttributes(r,a,c,f,u,h)))}getConditionalAttributes(i,t,o,n,s,l){switch(i){case e.SEARCH:return{suppressEmptyOption:t,optionLoader:i=>this.onSearch(i)};case e.OPTIONSELECTOR:return{suppressEmptyOption:t,options:o};case e.CHECKBOX:case e.SWITCH:return{mode:l};case e.INTEGERNUMBER:case e.DECIMALNUMBER:return{precision:n,prettyPrecision:s,onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};case e.DATE:case e.DATETIME:case e.TIME:return{onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};default:return{}}}onChange(i){this.fieldConfig.defaultValue.value=this.getValidatedValue(i),this.configOptionsChanged.emit(this.fieldConfig)}onSearch(i){if(null!=this._application&&null!=this.fieldConfig)return this._application.executeSearch(i,this.fieldConfig.name,this.dataUnit)}buildField(i,t){const{name:o,label:n,readOnly:s,required:l,defaultValue:r}=t,{userInterface:d,properties:h}=i;let c,g=a.getBooleanValue(null==h?void 0:h.allowDefault,!s);d===e.FILE&&(g=!1),g&&(c=null==r?void 0:r.value,null!=c&&(c=f(null==i?void 0:i.dataType,c)));const m={value:c,enabled:g,label:n,name:o,required:l,userInterface:d};switch(d){case e.SWITCH:return this.buildInputDefault(m,void 0,u.SWITCH);case e.CHECKBOX:return this.buildInputDefault(m,void 0,u.REGULAR);case e.OPTIONSELECTOR:case e.DECIMALNUMBER:return this.buildInputDefault(m,h);default:return this.buildInputDefault(m)}}componentWillLoad(){var i;this.loadDefaultValue(),this._application=r.getContextValue("__SNK__APPLICATION__"),this._fieldProperties=this.getFieldProperties(null===(i=this.fieldConfig)||void 0===i?void 0:i.name)}componentDidLoad(){d.addIDInfo(this._element,this.fieldConfig.name)}render(){var i,t;return o(n,null,o("div",{id:this.idConfig},o("div",{class:"ez-row ez-padding--medium"},o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-text-input",{label:this.getMessage("snkConfigOptions.label.nameField"),value:null===(i=this.fieldConfig)||void 0===i?void 0:i.label,onEzChange:i=>{this.fieldConfig.label=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.typeValueDefault"),suppressEmptyOption:!0,enabled:this.enabledValueDefault(),onEzChange:i=>{var t;return this.onConfigDefault(null===(t=i.detail)||void 0===t?void 0:t.value)},value:this.getDefaultType()},o("option",{value:b.fixed},this.getMessage("snkConfigOptions.options.valueFixed")),o("option",{value:b.variable},this.getMessage("snkConfigOptions.options.variable")))),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},this._defaultType===b.variable?o("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.valueDefault"),enabled:this.isAllowDefault(),onEzChange:i=>{var t;this.fieldConfig.defaultValue.value=null===(t=i.detail)||void 0===t?void 0:t.value,this.configOptionsChanged.emit(this.fieldConfig)},value:this.fieldConfig.defaultValue.value,options:this.buildOptions()}):(null===(t=this._fieldProperties)||void 0===t?void 0:t.userInterface)&&this.buildField(this._fieldProperties,this.fieldConfig))),o("div",{class:"ez-row ez-padding--medium config-options__switch-row"},o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.clearDuplicate"),value:this.fieldConfig.cleanOnCopy,onEzChange:i=>{this.fieldConfig.cleanOnCopy=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.requiredField"),enabled:this.getEnabledByProperty("required","systemRequired"),value:this.getValueByProperty("required"),onEzChange:i=>{this.fieldConfig.required=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),o("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},o("ez-check",{mode:u.SWITCH,label:this.getMessage("snkConfigOptions.label.protectedField"),enabled:this.getEnabledByProperty("readOnly","systemReadOnly"),value:this.getValueByProperty("readOnly"),onEzChange:i=>{this.fieldConfig.readOnly=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})))))}get _element(){return s(this)}};E.style=".sc-snk-config-options-h{--snk-config-options--border:2px solid var(--color--secondary-200, #D2D3DA);width:100%;border-radius:15px;border:var(--snk-config-options--border)}.config-options__switch-row.sc-snk-config-options{margin-top:-30px}";const T=class{constructor(o){i(this,o),this.exit=t(this,"exit",7),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this._customEditors=new Map,this._dataUnit=void 0,this._dataState=void 0,this._showFormConfig=!1,this._configManager=void 0,this.configName=void 0,this.recordsValidator=void 0,this.messagesBuilder=void 0,this.formLegacyConfigName=void 0,this.resourceID=void 0}async showConfig(){this._showFormConfig=!0}async hideConfig(){this._showFormConfig=!1}async addCustomEditor(i,t){if(this._form)return void this._form.addCustomEditor(i,t);const o=new Map(this._customEditors);o.set(i,t),this._customEditors=o}async setFieldProp(i,t,o){await this._form.setFieldProp(i,t,o)}closeConfig(){this.hideConfig()}dataunitReady(){d.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}setCustomEditors(){if(this._form)for(const[i,t]of this._customEditors)this._form.addCustomEditor(i,t),this._customEditors.delete(i)}async componentDidRender(){this.setCustomEditors()}async componentWillLoad(){let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.dataunitReady():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail})),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this));break}i=i.parentElement}null==this.resourceID&&(this.resourceID=await y.getResourceID()),this._configManager=new x(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const o=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of o||[]){if(!i)continue;const o=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(o||0===o)&&(await this.setFieldProp(i,"precision",o),await this.setFieldProp(i,"prettyPrecision",o))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return o("section",null,o("div",{class:"ez-row"},o("div",{class:"ez-col ez-col--sd-12"},o("ez-form",{ref:i=>this._form=i,key:"ezForm"+this._snkDataUnit.entityName,"data-element-id":"embedded",dataUnit:this._dataUnit,config:this._configManager.getConfig(this._dataUnit),recordsValidator:this.recordsValidator,class:this._showFormConfig?"snk-form__form--hidden":""}),this._showFormConfig&&o("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return s(this)}};T.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const O="EZ-COLLAPSIBLE-BOX",S="fieldsWithoutGroupContainer",A="fieldsAvailableContainer",L="addNewGroupContainer",I=class{constructor(o){i(this,o),this.configChange=t(this,"configChange",7),this.configClose=t(this,"configClose",7),this._listEnabledFields=[],this._renderTimer=500,this._tabSelected=1,this._labelNewGroup="Novo grupo",this._mouseOnFieldConfig=!1,this._mouseOnConfigOptions=!1,this._editingTitleGroup=!1,this._newGroupBoxes=[],this._currentGroupBoxes=[],this._formFieldsStyle="ez-col ez-col--sd-12 ez-col--tb-4 ez-padding-right--small ez-padding-bottom--medium sc-snk-form-config",this._fieldsAvailableStyle="ez-col ez-col--sd-12 ez-col--tb-12 ez-margin-bottom--medium ez-margin-right--medium sc-snk-form-config",this._fieldFloatingStyle="form-config__field-config--dragged",this._sortableTimer=100,this._formConfigOptions=[],this._fieldConfigSelected=void 0,this._layoutFormConfig=void 0,this._fieldsAvailable=void 0,this._formConfig={},this._formConfigChanged=!1,this._optionFormConfigSelected=void 0,this._optionFormConfigChanged=!1,this._tempGroups=[],this.dataUnit=void 0,this.configManager=void 0,this.messagesBuilder=void 0,this.ignoreReadOnlyFormFields=void 0}observeConfigManager(){this.loadConfig(this._sortableTimer)}loadFields(i=0){this._layoutFormConfig=[],i>0?setTimeout((()=>{this.buildFields()}),i):this.buildFields()}buildFields(){this.buildFormConfig(),this.buildAvailableFields()}loadFormConfig(i){var t;this._formConfig=this.getConfig(),this.loadFields(i),this.controlFieldConfig(),null!=(null===(t=this._filterFieldsAvailable)||void 0===t?void 0:t.value)&&(this._filterFieldsAvailable.value="")}getConfig(){let i=this.configManager.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=D(this.dataUnit)),l.copy(i)}cancelChangeConfig(){!0===this._formConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._formConfigChanged=!1,this.resetChangeConfig())})):this.resetChangeConfig()}cancelChangeOptionConfig(){!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._optionFormConfigChanged=!1,this.resetChangeOptionConfig())})):this.resetChangeOptionConfig()}resetChangeConfig(){this.loadFormConfig(this._sortableTimer),this.clearTempGroups()}resetChangeOptionConfig(){this._formConfigChanged=!1,this.loadConfig(this._sortableTimer),this.clearTempGroups()}getTabsToSave(){return this._layoutFormConfig.map(((i,t)=>({label:i.tab,order:t,visible:i.visible})))}getFieldsToSave(){const i=[];return this._formContainer.querySelectorAll("snk-field-config").forEach((t=>{const o=t.fieldConfig;if(null==o)return;const n={cleanOnCopy:o.cleanOnCopy||!1,group:o.group,label:o.label,name:o.name,required:o.required,readOnly:o.readOnly,tab:o.tab};null!=o.defaultValue&&(n.defaultValue=null==o.defaultValue.type?{type:b.fixed,value:o.defaultValue}:o.defaultValue),i.push(n)})),i}isDefaultConfiguration(){var i;return(null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin)===w.DEFAULT&&!0===this._optionFormConfigChanged&&!1===this._formConfigChanged}buildConfigToSave(){let i={};const t=this.isDefaultConfiguration();if(i=t?this.getConfig():l.copy(this._formConfig),!1===t){const t=this.getTabsToSave();(null==t?void 0:t.length)>0&&(i.tabs=t);const o=this.getFieldsToSave();(null==o?void 0:o.length)>0&&(i.fields=o)}return i.defaultConfiguration=t,i}saveConfig(){var i;(null===(i=this._tempGroups)||void 0===i?void 0:i.length)>0?g.alert(this.getMessage("snkFormConfig.confirm.title"),this.getMessage("snkFormConfig.confirm.group")):(this._formConfigChanged=!1,this._optionFormConfigChanged=!1,this.configManager.saveConfig(this.buildConfigToSave()).then((i=>{var t;g.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"});const o=null===(t=this._formConfigOptions)||void 0===t?void 0:t.find((i=>i.origin===w.USER));this.setFormConfig(o),this.configChange.emit(i)})))}applyOptionConfig(){if(!0===this._optionFormConfigChanged&&null!=this._optionFormConfigSelected){const i=this._optionFormConfigSelected.name||"configuração selecionada",t=this._optionFormConfigSelected.origin===w.DEFAULT?"pessoal":"padrão",o=this.getMessage("snkFormConfig.confirm.apply").replace("{0}",i).replace("{1}",t);this.openConfirmDialog(o).then((i=>{i&&this.saveConfig()}))}else this.saveConfig()}controlFieldConfig(i){var t;this._fieldConfigSelected=null!=i?(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===(null==i?void 0:i.name)?void 0:i:void 0}getFieldConfigStyle(i){var t;return this._formFieldsStyle+((null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name?" form-config__field-config--selected":"")}getFieldsByGroup(i){var t;return(null===(t=i.fields)||void 0===t?void 0:t.length)?i.fields.map((i=>{var t,n;return o("div",{key:i.name,class:this.getFieldConfigStyle(i),"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},o("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},modeInsertion:!1,fieldConfig:i,dataUnit:this.dataUnit,isConfigActive:(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name,id:i.name,key:i.name}),(null===(n=this._fieldConfigSelected)||void 0===n?void 0:n.name)===i.name&&o("div",{class:"ez-flex form-config__config-options"},o("snk-config-options",{idConfig:i.name,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,fieldConfig:this._fieldConfigSelected,"data-element-id":this._element.getAttribute(d.DATA_ELEMENT_ID_ATTRIBUTE_NAME),onConfigOptionsChanged:i=>this.handleconfigOptionsChanged(i.detail)})))})):o("div",{class:"form-config__add-group-container"},o("div",{class:"form-config__add-group-content"},o("div",{class:"form-config__add-group-label"},o("label",{class:"ez-text ez-text--center ez-text--medium ez-text--primary ez-text--bold"},this.getMessage("snkFormConfig.form.labelDropField")))))}handleconfigOptionsChanged(i){var t;null===(t=this._formConfig.fields)||void 0===t||t.forEach((()=>{})),this._formConfigChanged=!0}closeFormConfig(){!0===this._formConfigChanged||!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.exit")).then((i=>{i&&(this._formConfigChanged=!1,this.configClose.emit())})):this.configClose.emit()}openConfirmDialog(i="",t=this.getMessage("snkFormConfig.confirm.title")){return g.confirm(t,i)}controlMoveField(i){const t=null==i?void 0:i.target;null!=(null==t?void 0:t.closest('[data-draggable-element="field"]'))&&(this._mouseOnFieldConfig=!0,null!=(null==t?void 0:t.closest(".form-config__config-options"))||null!=(null==t?void 0:t.closest(".field-config__options"))?this._mouseOnConfigOptions=!0:!1===["minus","settings-inverted","chevron-up"].includes(null==t?void 0:t.iconName)&&this.controlFieldConfig())}controlStartDraggingField(i){var t,o,n;if(this._mouseOnConfigOptions)null==i||i.cancel(),this._mouseOnConfigOptions=!1;else{const s=null===(n=null===(o=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===o?void 0:o.data)||void 0===n?void 0:n.sourceContainer;null!=s&&s.classList.add(this._fieldFloatingStyle)}}controlSortedDraggingField(i){var t,o,n,s,e,l,a,r;const d=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.oldContainer,h=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.newContainer,c=null===(e=null===(s=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.source,f=null===(r=null===(a=null===(l=null==i?void 0:i.data)||void 0===l?void 0:l.dragEvent)||void 0===a?void 0:a.data)||void 0===r?void 0:r.originalSource;null!=d&&null!=h&&null!=c&&null!=f&&(h.tagName!==O&&h.id!==S||d.id!==A?d.tagName!==O&&d.id!==S||h.id!==A||(c.className=this._fieldsAvailableStyle,c.querySelector("snk-field-config").modeInsertion=!0,f.className=this._fieldsAvailableStyle,f.querySelector("snk-field-config").modeInsertion=!0):(c.className=this._formFieldsStyle,c.querySelector("snk-field-config").modeInsertion=!1,f.className=this._formFieldsStyle,f.querySelector("snk-field-config").modeInsertion=!1))}isCancelDragAvailableField(i,t,o){var n,s;return null!=i&&null!=t&&null!=o&&(null===(n=o.data)||void 0===n?void 0:n.newIndex)!==(null===(s=o.data)||void 0===s?void 0:s.oldIndex)&&i.id===A&&t.id===i.id&&(o.cancel(),this._fieldsAvailable=[],setTimeout((()=>{this.buildAvailableFields()}),this._sortableTimer),!0)}isRemoveField(i,t,o){if(null==i||null==t||null==o)return!1;if((t.tagName===O||t.id===S)&&i.id===A){const i={detail:{field:o,type:C.remove}};return setTimeout((()=>{this.handleFieldConfigChange(i)}),this._renderTimer),!0}return!1}isAddOrMoveField(i,t,o,n){var s;return null!=i&&null!=t&&null!=o&&null!=n&&(n.newIndex!==n.oldIndex||t.dataset.groupName!==i.dataset.groupName||i.id===S&&t.id===A)&&(this.isFieldAvailable(i,t)&&(o.tab=null===(s=this._tabConfig)||void 0===s?void 0:s.selectedTab),o.group=i.dataset.groupName,setTimeout((()=>{i.id.includes(L)&&this.clearTempGroups(!0),this.updateFieldsToSave(t.dataset.groupName!==i.dataset.groupName||i.id===S&&t.id===A?this._sortableTimer:0)}),this._renderTimer),!0)}isFieldAvailable(i,t){return null!=i&&null!=t&&(i.tagName===O||i.id===S)&&t.id===A}controlStopDraggingField(i){var t,o,n,s,e,l;const a=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.oldContainer,r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.newContainer;if(this.isCancelDragAvailableField(r,a,i))return;const d=null===(e=null===(s=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.originalSource,h=null===(l=null==d?void 0:d.querySelector("snk-field-config"))||void 0===l?void 0:l.fieldConfig;this.isRemoveField(r,a,h)||this.isAddOrMoveField(r,a,h,null==i?void 0:i.data)}updateFieldsToSave(i=0){const t=this.getFieldsToSave();(null==t?void 0:t.length)>0&&(this._formConfig.fields=t),this.loadFields(i),this._formConfigChanged=!0}controlSortableField(){null!=this._sortableContainer&&(this._sortableField&&this._sortableField.destroy(),this._sortableField=new F(this._sortableContainer.querySelectorAll('[data-draggable-parent="field"]'),{draggable:'[data-draggable-element="field"]',mirror:{constrainDimensions:!0},distance:z.dragStartDistance}),this._sortableField.on(_.dragStart,(i=>this.controlStartDraggingField(i))),this._sortableField.on(_.dragSorted,(i=>this.controlSortedDraggingField(i))),this._sortableField.on(_.dragStop,(i=>this.controlStopDraggingField(i))))}controlStartDraggingGroup(i){(this._mouseOnFieldConfig||this._editingTitleGroup)&&(null==i||i.cancel(),this._mouseOnFieldConfig=!1)}controlStopDraggingGroup(i){i.data.newIndex!==i.data.oldIndex&&setTimeout((()=>{this.updateFieldsToSave(this._sortableTimer)}),this._renderTimer)}controlSortableGroup(){null!=this._sortableContainer&&(this._sortableGroup&&this._sortableGroup.destroy(),this._sortableGroup=new F(this._sortableContainer.querySelectorAll('[data-draggable-parent="group"]'),{draggable:'[data-draggable-element="group"]',mirror:{constrainDimensions:!0},distance:z.dragStartDistance}),this._sortableGroup.on(_.dragStart,(i=>this.controlStartDraggingGroup(i))),this._sortableGroup.on(_.dragStop,(i=>this.controlStopDraggingGroup(i))))}loadUserConfig(){null!=this.configManager&&this.configManager.fetchUserAvailableConfigs().then((i=>{if(this._formConfigOptions=i,null==this._formConfigOptions)return;let t=null==this._formConfig||this._formConfig.defaultConfiguration;const o=i.find((i=>i.origin===(t?w.DEFAULT:w.USER)));this.setFormConfig(o)}))}setFormConfig(i){this._optionFormConfigSelected=i}controlSelectFormConfig(i){const t=null==i?void 0:i.detail,o=this._formConfigOptions.find((i=>i.origin===(null==t?void 0:t.value)));this.setFormConfig(o),this._optionFormConfigChanged=!0,this.loadConfigByUser()}changeTabOrder(i){const t=[],o=this._tabConfig.querySelectorAll(".tab-config__tab");this._tabSelected=i,o.forEach(((i,o)=>{var n;if(o){const s=null===(n=i.querySelector(".tab-config__tab-label"))||void 0===n?void 0:n.getAttribute("title");t.push({label:s,order:o-1})}})),this._layoutFormConfig.map((i=>{t.forEach((t=>{t.label===i.tab&&(t.visible=i.visible)}))})),t.length>0&&(this._formConfig.tabs=t,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}async loadConfigByUser(){if(null==this.configManager)return;if(null==this._optionFormConfigSelected)return;let i;this._optionFormConfigSelected.origin===w.DEFAULT?(i=await this.configManager.fetchDefaultConfig(),i||(i=this.configManager.getEmptyConfig())):i=this.getConfig(),null!=i&&(this._formConfig=i,this._tabSelected=1,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this.clearTempGroups())}loadConfig(i=0){this.loadFormConfig(i),this.loadUserConfig()}addNewGroup(){var i,t;const o=null===(i=this._tabConfig)||void 0===i?void 0:i.selectedTab;null==(null===(t=this._tempGroups)||void 0===t?void 0:t.find((i=>i.tab===o&&i.group.includes(this._labelNewGroup))))&&(this._tempGroups.push({tab:o,group:this.handleDuplicateGroups(this._labelNewGroup,this._tabConfig.selectedTab)}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0)}clearTempGroups(i=!1){var t;(null===(t=this._tempGroups)||void 0===t?void 0:t.length)>0&&(this._tempGroups=i?this._tempGroups.filter((i=>i.tab!==this._tabConfig.selectedTab)):[])}removeGroup(i){null!=i?this._tempGroups=this._tempGroups.filter(((t,o)=>o!==i&&t.tab===this._tabConfig.selectedTab||t.tab!==this._tabConfig.selectedTab)):this.updateFieldsToSave(this._sortableTimer)}checkGroupExists(i,t,o=!1){var n,s,e;const l=null===(n=this._tabConfig)||void 0===n?void 0:n.selectedTab,a=null===(s=this._layoutFormConfig)||void 0===s?void 0:s.find((i=>i.tab===l)),r=null===(e=null==a?void 0:a.groups)||void 0===e?void 0:e.map((i=>{var t;return null===(t=i.group)||void 0===t?void 0:t.toLowerCase()}));if(null==r?void 0:r.includes(null==i?void 0:i.toLowerCase())){const n=this.getMessage("snkFormConfig.confirm.title"),s=`\n ${this.getMessage("snkFormConfig.alert.titleGroupExists")}\n <b>${i}</b>\n ${this.getMessage("snkFormConfig.alert.inTab")}\n <b>${l===k.main?this.getMessage("snkFormConfig.form.mainArea"):l}</b>.\n <br/><br/>\n ${this.getMessage("snkFormConfig.alert.infoValidTitle")}\n `;return g.alert(n,s).then((()=>{var i,n;o?null===(i=this._newGroupBoxes[t])||void 0===i||i.applyFocusTextEdit():null===(n=this._currentGroupBoxes[l][t])||void 0===n||n.applyFocusTextEdit()})),!1}return!0}saveEditLabelTempGroup(i,t){const{newValue:o}=i.detail;null!=this._newGroupBoxes&&null!=this._newGroupBoxes[t]&&(this._newGroupBoxes[t].dataset.groupName=o)}saveEditLabelGroup(i){var t;const{value:o,newValue:n}=i.detail;null===(t=this._formConfig.fields)||void 0===t||t.forEach((i=>{i.group===o&&(i.group=n)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}renderTempGroupByTab(i){return this._tempGroups.map(((t,n)=>{if(t.tab===i)return o("ez-collapsible-box",{ref:i=>this._newGroupBoxes[n]=i,id:`${L}-${n}`,editable:!0,removable:!0,"header-size":"large",label:t.group,"icon-placement":"left","data-group-name":t.group,"data-draggable-parent":"field",class:"form-config__add-group",onEzRemove:()=>this.removeGroup(n),onEzSaveEditLabel:i=>this.saveEditLabelTempGroup(i,n),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,n,!0)},this.getFieldsByGroup(t))}))}handleDuplicateGroups(i,t){var o;const n=this._layoutFormConfig[this._tabConfig.selectedIndex].groups.map((i=>i.group));return null!=n&&(null===(o=this._layoutFormConfig)||void 0===o||o.map((o=>{o.tab===t&&o.groups.some((t=>t.group===i))&&(i+=`${this.captureHighestValueTitle(n)}`)}))),i}captureHighestValueTitle(i){let t=[];return null==i||i.map((i=>{null!=i&&t.push(i.replace(/[^0-9]/g,""))})),Math.max.apply(null,t)>0?` (${Math.max.apply(null,t)+1})`:" (1)"}getLayoutFormConfig(){var i,t;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=[],n=[];for(const i of this._formConfig.fields)if(null==n.find((t=>i.name===t.name&&i.tab===t.tab))){n.push(i);const s=this.dataUnit.getField(i.name);if(null==s?void 0:s.visible){null!=i.label&&""!==i.label||(i.label=s.label),null!=i.tab&&""!==i.tab||(i.tab=this.getMessage("snkFormConfig.form.tabGeneral"));let n=o.find((t=>t.tab===i.tab));if(null==n){let s=null;if(null!=this._formConfig.tabs){const t=this._formConfig.tabs.filter((t=>t.label===i.tab));t.length>0&&(s=t[0].visible)}const e=(null===(t=i.tab)||void 0===t?void 0:t.label)||i.tab;n=null!==s?{tab:e,groups:[],visible:s}:{tab:e,groups:[],visible:!0},o.push(n)}const e=n.groups.find((t=>t.group===i.group));if(e)e.fields.push(i);else{const t={group:i.group,fields:[i]};void 0===i.group?n.groups.unshift(t):n.groups.push(t)}}}return o}configureTabs(i){var t;return null==(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?i:(null==i&&(i=[]),this._formConfig.defaultConfiguration?i:this._formConfig.tabs.map((t=>i.find((i=>{var o,n;return(null===(o=t.label)||void 0===o?void 0:o.toLowerCase())===(null===(n=i.tab)||void 0===n?void 0:n.toLowerCase())}))||{tab:t.label,groups:[],visible:t.visible})))}configureTabMain(i){return null==i&&(i=[]),null==i.find((i=>i.tab===k.main))&&i.unshift({tab:k.main,groups:[],visible:!0}),i}updateTabs(){const i=this.getTabsToSave();(null==i?void 0:i.length)>0&&(this._formConfig.tabs=i,1===i.length&&(this._tabSelected=0))}buildFormConfig(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let t=this.getLayoutFormConfig();t=this.configureTabs(t),t=this.configureTabMain(t),this._layoutFormConfig=t,this.updateTabs()}buildAvailableFields(){var i,t;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=[],n=this.dataUnit.metadata.fields;for(const i of this._formConfig.fields)o.push(i);const s=n.filter((({name:i,visible:t})=>!0===t&&!1===o.some((({name:t})=>t===i))));this._fieldsAvailable=s,this._listEnabledFields=s,null!=(null===(t=this._filterFieldsAvailable)||void 0===t?void 0:t.value)&&this.onFilterChange(this._filterFieldsAvailable.value)}changeTabSelected(i){this._tabSelected=i.index;const t=this._formContainer.querySelector("div#tab"+i.index);this._formContainer.querySelectorAll(".form-config__tab-content").forEach((i=>i.className="form-config__hide-content sc-snk-form-config")),t&&(t.className="form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium sc-snk-form-config")}onFilterChange(i){this._fieldsAvailable=h.applyStringFilter(i,this._listEnabledFields,!0,"label")}orderFieldsAvailable(i){return h.sortAlphabetically(i)}handleLabelCounter(i){const t=[this.getMessage("snkFormConfig.availableFields.labelNoFields"),this.getMessage("snkFormConfig.availableFields.labelOneField")];return i>1?`${i} ${this.getMessage("snkFormConfig.availableFields.labelAvailableFields")}`:t[i]}controlAddFieldConfig(i){var t;if(this._formConfigChanged=!1,null==i)return;null==this._formConfig.fields&&(this._formConfig.fields=[]);const o=this._formConfig.fields.filter((t=>t.name===i.name&&t.tab&&i.tab));o.length>0?o.forEach((t=>{t.name=i.name,t.label=i.label,t.required=i.required,t.readOnly=i.readOnly,t.group=i.group})):this._formConfig.fields.push({name:i.name,label:i.label,required:i.required,readOnly:i.readOnly,group:i.group,tab:null===(t=this._tabConfig)||void 0===t?void 0:t.selectedTab}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables()}controlRemoveFieldConfig(i,t){var o;this._formConfigChanged=!1,null!=i&&(this._formConfig.fields=null===(o=this._formConfig.fields)||void 0===o?void 0:o.filter((t=>t.name!==i.name)),this.loadFields(t),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables())}resetSortables(){this.controlSortableField(),this.controlSortableGroup()}handleFieldConfigChange(i,t=0){const{field:o,type:n}=i.detail;n!==C.configuration?n!==C.remove?n!==C.add||this.controlAddFieldConfig(o):this.controlRemoveFieldConfig(o,t):this.controlFieldConfig(o)}changeTabLabel(i){var t,o;const{value:n,newValue:s}=i.detail.detail;null===(t=this._formConfig.fields)||void 0===t||t.forEach((i=>{i.tab===n&&(i.tab=s)})),null===(o=this._formConfig.tabs)||void 0===o||o.forEach((i=>{i.label===n&&(i.label=s)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleDeleteTab(i){let t={canClose:!1,labelCancel:this.getMessage("snkFormConfig.confirm.labelCancel"),labelConfirm:this.getMessage("snkFormConfig.confirm.labelDelete"),btnConfirmDanger:!1};const o=this.getMessage("snkFormConfig.confirm.title"),n=this.getMessage("snkFormConfig.confirm.deleteTab")+` <b>${i.detail.label}</b>?`;g.confirm(o,n,null,m.WARN,t).then((t=>{var o;t&&(this._formConfig.tabs=null===(o=this._formConfig.tabs)||void 0===o?void 0:o.filter((t=>t.label!==i.detail.label)),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}))}changeHideTab(i){var t;null===(t=this._formConfig.tabs)||void 0===t||t.forEach((t=>{t.label===i.detail.label&&(t.visible=!t.visible)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleCanStartDragTab(){var i,t;const o=this._layoutFormConfig.map((i=>i.tab));for(const t of o)null===(i=this._currentGroupBoxes[t])||void 0===i||i.map((i=>null==i?void 0:i.cancelEdition()));null===(t=this._newGroupBoxes)||void 0===t||t.map((i=>null==i?void 0:i.cancelEdition()))}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}componentDidRender(){this.controlSortableField(),this.controlSortableGroup()}async componentWillRender(){if(null==this.messagesBuilder){const i=r.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}componentWillLoad(){this.loadConfig()}componentDidLoad(){d.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}render(){var i,t,s,e;return o(n,null,o("div",{class:"ez-row ez-padding--medium"},o("div",{class:"ez-col ez-col--sd-7 ez-col--tb-9 ez-align--middle"},o("ez-button",{mode:"icon",title:this.getMessage("snkFormConfig.goBackTitle"),iconName:"arrow_back",class:"ez-padding--small",size:"small",onClick:()=>this.closeFormConfig(),id:"formConfigToBack"}),o("h1",{class:"ez-title ez-title--primary ez-title--extra-large ez-padding--small"},this.getMessage("snkFormConfig.title")),this._formConfigOptions&&o("ez-actions-button",{class:"form-config__actions-button ez-margin-left--medium",value:null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin,showLabel:!0,displayIcon:"chevron-down",checkOption:!0,size:"small",actions:this._formConfigOptions.map((i=>({value:i.origin,label:i.name}))),onEzAction:i=>this.controlSelectFormConfig(i),id:"selectConfig"})),o("div",{class:"ez-col ez-col--sd-5 ez-col--tb-3 ez-align--middle ez-align--right"},!0===this._formConfigChanged&&!1===this._optionFormConfigChanged&&o("div",{class:"ez-row ez-align--middle ez-align--right"},o("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeConfig()}),o("ez-button",{label:"Salvar",class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.saveConfig()},o("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"save"}))),!0===this._optionFormConfigChanged&&o("div",{class:"ez-row ez-align--middle ez-align--right"},o("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeOptionConfig()}),o("ez-button",{label:this.getMessage("snkFormConfig.applyConfig"),class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.applyOptionConfig()})))),o("div",{class:"ez-row ez-padding--medium",ref:i=>this._sortableContainer=i},o("div",{class:"form-config__tab-container ez-col ez-col--sd-9 ez-col--tb-9 ez-padding-right--medium"},(null===(t=this._layoutFormConfig)||void 0===t?void 0:t.length)>0&&o("section",{class:"ez-box__container",ref:i=>this._formContainer=i},o("snk-tab-config",{ref:i=>this._tabConfig=i,selectedIndex:this._tabSelected,messagesBuilder:this.messagesBuilder,onEzTabChange:i=>this.changeTabSelected(i.detail),onEzOrderChange:i=>this.changeTabOrder(i.detail),onEditionTitleTab:i=>this.changeTabLabel(i),onDeleteTab:i=>this.handleDeleteTab(i),onHideTab:i=>this.changeHideTab(i),onCanStartDrag:()=>this.handleCanStartDragTab(),tabItems:this._layoutFormConfig.map((i=>({tabKey:i.tab,label:i.tab,visible:i.visible})))}),this._layoutFormConfig.map(((i,t)=>o("div",{id:"tab"+t,"data-draggable-parent":"group",class:this._tabSelected===t?"form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium":"form-config__hide-content"},i.groups.map(((t,n)=>t.group?(null==this._currentGroupBoxes[i.tab]&&(this._currentGroupBoxes[i.tab]=[]),o("ez-collapsible-box",{ref:t=>this._currentGroupBoxes[i.tab][n]=t,editable:!0,removable:!0,"header-size":"large",label:t.group,"icon-placement":"left","data-group-name":t.group,"data-draggable-parent":"field","data-draggable-element":"group",onEzRemove:()=>this.removeGroup(),onEzSaveEditLabel:i=>this.saveEditLabelGroup(i),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,n)},this.getFieldsByGroup(t))):o("div",{class:"ez-flex ez-flex--column ez-size-width--full"},o("label",{class:"ez-text ez-text--secondary ez-margin-vertical--small"},this.getMessage("snkFormConfig.form.subTitleInfo")),o("div",{id:S,class:"ez-row","data-draggable-parent":"field"},this.getFieldsByGroup(t)),o("hr",{class:"ez-divider-horizontal ez-margin-vertical--medium"})))),this.renderTempGroupByTab(i.tab)))),o("div",{class:"form-config__btn-add-group ez-row"},o("div",{class:"form-config__btn-add-group-container ez-col ez-col--sd-12 ez-col--tb-12 ez-align--center"},o("ez-button",{label:this.getMessage("snkFormConfig.form.labelNewGroup"),class:"ez-padding-horizontal--small ez-button--primary",size:"small",onClick:()=>this.addNewGroup()},o("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"plus"})))))),o("div",{class:"form-config__fields-available ez-col ez-col--sd-3 ez-col--tb-3"},o("section",{class:"ez-box__container ez-col ez-col--pn-12"},o("h1",{class:"ez-title ez-title--large ez-title--primary ez-padding-bottom--medium"},this.getMessage("snkFormConfig.availableFields.title")),o("ez-filter-input",{id:"searchFields",ref:i=>this._filterFieldsAvailable=i,label:this.getMessage("snkFormConfig.availableFields.labelSearchField"),onEzChange:i=>this.onFilterChange(i.detail)}),o("span",{class:"ez-box__label-counter ez-text ez-text--medium ez-text--primary ez-margin-bottom--medium"},this.handleLabelCounter(null===(s=this._fieldsAvailable)||void 0===s?void 0:s.length)),(null===(e=this._layoutFormConfig)||void 0===e?void 0:e.length)>0&&o("div",{id:A,class:"ez-row","data-draggable-parent":"field"},this.orderFieldsAvailable(this._fieldsAvailable).map((i=>o("div",{key:i.name,class:this._fieldsAvailableStyle,"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},o("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},dataUnit:this.dataUnit,fieldConfig:i,id:i.name})))))))))}get _element(){return s(this)}static get watchers(){return{configManager:["observeConfigManager"]}}};I.style=".sc-snk-form-config-h{--snk-form-config--z-index:var(--more-visible, 2);--snk-form-config--background-color:var(--background--xlight, #fff);--snk-form-config__icon--color:var(--text--disable, #AFB6C0);--snk-form-config__label-counter--font-weight:var(--text-weight--extra-small, 200);--snk-form-config__add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__add-group-container--background-color:var(--background--medium, #d2dce9);--snk-form-config__add-group-container--padding:var(--space--small, 6px);--snk-form-config__add-group-content--border:2px dashed var(--color-strokes, #DCE0E8);--snk-form-config__add-group-content--border-radius:var(--border--radius-small, 6px);--snk-form-config__add-group-label--padding:var(--space--large, 24px);--snk-form-config__btn-add-group--padding:var(--space--large, 24px) var(--space--medium, 12px) 0;--snk-form-config__btn-add-group-container--padding:var(--space--medium, 12px);--snk-form-config__btn-add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__btn-add-group-container--border:2px solid var(--color-strokes, #DCE0E8);--snk-form-config__btn-add-group-container--background-color:var(--background--body, #fafcff);display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;z-index:var(--snk-form-config--z-index);background-color:var(--snk-form-config--background-color)}div.sc-snk-form-config:focus-visible,div.sc-snk-form-config:focus{outline:none}.form-config__header-container.sc-snk-form-config{display:flex}.form-config__field-container.sc-snk-form-config{width:32%;padding:6px}.form-config__hide-content.sc-snk-form-config{display:none}ez-icon.sc-snk-form-config .left-icon.sc-snk-form-config{--ez-icon--color:var(--snk-form-config__icon--color)}.ez-box__label-counter.sc-snk-form-config{margin-top:-7px;font-weight:var(--snk-form-config__label-counter--font-weight)}.form-config__btn-options.sc-snk-form-config{--ez-button--min-width:300px;--ez-button--background-color:var(--snk-form-config--background-color)}[data-draggable-parent].sc-snk-form-config{position:relative}.form-config__field-config--selected.sc-snk-form-config{position:static}.form-config__field-config--dragged.sc-snk-form-config .draggable-mirror.sc-snk-form-config{z-index:var(--snk-form-config--z-index)}.form-config__config-options.sc-snk-form-config{position:relative;margin-top:-3px;min-width:100%;z-index:1}.form-config__tab-container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config{position:relative;height:100%;max-height:calc(100vh - 92px)}.form-config__tab-container.sc-snk-form-config .ez-box__container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config .ez-box__container.sc-snk-form-config{align-content:flex-start;height:100%}.form-config__fields-available.sc-snk-form-config [data-draggable-parent].sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:100%;max-height:calc(100% - 122px)}.form-config__tab-content.sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:auto;max-height:calc(100% - 128px)}[data-draggable-element].sc-snk-form-config{cursor:grab}.form-config__actions-button.sc-snk-form-config{--ez-actions-button__btn-action--min-width:235px}.form-config__add-group.sc-snk-form-config{position:relative;min-height:120px;margin-bottom:10px}.form-config__add-group-container.sc-snk-form-config{position:absolute;display:flex;flex-wrap:wrap;width:100%;box-sizing:border-box;border-radius:var(--snk-form-config__add-group-container--border-radius);background-color:var(--snk-form-config__add-group-container--background-color);padding:var(--snk-form-config__add-group-container--padding)}.form-config__add-group-content.sc-snk-form-config{width:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;box-sizing:border-box;border:var(--snk-form-config__add-group-content--border);border-radius:var(--snk-form-config__add-group-content--border-radius)}.form-config__add-group-label.sc-snk-form-config{display:flex;justify-content:center;box-sizing:border-box;padding:var(--snk-form-config__add-group-label--padding)}.form-config__btn-add-group.sc-snk-form-config{position:relative;padding:var(--snk-form-config__btn-add-group--padding)}.form-config__btn-add-group-container.sc-snk-form-config{padding:var(--snk-form-config__btn-add-group-container--padding);border-radius:var(--snk-form-config__btn-add-group-container--border-radius);border:var(--snk-form-config__btn-add-group-container--border);background-color:var(--snk-form-config__btn-add-group-container--background-color)}ez-collapsible-box.draggable-mirror.sc-snk-form-config{display:table;background-color:var(--snk-form-config--background-color)}ez-collapsible-box.sc-snk-form-config{margin-bottom:10px}@media screen and (min-width: 480px){.form-config__field-config--selected.sc-snk-form-config .ez-flex.form-config__config-options.sc-snk-form-config{min-width:calc(300% + 12px)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+2) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -1)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+3) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -2)}}";export{E as snk_config_options,T as snk_form,I as snk_form_config}
@@ -1,6 +1,6 @@
1
- import{DataType as e,ApplicationContext as t}from"@sankhyalabs/core";import{d as i,D as n}from"./p-f3434fc4.js";class r{constructor(){this._defaultPageSize=100,this._templateByQuery=new Map,this._searchListenersByDataUnit=new Map,this.buldTemplates()}buldTemplates(){this._templateByQuery.set("search",i.gql`query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
1
+ import{DataType as e,ApplicationContext as t}from"@sankhyalabs/core";import{d as i,D as n}from"./p-00278e07.js";class r{constructor(){this._defaultPageSize=100,this._templateByQuery=new Map,this._searchListenersByDataUnit=new Map,this.buldTemplates()}buldTemplates(){this._templateByQuery.set("search",i.gql`query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
2
2
  $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria options: $options){
3
3
  value
4
4
  label
5
5
  }
6
- }`)}loadSearchOptions(t,i,r,s){var a;const l=(null==i?void 0:i.toString().trim())||void 0;i=isNaN(Number(l))&&l?`%${l}`:l,null==r||r.params.forEach((t=>{t.dataType===e.OBJECT&&(t.value=JSON.stringify(t.value))}));const u=this.applySearchListener(o.beforeSearch,t,i,r,s),c={argument:(null==u?void 0:u.argument)||i,entityName:t,criteria:(null==u?void 0:u.criteria)||r,options:(null==u?void 0:u.searchOptions)||s};return c.options&&(null===(a=c.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{n.get().callGraphQL({values:c,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}loadAdvancedSearch(i,r,s,a){var l,u,c,d,v;const h=this.applySearchListener(o.beforeSearch,i,r,s,a),m={argument:(null==h?void 0:h.argument)||r,criteria:(null==h?void 0:h.criteria)||s,searchOptions:Object.assign(Object.assign({},a),null==h?void 0:h.searchOptions)},p={query:{$:null===(l=m.criteria)||void 0===l?void 0:l.expression}};(null===(c=null===(u=m.criteria)||void 0===u?void 0:u.params)||void 0===c?void 0:c.length)>0&&(p.params={param:m.criteria.params.map((i=>{let n=i.value;if("string"==typeof n){const e=/CTX\{([^}]+)\}/.exec(n);e&&(n=t.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${e[1]})__`))}let r=i.dataType;return r===e.OBJECT?(n=n.value,r="S"):r=function(t){switch(t){case e.NUMBER:return"I";case e.DATE:return"D";default:return"S"}}(i.dataType),{$:n,type:r}}))});const y=null!=a?Object.assign(Object.assign({},null==m?void 0:m.searchOptions),{pkFieldName:a.codeFieldName,label:a.descriptionFieldName,fieldName:a.codeFieldName,useDescriptionOptions:!1,enableRowsCounter:!0}):void 0,f={serviceName:"PesquisaSP.getSuggestion",requestBody:{criteria:Object.assign({entityName:i,compacted:!1,ignoreEntityCriteria:null!==(d=null==y?void 0:y.ignoreEntityCriteria)&&void 0!==d&&d,limit:this._defaultPageSize,query:{$:m.argument},orderByDesc:!1,externalCriteria:p,localEntityName:null===(v=m.searchOptions)||void 0===v?void 0:v.rootEntity},{options:y}),clientEventList:{clientEvent:[]}}},S={urlParams:{quietMode:!0}};return new Promise(((e,t)=>{n.get().callServiceBroker("PesquisaSP.getSuggestion",JSON.stringify(f),S).then((t=>e(t))).catch((e=>t(e)))}))}addSearchListener(e,t,i){var n;const r=this._searchListenersByDataUnit.get(t)||[],o=r.find((t=>t.entity===e));if(o){for(const e of Object.keys(i))if(e in o.listener){if((null===(n=o.listener[e])||void 0===n?void 0:n.toString())===i[e].toString())continue;o.listener[e]=i[e]}}else this._searchListenersByDataUnit.set(t,[...r,{entity:e,listener:i}]);return()=>{const i=r.filter((t=>t.entity!==e));i.length?this._searchListenersByDataUnit.set(t,i):this._searchListenersByDataUnit.delete(t)}}applySearchListener(e,t,i,n,r){var o;const s=null==r?void 0:r.dataUnitId;if(!s)return;const a=null===(o=this._searchListenersByDataUnit.get(s))||void 0===o?void 0:o.find((({entity:e})=>e===t));if(!a)return;const{listener:l}=a;return e in l?l[e]({argument:i,criteria:n,searchOptions:r}):void 0}}var o;!function(e){e.beforeSearch="beforeSearch"}(o||(o={}));export{r as P}
6
+ }`)}loadSearchOptions(t,i,r,s){var a;const l=(null==i?void 0:i.toString().trim())||void 0;i=isNaN(Number(l))&&l?`%${l}`:l,null==r||r.params.forEach((t=>{t.dataType===e.OBJECT&&(t.value=JSON.stringify(t.value))}));const u=this.applySearchListener(o.beforeSearch,t,i,r,s),c={argument:(null==u?void 0:u.argument)||i,entityName:t,criteria:(null==u?void 0:u.criteria)||r,options:(null==u?void 0:u.searchOptions)||s};return c.options&&(null===(a=c.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{n.get().callGraphQL({values:c,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}loadAdvancedSearch(i,r,s,a){var l,u,c,d,v;const h=this.applySearchListener(o.beforeSearch,i,r,s,a),m={argument:(null==h?void 0:h.argument)||r,criteria:(null==h?void 0:h.criteria)||s,searchOptions:Object.assign(Object.assign({},a),null==h?void 0:h.searchOptions)},p={query:{$:null===(l=m.criteria)||void 0===l?void 0:l.expression}};(null===(c=null===(u=m.criteria)||void 0===u?void 0:u.params)||void 0===c?void 0:c.length)>0&&(p.params={param:m.criteria.params.map((i=>{let n=i.value;if("string"==typeof n){const e=/CTX\{([^}]+)\}/.exec(n);e&&(n=t.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${e[1]})__`))}let r=i.dataType;return r===e.OBJECT?(n=n.value,r="S"):r=function(t){switch(t){case e.NUMBER:return"I";case e.DATE:return"D";default:return"S"}}(i.dataType),{$:n,type:r}}))});const y=null!=a?Object.assign(Object.assign({},null==m?void 0:m.searchOptions),{pkFieldName:a.codeFieldName,label:a.descriptionFieldName,fieldName:a.codeFieldName,useDescriptionOptions:!1,enableRowsCounter:!0}):void 0,S={serviceName:"PesquisaSP.getSuggestion",requestBody:{criteria:Object.assign({entityName:i,compacted:!1,ignoreEntityCriteria:null!==(d=null==y?void 0:y.ignoreEntityCriteria)&&void 0!==d&&d,limit:this._defaultPageSize,query:{$:m.argument},orderByDesc:!1,externalCriteria:p,localEntityName:null===(v=m.searchOptions)||void 0===v?void 0:v.rootEntity},{options:y}),clientEventList:{clientEvent:[]}}},N={urlParams:{quietMode:!0}};return new Promise(((e,t)=>{n.get().callServiceBroker("PesquisaSP.getSuggestion",JSON.stringify(S),N).then((t=>e(t))).catch((e=>t(e)))}))}addSearchListener(e,t,i){var n;const r=this._searchListenersByDataUnit.get(t)||[],o=r.find((t=>t.entity===e));if(o){for(const e of Object.keys(i))if(e in o.listener){if((null===(n=o.listener[e])||void 0===n?void 0:n.toString())===i[e].toString())continue;o.listener[e]=i[e]}}else this._searchListenersByDataUnit.set(t,[...r,{entity:e,listener:i}]);return()=>{const i=r.filter((t=>t.entity!==e));i.length?this._searchListenersByDataUnit.set(t,i):this._searchListenersByDataUnit.delete(t)}}applySearchListener(e,t,i,n,r){var o;const s=null==r?void 0:r.dataUnitId;if(!s)return;const a=null===(o=this._searchListenersByDataUnit.get(s))||void 0===o?void 0:o.find((({entity:e})=>e===t));if(!a)return;const{listener:l}=a;return e in l?l[e]({argument:i,criteria:n,searchOptions:r}):void 0}}var o;!function(e){e.beforeSearch="beforeSearch"}(o||(o={}));export{r as P}
@@ -1 +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
+ 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-9ffd9fc7.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-126c58ea.js";import"./p-00278e07.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}
@@ -0,0 +1 @@
1
+ export{S as snk_guides_viewer}from"./p-e3a285a2.js";import"./p-d2d301a6.js";import"@sankhyalabs/core";import"./p-0e206e62.js";import"./p-9ffd9fc7.js";import"./p-126c58ea.js";import"./p-00278e07.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"./p-95ce311a.js";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-23736d75.js";import"./p-7e7a7473.js";import"./p-30cf616e.js";import"./p-6dc031de.js";import"./p-341465ce.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-47d24ac8.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"@sankhyalabs/core/dist/dataunit/DataUnit";