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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) 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-0419911a.js} +5 -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/lib/http/data-fetcher/DataFetcher.js +8 -6
  30. package/dist/components/DataFetcher.js +7 -5
  31. package/dist/components/snk-application2.js +95 -53
  32. package/dist/esm/{ConfigStorage-7b36d041.js → ConfigStorage-6514d66e.js} +2 -2
  33. package/dist/esm/{ContinuousInsertUtils-881c41a9.js → ContinuousInsertUtils-b62906f9.js} +4 -4
  34. package/dist/esm/{DataFetcher-a9c598f2.js → DataFetcher-5034df59.js} +7 -5
  35. package/dist/esm/{SnkFormConfigManager-f1a0fc92.js → SnkFormConfigManager-b409c745.js} +2 -2
  36. package/dist/esm/{auth-fetcher-749d880f.js → auth-fetcher-ca5d3a49.js} +1 -1
  37. package/dist/esm/{dataunit-fetcher-fd58c640.js → dataunit-fetcher-56cb648b.js} +1 -1
  38. package/dist/esm/{form-config-fetcher-adbe5d34.js → form-config-fetcher-a7d3e277.js} +1 -1
  39. package/dist/esm/{pesquisa-fetcher-50fc7e6b.js → pesquisa-fetcher-6bc2e41a.js} +1 -1
  40. package/dist/esm/snk-actions-button_4.entry.js +5 -5
  41. package/dist/esm/snk-application.entry.js +101 -59
  42. package/dist/esm/snk-attach.entry.js +5 -5
  43. package/dist/esm/snk-config-options_3.entry.js +4 -4
  44. package/dist/esm/snk-crud.entry.js +5 -5
  45. package/dist/esm/snk-data-exporter.entry.js +5 -5
  46. package/dist/esm/{snk-data-unit-590225b5.js → snk-data-unit-618e0b80.js} +1 -1
  47. package/dist/esm/snk-data-unit.entry.js +3 -3
  48. package/dist/esm/snk-detail-view.entry.js +7 -7
  49. package/dist/esm/snk-filter-bar_4.entry.js +3 -3
  50. package/dist/esm/snk-filter-modal-item.entry.js +3 -3
  51. package/dist/esm/snk-grid.entry.js +6 -6
  52. package/dist/esm/{snk-guides-viewer-2f4dcdc5.js → snk-guides-viewer-18453d98.js} +5 -5
  53. package/dist/esm/snk-guides-viewer.entry.js +7 -7
  54. package/dist/esm/snk-personalized-filter.entry.js +3 -3
  55. package/dist/esm/snk-simple-crud.entry.js +7 -7
  56. package/dist/sankhyablocks/{p-f3434fc4.js → p-00278e07.js} +1 -1
  57. package/dist/sankhyablocks/{p-fadc8339.js → p-0e206e62.js} +1 -1
  58. package/dist/sankhyablocks/{p-242d010e.entry.js → p-0e250436.entry.js} +1 -1
  59. package/dist/sankhyablocks/{p-06421fdb.js → p-126c58ea.js} +1 -1
  60. package/dist/sankhyablocks/{p-6114ee36.entry.js → p-1dbd5c18.entry.js} +1 -1
  61. package/dist/sankhyablocks/{p-7bd9683d.js → p-2aebe5b6.js} +1 -1
  62. package/dist/sankhyablocks/{p-fa6c5826.entry.js → p-30ebcbe0.entry.js} +1 -1
  63. package/dist/sankhyablocks/{p-8a9638ae.js → p-341465ce.js} +2 -2
  64. package/dist/sankhyablocks/{p-052213ba.entry.js → p-3858a2e4.entry.js} +1 -1
  65. package/dist/sankhyablocks/{p-47bce500.js → p-47d24ac8.js} +1 -1
  66. package/dist/sankhyablocks/p-4fd06221.entry.js +1 -0
  67. package/dist/sankhyablocks/{p-275de842.entry.js → p-563b7c28.entry.js} +1 -1
  68. package/dist/sankhyablocks/{p-72c10005.entry.js → p-9c3138f5.entry.js} +1 -1
  69. package/dist/sankhyablocks/{p-4d9549cf.js → p-9ffd9fc7.js} +1 -1
  70. package/dist/sankhyablocks/{p-0b6cd238.entry.js → p-a2c790ac.entry.js} +1 -1
  71. package/dist/sankhyablocks/{p-fd13b4d2.js → p-a75e9dcc.js} +1 -1
  72. package/dist/sankhyablocks/{p-212213d9.entry.js → p-aa003d4e.entry.js} +1 -1
  73. package/dist/sankhyablocks/p-aaf94476.js +1 -0
  74. package/dist/sankhyablocks/{p-583517ba.entry.js → p-c1adf0dd.entry.js} +1 -1
  75. package/dist/sankhyablocks/p-da87e42c.entry.js +11 -0
  76. package/dist/sankhyablocks/{p-cfa1b199.js → p-e4391e16.js} +1 -1
  77. package/dist/sankhyablocks/{p-5e51e833.entry.js → p-f0aaad2b.entry.js} +1 -1
  78. package/dist/sankhyablocks/{p-cefb0ee1.entry.js → p-f7d76646.entry.js} +1 -1
  79. package/dist/sankhyablocks/{p-fb34e0cf.entry.js → p-fca0e5cc.entry.js} +1 -1
  80. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  81. package/dist/types/components/snk-application/request-listener/DebouncedRequestListener.d.ts +11 -0
  82. package/dist/types/components/snk-application/request-listener/RequestListenerFactory.d.ts +12 -0
  83. package/dist/types/components/snk-application/request-listener/RequestListenerLoadingBar.d.ts +13 -0
  84. package/dist/types/components/snk-application/snk-application.d.ts +3 -12
  85. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -0
  86. package/package.json +1 -1
  87. package/dist/sankhyablocks/p-ab1645fb.entry.js +0 -1
  88. package/dist/sankhyablocks/p-ca5ec380.js +0 -1
  89. 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 e,h as t,F as s}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as a}from"@sankhyalabs/core";import{S as n}from"./p-fadc8339.js";import{buildFormMetadata as d,FormMetadata as o}from"@sankhyalabs/ezui/dist/collection/utils/form";import{o as h,T as l,b as u}from"./p-23736d75.js";import{T as c}from"./p-7e7a7473.js";import{V as v}from"./p-95ce311a.js";import"./p-f3434fc4.js";import"./p-8a9638ae.js";import{P as g}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-47bce500.js";import"./p-ff1990ad.js";import"./p-06421fdb.js";import{SelectionMode as m}from"@sankhyalabs/core/dist/dataunit/DataUnit";const k="__FORM:",f=class{constructor(t){i(this,t),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={}}observeDataUnit(){this.loadGuides(!0)}observeDataState(i,e){const t=null==i?void 0:i.selectedRecord,s=null==e?void 0:e.selectedRecord;(null==t?void 0:t.__record__id__)!==(null==s?void 0:s.__record__id__)&&this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected())}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async findField(){await h(this._moreOptions,this._fieldSearch)}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,t){const s={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:t})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),s)}async setFocus(){this._container.focus()}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===c.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){f.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=d(this.masterFormConfig,this.dataUnit,!0);const e=this._masterFormMetadata.getAllSheets(),t=this.dataUnit.getSelectedRecord(),s=!t||this.dataUnit.isNewRecord(t.__record__id__),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&s&&(e.tooltip="Para alterar detalhes é necessário estar com um registro selecionado.",e.disabled=!0),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}isDetail(i){return null!=o.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}getTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkGuideViewer.finish_edition":"snkGuideViewer.regular"}loadTaskbarProcessor(){var i;const e=this.getTaskBarId(),t=[];this.dataState&&this.dataState.hasPrevious||t.push("PREVIOUS"),this.dataState&&this.dataState.hasNext||t.push("NEXT"),(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&(this.dataState.selectionInfo.length>1&&t.push("CLONE"),this.dataState.selectionInfo.isAllRecords()&&t.push("REMOVE"));const s=["PREVIOUS","NEXT","DIVIDER","ATTACH","CLONE","REMOVE","MORE_OPTIONS","ACTIONS_BUTTON","DIVIDER","GRID_MODE","CONFIGURATOR"];this.presentationMode==g.SECONDARY?s.unshift("INSERT"):s.push("INSERT");const r=this.getInvisibleButtons();this._taskbarProcessor=new l({"snkGuideViewer.regular":s,"snkGuideViewer.finish_edition":["CANCEL","SAVE",this.handleAddGridMode()]}),this._taskbarProcessor.process(e,this.taskbarManager,this.dataState,t,r)}handleAddGridMode(){return this.enableGridInsert?c.GRID_MODE:""}getInvisibleButtons(){const i=[];return this.dataState&&this.dataState.selectionInfo.mode===m.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}static updateContentCard(i,e,t,s){return s.saveCardState(i,e,t)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return t(s,null,Array.from(r.entries()).filter((([e,t])=>(null==t?void 0:t.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,s])=>{var r,a;const n=i.formMetadata.getSheet(e);if(null!=n)return t("snk-form-view",{levelPath:i.levelPath,label:n.label,name:e,fields:n.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==s?void 0:s.presentation),fixed:null==s?void 0:s.fixed,summaryFields:null===(a=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps})})))}wrapDetail(i,e){if(0===i.length)return e;const s=i.pop(),r=o.getDetailName(s);return r?this.wrapDetail(i,t("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const t=i.map((i=>o.getDetailName(i)));return`${this.entityPath}/${t.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){var i,e,s,r,a;if(!this.selectedGuide)return;const n=this.selectedGuide.id;let d;const h=n.split("::"),l=h.pop(),u=o.getDetailName(l);let c=n;if(u||h.length>0){let e,s;if(n.includes(k)){[c,e]=n.split(k);const t=(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)||0;s=t>1?this._breadcrumbItems[t-2]:this.selectedGuide}else s=this.selectedGuide;d=this.wrapDetail(h,t("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(h,u),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:u,selectedForm:e,branchGuide:s,guideItemPath:this._breadcrumbItems,key:`detail${c}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders}))}else{const i=this.selectedGuide.id,o=this._masterFormMetadata.getSheet(i);if(o){const h=null===(s=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===s?void 0:s.get(i);d=t("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==h?void 0:h.fixed,summaryFields:null===(a=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(i),name:i,label:o.label,fields:o.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:n,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps},this.presentationMode==g.SECONDARY&&this.buildTaskBar())}}return d}onBreadcrumbClickHandler(i){null!=(null==i?void 0:i.id)&&this._guideNavigator.selectGuide(i.id)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))]}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error("Erro interno: resourceID não informado");this._configManager=new n(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(this._currentDetail?this._currentDetail.showUp():this._mainForm&&this._mainForm.showUp(),this._guideHasChanged=!1)}getFieldsSearch(i,e){return(null==this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._moreOptions=i,i.addEventListener("taskbarActionsButtonDisconnected",(()=>this._hasToCreateFieldSearch=!0)),this._fieldSearch=u(e,(({argument:i})=>this.fieldsOptionLoader(i)),(e=>this.onSelectField(e,i)))),this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}onSelectField(i,e){if(null==i)return;this._fieldToGetFocus=i.value;const t=this.getGuideName(i.value);t!==this.selectedGuide.id&&this.changeGuideHandler(t),e.hideActions()}getActionsList(){return[{value:"",label:this.getMessage("snkCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,e)=>this.getFieldsSearch(i,e)}].concat(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions?this.taskbarManager.getMoreOptions(this.getTaskBarId(),this.configName,this.dataState,this.actionsList):this.actionsList)}buildTaskBar(){var i;return t("div",{class:"snk-guides-viewer__header-taskbar "+(this.presentationMode!=g.SECONDARY?"ez-align--right":"ez-padding-bottom--medium")},t("snk-taskbar",{key:"guideViewerTaskbar","data-element-id":"guideViewer",configName:this.configName,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,actionsList:this.getActionsList(),messagesBuilder:this.messagesBuilder,presentationMode:this.presentationMode,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-taskbar-owner":"master",dataUnit:this.dataUnit,resourceID:this.resourceID,customSlotId:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS",alignRigth:!0},t("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"})))}async dataUnitActionHandler(i){var e;if(i.type===r.FIELD_INVALIDATED){const t=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(t),await this.openGuideNavigator(t)}}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var t;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(t=i.badge)&&void 0!==t?t:null}getGuideName(i){var e;for(const t of this._masterFormMetadata.getAllSheets()){const s=null===(e=t[1])||void 0===e?void 0:e.fields;for(const e of s)if(e.name===i)return t[0]}return""}getTitle(){var i,e;return null!==(e=null===(i=this.getCustomTitle)||void 0===i?void 0:i.call(this))&&void 0!==e?e:this.getMessage("snkCrud.title")}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}render(){var i,e;if(null!=this._formEditorConfigManager)return t("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,ignoreReadOnlyFormFields:this.ignoreReadOnlyFormFields});if(!this.dataUnit||!this._configManager.isLoaded)return;this.loadTaskbarProcessor();const s=this._guides&&this._guides.length>1;return t("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabindex:-1},t("div",{class:"ez-row snk-guides-viewer__header"},t("div",{class:"snk-guides-viewer__header-breadcrumb ez-flex--align-items-center ez-flex-item--align-center ez-padding-left--large",key:"header"},t("ez-button",{onClick:()=>this.exitViewer(),title:this.getMessage("snkCrud.goBackTitle"),mode:"icon",iconName:"arrow_back",class:"ez-padding-right--medium",size:"small"}),t("div",{class:"ez-flex ez-flex--column ez-flex-item--auto"},t("h1",{class:"ez-title ez-title--primary ez-title--xlarge"},this.getTitle()),(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)>1&&t("div",{class:"ez-margin-top--extra-small"},t("ez-breadcrumb",Object.assign({items:this._breadcrumbItems,onSelectedItem:i=>this.onBreadcrumbClickHandler(null==i?void 0:i.detail)},{[a.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${a.getInternalIDInfo("breadcrumb")}`}))))),this.presentationMode!=g.SECONDARY&&this.buildTaskBar()),t("div",{class:"snk-guides-viewer__container"},s?t("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):t("div",null),t("div",{class:"snk-guides-viewer__detail-container"},f.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps}),this.getContent())),t("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID}))}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};f.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:68px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;display:block}snk-form-view.sc-snk-guides-viewer{width:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding-left:0px;padding-top:0px;padding-right:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:calc(var(--snk-guides-viewer__header--min-height) + var(--snk-guides-viewer--space-small));height:calc(100vh - var(--snk-guides-viewer__header--min-height) - var(--snk-guides-viewer--space-large) - var(--snk-guides-viewer--space-small))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{f as S}
1
+ import{r as i,c as e,h as t,F as s}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as a}from"@sankhyalabs/core";import{S as n}from"./p-0e206e62.js";import{buildFormMetadata as d,FormMetadata as o}from"@sankhyalabs/ezui/dist/collection/utils/form";import{o as h,T as l,b as u}from"./p-23736d75.js";import{T as c}from"./p-7e7a7473.js";import{V as v}from"./p-95ce311a.js";import"./p-00278e07.js";import"./p-341465ce.js";import{P as g}from"./p-30cf616e.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{SelectionMode as m}from"@sankhyalabs/core/dist/dataunit/DataUnit";const k="__FORM:",p=class{constructor(t){i(this,t),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={}}observeDataUnit(){this.loadGuides(!0)}observeDataState(i,e){const t=null==i?void 0:i.selectedRecord,s=null==e?void 0:e.selectedRecord;(null==t?void 0:t.__record__id__)!==(null==s?void 0:s.__record__id__)&&this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected())}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async findField(){await h(this._moreOptions,this._fieldSearch)}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,t){const s={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:t})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),s)}async setFocus(){this._container.focus()}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===c.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){p.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=d(this.masterFormConfig,this.dataUnit,!0);const e=this._masterFormMetadata.getAllSheets(),t=this.dataUnit.getSelectedRecord(),s=!t||this.dataUnit.isNewRecord(t.__record__id__),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&s&&(e.tooltip="Para alterar detalhes é necessário estar com um registro selecionado.",e.disabled=!0),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}isDetail(i){return null!=o.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}getTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkGuideViewer.finish_edition":"snkGuideViewer.regular"}loadTaskbarProcessor(){var i;const e=this.getTaskBarId(),t=[];this.dataState&&this.dataState.hasPrevious||t.push("PREVIOUS"),this.dataState&&this.dataState.hasNext||t.push("NEXT"),(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&(this.dataState.selectionInfo.length>1&&t.push("CLONE"),this.dataState.selectionInfo.isAllRecords()&&t.push("REMOVE"));const s=["PREVIOUS","NEXT","DIVIDER","ATTACH","CLONE","REMOVE","MORE_OPTIONS","ACTIONS_BUTTON","DIVIDER","GRID_MODE","CONFIGURATOR"];this.presentationMode==g.SECONDARY?s.unshift("INSERT"):s.push("INSERT");const r=this.getInvisibleButtons();this._taskbarProcessor=new l({"snkGuideViewer.regular":s,"snkGuideViewer.finish_edition":["CANCEL","SAVE",this.handleAddGridMode()]}),this._taskbarProcessor.process(e,this.taskbarManager,this.dataState,t,r)}handleAddGridMode(){return this.enableGridInsert?c.GRID_MODE:""}getInvisibleButtons(){const i=[];return this.dataState&&this.dataState.selectionInfo.mode===m.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}static updateContentCard(i,e,t,s){return s.saveCardState(i,e,t)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return t(s,null,Array.from(r.entries()).filter((([e,t])=>(null==t?void 0:t.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,s])=>{var r,a;const n=i.formMetadata.getSheet(e);if(null!=n)return t("snk-form-view",{levelPath:i.levelPath,label:n.label,name:e,fields:n.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==s?void 0:s.presentation),fixed:null==s?void 0:s.fixed,summaryFields:null===(a=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps})})))}wrapDetail(i,e){if(0===i.length)return e;const s=i.pop(),r=o.getDetailName(s);return r?this.wrapDetail(i,t("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const t=i.map((i=>o.getDetailName(i)));return`${this.entityPath}/${t.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){var i,e,s,r,a;if(!this.selectedGuide)return;const n=this.selectedGuide.id;let d;const h=n.split("::"),l=h.pop(),u=o.getDetailName(l);let c=n;if(u||h.length>0){let e,s;if(n.includes(k)){[c,e]=n.split(k);const t=(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)||0;s=t>1?this._breadcrumbItems[t-2]:this.selectedGuide}else s=this.selectedGuide;d=this.wrapDetail(h,t("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(h,u),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:u,selectedForm:e,branchGuide:s,guideItemPath:this._breadcrumbItems,key:`detail${c}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders}))}else{const i=this.selectedGuide.id,o=this._masterFormMetadata.getSheet(i);if(o){const h=null===(s=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===s?void 0:s.get(i);d=t("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==h?void 0:h.fixed,summaryFields:null===(a=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(i),name:i,label:o.label,fields:o.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:n,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps},this.presentationMode==g.SECONDARY&&this.buildTaskBar())}}return d}onBreadcrumbClickHandler(i){null!=(null==i?void 0:i.id)&&this._guideNavigator.selectGuide(i.id)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))]}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error("Erro interno: resourceID não informado");this._configManager=new n(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(this._currentDetail?this._currentDetail.showUp():this._mainForm&&this._mainForm.showUp(),this._guideHasChanged=!1)}getFieldsSearch(i,e){return(null==this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._moreOptions=i,i.addEventListener("taskbarActionsButtonDisconnected",(()=>this._hasToCreateFieldSearch=!0)),this._fieldSearch=u(e,(({argument:i})=>this.fieldsOptionLoader(i)),(e=>this.onSelectField(e,i)))),this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}onSelectField(i,e){if(null==i)return;this._fieldToGetFocus=i.value;const t=this.getGuideName(i.value);t!==this.selectedGuide.id&&this.changeGuideHandler(t),e.hideActions()}getActionsList(){return[{value:"",label:this.getMessage("snkCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,e)=>this.getFieldsSearch(i,e)}].concat(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions?this.taskbarManager.getMoreOptions(this.getTaskBarId(),this.configName,this.dataState,this.actionsList):this.actionsList)}buildTaskBar(){var i;return t("div",{class:"snk-guides-viewer__header-taskbar "+(this.presentationMode!=g.SECONDARY?"ez-align--right":"ez-padding-bottom--medium")},t("snk-taskbar",{key:"guideViewerTaskbar","data-element-id":"guideViewer",configName:this.configName,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,actionsList:this.getActionsList(),messagesBuilder:this.messagesBuilder,presentationMode:this.presentationMode,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-taskbar-owner":"master",dataUnit:this.dataUnit,resourceID:this.resourceID,customSlotId:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS",alignRigth:!0},t("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"})))}async dataUnitActionHandler(i){var e;if(i.type===r.FIELD_INVALIDATED){const t=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(t),await this.openGuideNavigator(t)}}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var t;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(t=i.badge)&&void 0!==t?t:null}getGuideName(i){var e;for(const t of this._masterFormMetadata.getAllSheets()){const s=null===(e=t[1])||void 0===e?void 0:e.fields;for(const e of s)if(e.name===i)return t[0]}return""}getTitle(){var i,e;return null!==(e=null===(i=this.getCustomTitle)||void 0===i?void 0:i.call(this))&&void 0!==e?e:this.getMessage("snkCrud.title")}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}render(){var i,e;if(null!=this._formEditorConfigManager)return t("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,ignoreReadOnlyFormFields:this.ignoreReadOnlyFormFields});if(!this.dataUnit||!this._configManager.isLoaded)return;this.loadTaskbarProcessor();const s=this._guides&&this._guides.length>1;return t("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabindex:-1},t("div",{class:"ez-row snk-guides-viewer__header"},t("div",{class:"snk-guides-viewer__header-breadcrumb ez-flex--align-items-center ez-flex-item--align-center ez-padding-left--large",key:"header"},t("ez-button",{onClick:()=>this.exitViewer(),title:this.getMessage("snkCrud.goBackTitle"),mode:"icon",iconName:"arrow_back",class:"ez-padding-right--medium",size:"small"}),t("div",{class:"ez-flex ez-flex--column ez-flex-item--auto"},t("h1",{class:"ez-title ez-title--primary ez-title--xlarge"},this.getTitle()),(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)>1&&t("div",{class:"ez-margin-top--extra-small"},t("ez-breadcrumb",Object.assign({items:this._breadcrumbItems,onSelectedItem:i=>this.onBreadcrumbClickHandler(null==i?void 0:i.detail)},{[a.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${a.getInternalIDInfo("breadcrumb")}`}))))),this.presentationMode!=g.SECONDARY&&this.buildTaskBar()),t("div",{class:"snk-guides-viewer__container"},s?t("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):t("div",null),t("div",{class:"snk-guides-viewer__detail-container"},p.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps}),this.getContent())),t("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID}))}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};p.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:68px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;display:block}snk-form-view.sc-snk-guides-viewer{width:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding-left:0px;padding-top:0px;padding-right:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:calc(var(--snk-guides-viewer__header--min-height) + var(--snk-guides-viewer--space-small));height:calc(100vh - var(--snk-guides-viewer__header--min-height) - var(--snk-guides-viewer--space-large) - var(--snk-guides-viewer--space-small))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{p as S}
@@ -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}