@sankhyalabs/sankhyablocks 10.1.0-dev.53 → 10.1.0-dev.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/cjs/{ConfigStorage-4201dd3d.js → ConfigStorage-a28eceb2.js} +2 -2
  2. package/dist/cjs/{DataFetcher-b3a8075d.js → DataFetcher-98d95e8f.js} +0 -39
  3. package/dist/cjs/{ISave-4674c283.js → ISave-a9815bb3.js} +1 -1
  4. package/dist/cjs/{SnkFormConfigManager-c3a49038.js → SnkFormConfigManager-af47ba2f.js} +2 -2
  5. package/dist/cjs/{SnkMultiSelectionListDataSource-0bc94d36.js → SnkMultiSelectionListDataSource-83065af6.js} +4 -4
  6. package/dist/cjs/{auth-fetcher-0ecc53ff.js → auth-fetcher-9c257a1f.js} +1 -1
  7. package/dist/cjs/{dataunit-fetcher-bcbc38c0.js → dataunit-fetcher-afc246d8.js} +28 -106
  8. package/dist/cjs/{form-config-fetcher-f80dbc3b.js → form-config-fetcher-1ce4125c.js} +1 -1
  9. package/dist/cjs/pesquisa-grid_2.cjs.entry.js +4 -4
  10. package/dist/cjs/snk-actions-button_9.cjs.entry.js +5 -5
  11. package/dist/cjs/snk-application.cjs.entry.js +6 -6
  12. package/dist/cjs/snk-attach_11.cjs.entry.js +8 -8
  13. package/dist/cjs/snk-crud.cjs.entry.js +6 -6
  14. package/dist/cjs/snk-data-exporter.cjs.entry.js +5 -5
  15. package/dist/cjs/{snk-data-unit-3b94547d.js → snk-data-unit-ab570f87.js} +2 -2
  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-dynaform-detail-view_2.cjs.entry.js +7 -7
  19. package/dist/cjs/{snk-dynaform-guides-view-e98f7f3a.js → snk-dynaform-guides-view-30ce5a8c.js} +2 -2
  20. package/dist/cjs/snk-dynaform-guides-view.cjs.entry.js +4 -4
  21. package/dist/cjs/snk-dynaform.cjs.entry.js +6 -6
  22. package/dist/cjs/snk-filter-bar_4.cjs.entry.js +3 -3
  23. package/dist/cjs/snk-form_2.cjs.entry.js +4 -4
  24. package/dist/cjs/snk-grid.cjs.entry.js +6 -6
  25. package/dist/cjs/{snk-guides-viewer-3054d541.js → snk-guides-viewer-2a55fa3a.js} +1 -1
  26. package/dist/cjs/snk-guides-viewer.cjs.entry.js +5 -5
  27. package/dist/cjs/snk-layout-form-config.cjs.entry.js +4 -4
  28. package/dist/cjs/snk-pesquisa.cjs.entry.js +4 -4
  29. package/dist/cjs/{taskbarUtils-38748460.js → taskbarUtils-4ca4235e.js} +4 -4
  30. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +1 -1
  31. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +11 -1
  32. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.js +15 -104
  33. package/dist/collection/lib/message/resources/en-us/dataUnitDataLoaderHelper.msg.js +0 -13
  34. package/dist/collection/lib/message/resources/es-es/dataUnitDataLoaderHelper.msg.js +0 -13
  35. package/dist/collection/lib/message/resources/pt-br/dataUnitDataLoaderHelper.msg.js +0 -13
  36. package/dist/components/SnkMessageBuilder.js +0 -39
  37. package/dist/components/dataunit-fetcher.js +27 -106
  38. package/dist/esm/{ConfigStorage-e834d1ea.js → ConfigStorage-346d781d.js} +2 -2
  39. package/dist/esm/{DataFetcher-5ed0a377.js → DataFetcher-7d8df5a2.js} +0 -39
  40. package/dist/esm/{ISave-5b46d691.js → ISave-2117075a.js} +1 -1
  41. package/dist/esm/{SnkFormConfigManager-bfd575c2.js → SnkFormConfigManager-066d370b.js} +2 -2
  42. package/dist/esm/{SnkMultiSelectionListDataSource-9e9166ae.js → SnkMultiSelectionListDataSource-c6c48bc9.js} +4 -4
  43. package/dist/esm/{auth-fetcher-5283045d.js → auth-fetcher-5891e22c.js} +1 -1
  44. package/dist/esm/{dataunit-fetcher-3b1ca96e.js → dataunit-fetcher-5dcb0e89.js} +28 -106
  45. package/dist/esm/{form-config-fetcher-db1bf140.js → form-config-fetcher-8e2082f3.js} +1 -1
  46. package/dist/esm/pesquisa-grid_2.entry.js +4 -4
  47. package/dist/esm/snk-actions-button_9.entry.js +5 -5
  48. package/dist/esm/snk-application.entry.js +6 -6
  49. package/dist/esm/snk-attach_11.entry.js +8 -8
  50. package/dist/esm/snk-crud.entry.js +6 -6
  51. package/dist/esm/snk-data-exporter.entry.js +5 -5
  52. package/dist/esm/{snk-data-unit-dfde62cb.js → snk-data-unit-f697345b.js} +2 -2
  53. package/dist/esm/snk-data-unit.entry.js +3 -3
  54. package/dist/esm/snk-detail-view.entry.js +7 -7
  55. package/dist/esm/snk-dynaform-detail-view_2.entry.js +7 -7
  56. package/dist/esm/{snk-dynaform-guides-view-1f1455d6.js → snk-dynaform-guides-view-6aae38f7.js} +2 -2
  57. package/dist/esm/snk-dynaform-guides-view.entry.js +4 -4
  58. package/dist/esm/snk-dynaform.entry.js +6 -6
  59. package/dist/esm/snk-filter-bar_4.entry.js +3 -3
  60. package/dist/esm/snk-form_2.entry.js +4 -4
  61. package/dist/esm/snk-grid.entry.js +6 -6
  62. package/dist/esm/{snk-guides-viewer-95fefcaa.js → snk-guides-viewer-3ea7e312.js} +1 -1
  63. package/dist/esm/snk-guides-viewer.entry.js +5 -5
  64. package/dist/esm/snk-layout-form-config.entry.js +4 -4
  65. package/dist/esm/snk-pesquisa.entry.js +4 -4
  66. package/dist/esm/{taskbarUtils-8501d09e.js → taskbarUtils-a43e4bba.js} +4 -4
  67. package/dist/sankhyablocks/{p-5d02c032.js → p-10d883b0.js} +1 -1
  68. package/dist/sankhyablocks/{p-51e853f2.js → p-13f91e7e.js} +1 -1
  69. package/dist/sankhyablocks/{p-6b8a1ec3.js → p-1bc6849e.js} +1 -1
  70. package/dist/sankhyablocks/{p-7628e04f.entry.js → p-2d63e79d.entry.js} +1 -1
  71. package/dist/sankhyablocks/{p-b1bf9564.js → p-3190ac29.js} +2 -2
  72. package/dist/sankhyablocks/{p-c538bd6c.entry.js → p-3630a5ae.entry.js} +1 -1
  73. package/dist/sankhyablocks/{p-b4c2a99c.entry.js → p-3cc67d50.entry.js} +1 -1
  74. package/dist/sankhyablocks/{p-7798788b.entry.js → p-4a53fbeb.entry.js} +1 -1
  75. package/dist/sankhyablocks/{p-2c00b93d.js → p-4cc1d58b.js} +1 -1
  76. package/dist/sankhyablocks/{p-61776b68.entry.js → p-536b988a.entry.js} +1 -1
  77. package/dist/sankhyablocks/{p-b75af274.entry.js → p-58e0f14b.entry.js} +1 -1
  78. package/dist/sankhyablocks/{p-43c94ba5.entry.js → p-5a8390f9.entry.js} +1 -1
  79. package/dist/sankhyablocks/{p-d7fd447e.entry.js → p-6f2de911.entry.js} +1 -1
  80. package/dist/sankhyablocks/{p-7038cf62.entry.js → p-741f1ad0.entry.js} +1 -1
  81. package/dist/sankhyablocks/{p-1edd6be6.entry.js → p-7827871d.entry.js} +1 -1
  82. package/dist/sankhyablocks/{p-22ddc1a5.entry.js → p-7e63af25.entry.js} +1 -1
  83. package/dist/sankhyablocks/{p-1cc4cf61.js → p-8d513b64.js} +1 -1
  84. package/dist/sankhyablocks/{p-589016e2.entry.js → p-a8a93568.entry.js} +1 -1
  85. package/dist/sankhyablocks/{p-3623fddf.entry.js → p-aa9d61fa.entry.js} +1 -1
  86. package/dist/sankhyablocks/{p-7c34a0f7.entry.js → p-acd3adf9.entry.js} +1 -1
  87. package/dist/sankhyablocks/{p-f1ef090f.entry.js → p-b3762105.entry.js} +1 -1
  88. package/dist/sankhyablocks/p-c1e168a2.js +60 -0
  89. package/dist/sankhyablocks/{p-d5810110.js → p-c3bc693a.js} +1 -1
  90. package/dist/sankhyablocks/{p-70c2ee5c.js → p-c5889dae.js} +1 -1
  91. package/dist/sankhyablocks/{p-451b5bcc.entry.js → p-c6b6567f.entry.js} +1 -1
  92. package/dist/sankhyablocks/{p-d88278f8.js → p-d7657667.js} +1 -1
  93. package/dist/sankhyablocks/{p-19d1ca14.js → p-e91bd00e.js} +1 -1
  94. package/dist/sankhyablocks/{p-77c26de0.js → p-ed1b1b14.js} +1 -1
  95. package/dist/sankhyablocks/{p-a4a0d9b7.entry.js → p-ee192f06.entry.js} +1 -1
  96. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  97. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.d.ts +3 -1
  98. package/package.json +5 -1
  99. package/dist/sankhyablocks/p-f076d742.js +0 -60
@@ -1,4 +1,4 @@
1
- import{R as e,F as t}from"./p-d88278f8.js";import{D as i,d as s}from"./p-5d02c032.js";import{F as r}from"./p-ff1990ad.js";import{ObjectUtils as a}from"@sankhyalabs/core";var n;function l(e,t){if(null==e)return e;if(e instanceof Date)return e.toISOString();if("object"==typeof e){if(e instanceof Array)return e.map((e=>l(r.MULTI_LIST===t?function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i}(e,["label"]):e)));{const i=Object.assign({},e);return Object.keys(e).forEach((s=>{void 0!==e[s]?i[s]=l(e[s],t):delete i[s]})),i}}return e}class o{constructor(){this.DEFAULT_RESOURCE="_default",this.templateByQuery=new Map,this.buildTemplates()}resolveURI(e,t,i){let s="filter-assistent-config://"+e;return t&&(s+="."+t),i&&(s+=this.DEFAULT_RESOURCE),s}resolveLegacyConfigName(e,t){if(!e)return"";let i=`?legacyResourceID=${e}`;return t&&(i+=this.DEFAULT_RESOURCE),i}buildTemplates(){this.templateByQuery.set("fetchFilterFields",s.gql`
1
+ import{R as e,F as t}from"./p-d7657667.js";import{D as i,d as s}from"./p-10d883b0.js";import{F as r}from"./p-ff1990ad.js";import{ObjectUtils as a}from"@sankhyalabs/core";var n;function l(e,t){if(null==e)return e;if(e instanceof Date)return e.toISOString();if("object"==typeof e){if(e instanceof Array)return e.map((e=>l(r.MULTI_LIST===t?function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i}(e,["label"]):e)));{const i=Object.assign({},e);return Object.keys(e).forEach((s=>{void 0!==e[s]?i[s]=l(e[s],t):delete i[s]})),i}}return e}class o{constructor(){this.DEFAULT_RESOURCE="_default",this.templateByQuery=new Map,this.buildTemplates()}resolveURI(e,t,i){let s="filter-assistent-config://"+e;return t&&(s+="."+t),i&&(s+=this.DEFAULT_RESOURCE),s}resolveLegacyConfigName(e,t){if(!e)return"";let i=`?legacyResourceID=${e}`;return t&&(i+=this.DEFAULT_RESOURCE),i}buildTemplates(){this.templateByQuery.set("fetchFilterFields",s.gql`
2
2
  query($name: String!) {
3
3
  $queryAlias$: fetchFilterFields(name: $name){
4
4
  currentLink {
@@ -1 +1 @@
1
- import"./p-5d02c032.js";import"./p-b1bf9564.js";import"@sankhyalabs/core";import{P as n}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-f076d742.js";import"./p-ff1990ad.js";import"./p-d88278f8.js";import{V as i}from"./p-9019a32f.js";import{T as s}from"./p-3072136e.js";class t{constructor(n){this._defaultButtons=[],this._defaultButtons=[...n]}process(n,i,s,t=[],r=[]){var o;this.taskbarID=n,this.customButtons=new Map,this.buttonsArray=[],this.disabledButtons=[...t],null===(o=this.getButtonsArray(i,s))||void 0===o||o.forEach((n=>{let o;"string"==typeof n?o=n:(this.customButtons.set(n.name,n),o=n.name),r.includes(o)||(this.isEnabled(i,o,s,t)||this.disabledButtons.push(o),this.buttonsArray.push(o))})),this.buttons=this.buttonsArray.join(",")}getButtonsArray(n,i){return n?n.getButtons(this.taskbarID,i,[...this._defaultButtons]):this._defaultButtons}isEnabled(n,i,s,t){const r=!t.includes(i);return n&&n.isEnabled?n.isEnabled(this.taskbarID,s,i,r):r}}const r=[s.FORM_MODE,s.PREVIOUS,s.NEXT,s.REFRESH,s.SPACER,s.ACTIONS_BUTTON,s.DATA_EXPORTER,s.ATTACH,s.CLONE,s.UPDATE,s.REMOVE,s.INSERT,s.CONFIGURATOR,s.MORE_OPTIONS];var o;function a(n,t,r){var a,e;const l=[{name:o.FILTER,hint:null!==(a=null==r?void 0:r.getMessage("snkCrud.customButtons.filter"))&&void 0!==a?a:"Abre o painel de filtros",iconName:"filter"},{name:o.ENTITY_SEARCH,hint:null!==(e=null==r?void 0:r.getMessage("snkCrud.customButtons.entitySearch"))&&void 0!==e?e:"Busca na entidade",iconName:"search"}],d=[s.CANCEL,s.SAVE];return{getButtons:(r,o,a)=>{var e,u;if(!r)return console.warn("taskbarID não fornecido"),[];if((null==o?void 0:o.insertionMode)||(null==o?void 0:o.isDirty))return d;if(n===i.FORM){const n=a.indexOf(s.FORM_MODE);n>-1&&(a=[...a.slice(0,n),s.GRID_MODE,...a.slice(n+1)])}if((null===(u=null===(e=null==o?void 0:o.selectionInfo)||void 0===e?void 0:e.records)||void 0===u?void 0:u.length)>1){const n=a.indexOf(s.UPDATE);n>-1&&(a=[...a.slice(0,n),s.UPDATE_MULTIPLE,...a.slice(n+1)])}const c=function(n,i){const t=n.findIndex((n=>n===s.SPACER||"string"==typeof n&&"SPACER"===n));return t>-1?[...n.slice(0,t),...i,...n.slice(t)]:[...i,...n]}(a,l);return(null==t?void 0:t.getButtons)?t.getButtons(r,o,c):c},isEnabled:(n,i,r,o)=>{var a;if(!i)return o;if(void 0===i.selectedRecord&&[s.UPDATE,s.REMOVE,s.ATTACH,s.CLONE].includes(r))return!1;const e=function(n){const i=[];return(null==n?void 0:n.hasPrevious)||i.push(s.PREVIOUS),(null==n?void 0:n.hasNext)||i.push(s.NEXT),i}(i);return!e.includes(r)&&(null!==(a=null==t?void 0:t.isEnabled(n,i,r,o))&&void 0!==a?a:o)},getMoreOptions(n,i,s,r){var o;return null===(o=null==t?void 0:t.getMoreOptions)||void 0===o?void 0:o.call(t,n,i,s,r)}}}function e(i,s){var t;const r=i&&!!(null===(t=i.selectionInfo)||void 0===t?void 0:t.length),o={primary:"snkGridHeaderTaskbar",secondary:"snkGridHeaderTaskbar",singleTaskbar:"snkGridHeaderTaskbar.singleTaskbar"}[s];let a=r?`${o}.selected`:`${o}.unselected`;return(null==i?void 0:i.isDirty)&&s===n.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}function l(n,i){const s={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[i];return(null==n?void 0:n.isDirty)?`snkGridTopTaskbar.finish_edition${s}`:`snkGridTopTaskbar.regular${s}`}!function(n){n.FILTER="FILTER",n.ENTITY_SEARCH="ENTITY_SEARCH"}(o||(o={}));export{o as C,r as D,t as S,e as a,a as b,l as g}
1
+ import"./p-10d883b0.js";import"./p-3190ac29.js";import"@sankhyalabs/core";import{P as n}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-c1e168a2.js";import"./p-ff1990ad.js";import"./p-d7657667.js";import{V as i}from"./p-9019a32f.js";import{T as s}from"./p-3072136e.js";class t{constructor(n){this._defaultButtons=[],this._defaultButtons=[...n]}process(n,i,s,t=[],r=[]){var o;this.taskbarID=n,this.customButtons=new Map,this.buttonsArray=[],this.disabledButtons=[...t],null===(o=this.getButtonsArray(i,s))||void 0===o||o.forEach((n=>{let o;"string"==typeof n?o=n:(this.customButtons.set(n.name,n),o=n.name),r.includes(o)||(this.isEnabled(i,o,s,t)||this.disabledButtons.push(o),this.buttonsArray.push(o))})),this.buttons=this.buttonsArray.join(",")}getButtonsArray(n,i){return n?n.getButtons(this.taskbarID,i,[...this._defaultButtons]):this._defaultButtons}isEnabled(n,i,s,t){const r=!t.includes(i);return n&&n.isEnabled?n.isEnabled(this.taskbarID,s,i,r):r}}const r=[s.FORM_MODE,s.PREVIOUS,s.NEXT,s.REFRESH,s.SPACER,s.ACTIONS_BUTTON,s.DATA_EXPORTER,s.ATTACH,s.CLONE,s.UPDATE,s.REMOVE,s.INSERT,s.CONFIGURATOR,s.MORE_OPTIONS];var o;function a(n,t,r){var a,e;const l=[{name:o.FILTER,hint:null!==(a=null==r?void 0:r.getMessage("snkCrud.customButtons.filter"))&&void 0!==a?a:"Abre o painel de filtros",iconName:"filter"},{name:o.ENTITY_SEARCH,hint:null!==(e=null==r?void 0:r.getMessage("snkCrud.customButtons.entitySearch"))&&void 0!==e?e:"Busca na entidade",iconName:"search"}],d=[s.CANCEL,s.SAVE];return{getButtons:(r,o,a)=>{var e,u;if(!r)return console.warn("taskbarID não fornecido"),[];if((null==o?void 0:o.insertionMode)||(null==o?void 0:o.isDirty))return d;if(n===i.FORM){const n=a.indexOf(s.FORM_MODE);n>-1&&(a=[...a.slice(0,n),s.GRID_MODE,...a.slice(n+1)])}if((null===(u=null===(e=null==o?void 0:o.selectionInfo)||void 0===e?void 0:e.records)||void 0===u?void 0:u.length)>1){const n=a.indexOf(s.UPDATE);n>-1&&(a=[...a.slice(0,n),s.UPDATE_MULTIPLE,...a.slice(n+1)])}const c=function(n,i){const t=n.findIndex((n=>n===s.SPACER||"string"==typeof n&&"SPACER"===n));return t>-1?[...n.slice(0,t),...i,...n.slice(t)]:[...i,...n]}(a,l);return(null==t?void 0:t.getButtons)?t.getButtons(r,o,c):c},isEnabled:(n,i,r,o)=>{var a;if(!i)return o;if(void 0===i.selectedRecord&&[s.UPDATE,s.REMOVE,s.ATTACH,s.CLONE].includes(r))return!1;const e=function(n){const i=[];return(null==n?void 0:n.hasPrevious)||i.push(s.PREVIOUS),(null==n?void 0:n.hasNext)||i.push(s.NEXT),i}(i);return!e.includes(r)&&(null!==(a=null==t?void 0:t.isEnabled(n,i,r,o))&&void 0!==a?a:o)},getMoreOptions(n,i,s,r){var o;return null===(o=null==t?void 0:t.getMoreOptions)||void 0===o?void 0:o.call(t,n,i,s,r)}}}function e(i,s){var t;const r=i&&!!(null===(t=i.selectionInfo)||void 0===t?void 0:t.length),o={primary:"snkGridHeaderTaskbar",secondary:"snkGridHeaderTaskbar",singleTaskbar:"snkGridHeaderTaskbar.singleTaskbar"}[s];let a=r?`${o}.selected`:`${o}.unselected`;return(null==i?void 0:i.isDirty)&&s===n.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}function l(n,i){const s={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[i];return(null==n?void 0:n.isDirty)?`snkGridTopTaskbar.finish_edition${s}`:`snkGridTopTaskbar.regular${s}`}!function(n){n.FILTER="FILTER",n.ENTITY_SEARCH="ENTITY_SEARCH"}(o||(o={}));export{o as C,r as D,t as S,e as a,a as b,l as g}
@@ -1 +1 @@
1
- import{r as t,e as i,h as s,f as e,F as n,g as a}from"./p-2c9d0870.js";import{ApplicationContext as o,DataType as r,Action as l,UserInterface as h,StringUtils as d,DataUnitLoaderUtils as c,DataUnit as u,ElementIDUtils as v,ObjectUtils as m,KeyboardManager as f}from"@sankhyalabs/core";import{D as p,S as g}from"./p-5d02c032.js";import{S as b}from"./p-b1bf9564.js";import{P as k}from"./p-0f3698af.js";import{P as _,D as y,I as w}from"./p-f076d742.js";import{F as C}from"./p-ff1990ad.js";import{F as z}from"./p-d88278f8.js";import{V as A,S as x}from"./p-9019a32f.js";import{A as S}from"./p-d5810110.js";import{T as O}from"./p-3072136e.js";import{A as F,F as I}from"./p-0dbd53d9.js";import{focusOnFieldSerch as E,SEARCH_FIELD_FULL_WIDTH as P,FormLayout as N,ApplicationUtils as T,CSSVarsUtils as L,buildFieldSearch as D}from"@sankhyalabs/ezui/dist/collection/utils";import{DataBinder as j}from"@sankhyalabs/ezui/dist/collection/utils/form";import{g as R,b as M,s as U,a as V,d as B}from"./p-af673291.js";import{P as K,a as G,D as $}from"./p-58709cf9.js";import{E as q}from"./p-1a68fb59.js";import{C as H,P as Q}from"./p-51e853f2.js";import{s as J}from"./p-a73b6b00.js";import{S as W,T as X,R as Y,a as Z,b as tt}from"./p-2c00b93d.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{S as it}from"./p-1cc4cf61.js";import{C as st}from"./p-e5a3711f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-7dd49d15.js";import"./p-8f3f2306.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";class et{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:s,operation:e}){var n,a;const o="INSERT"==e,r=o?s:i;if(!o&&(null==s?void 0:s.DESCRICAO)&&(null==s?void 0:s.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(b.DESCRIPTION_CANNOT_BE_CHANGED);const l={anexo:{codata:o?null==s?void 0:s.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(a=null===(n=s.CAMINHO_ARQUIVO)||void 0===n?void 0:n[0])||void 0===a?void 0:a.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,e)=>{p.get().callServiceBroker("Attach.save",JSON.stringify(l)).then((e=>{var n;return i([Object.assign(Object.assign(Object.assign({},e),s),{__owner__dataunit__name__:null!==(n=this.dataUnitName)&&void 0!==n?n:t})])})).catch((t=>e(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const s=await p.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(s)}async getDownloadKey(t){var i,s,e;if("S"==t.EHARQUIVOREPOSITORIO){const e={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},n=await p.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(e));return Promise.resolve({chave:{valor:null===(s=null===(i=null==n?void 0:n.responseBody)||void 0===i?void 0:i.chave)||void 0===s?void 0:s.valor}})}const n={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},a=await p.get().callServiceBroker("Attach.view",JSON.stringify(n));return(null==a?void 0:a.chaveAnexo)?Promise.resolve({chave:{valor:null===(e=null==a?void 0:a.chaveAnexo)||void 0===e?void 0:e.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const nt="AnexoSistemaSP.salvar",at="AnexoSistemaSP.excluir",ot="AnexoSistemaSP.baixar";class rt{constructor(t,i){var s;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(b.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(b.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(s=window.workspace)||void 0===s?void 0:s.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,s;let{updatingFields:e}=t;e=Object.assign(Object.assign({},e),{NOMEARQUIVO:null===(i=e.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(e);const t=e.LINK?null:e.NOMEARQUIVO,i={serviceName:nt,requestBody:{params:{resourceID:this.resourceID,description:e.DESCRICAO,fileSelect:t?1:0,keySession:null===(s=null==t?void 0:t.properties)||void 0===s?void 0:s.fileNameTmp,nameAttach:null==t?void 0:t.name,link:e.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:e.TIPOACESSO,typeApres:e.TIPOAPRES}}},n=await p.get().callServiceBroker(nt,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},n),e),{ARQUIVOOULINK:e.LINK?e.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,s,e;let{updatingFields:n,record:a}=t;const o=t=>void 0!==n[t]?n[t]:a[t],r=o("NOMEARQUIVO"),l=null===(s=null===(i=n.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===s?void 0:s.downloadURL;n=Object.assign(Object.assign({},n),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:a.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const h=n.LINK?null:n.NOMEARQUIVO;try{this.validateFields(n);const t={serviceName:nt,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==a?void 0:a.NUATTACH,description:n.DESCRICAO,fileSelect:l?1:0,keySession:null===(e=null==h?void 0:h.properties)||void 0===e?void 0:e.fileNameTmp,keyAttach:n.CHAVEARQUIVO,nameAttach:null==h?void 0:h.name,link:n.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:n.TIPOACESSO,typeApres:n.TIPOAPRES}}},i=await p.get().callServiceBroker(nt,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),n),{ARQUIVOOULINK:n.LINK?n.LINK:null==h?void 0:h.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},e={serviceName:at,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{p.get().callServiceBroker(at,JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},e={serviceName:ot,requestBody:{paramsDown:{nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{p.get().callServiceBroker(ot,JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}}class lt{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=o.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,s){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,e)=>this.saveLoader(e,i).then((t=>(t.length&&s(),t))),t.removeLoader=(t,e)=>this.removeLoader(t,e,i).then((t=>(t.length&&s(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((s=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));s(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((s=>{var e;const n=Array.isArray(t)?t[0]:{};((null===(e=null==n?void 0:n.record)||void 0===e?void 0:e.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(n).then((t=>{s(t)})).catch((t=>t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),s([])):t.message===b.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),s([])):t.message?(this._application.error(t.title||t.name,t.message),s([])):void s([])))}))}removeLoader(t,i,s){return new Promise((e=>{const{records:n}=t.getSelectionInfo(),a=n[0];s.delete(a).then((()=>(_.removeRecords(t,[a]),e(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:r.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,s){return new Promise((e=>i.type===l.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(s.goToView(A.GRID),e(i)):e(void 0))):e(i):i.type===l.DATA_SAVED?(t.loadData(),e(i)):void e(i)))}}let ht;const dt=t=>(ht||(ht=new g),ht.getMessage(t)),ct={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:dt("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:dt("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},ut={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:dt("snkAttach.attachMetadata.lblCode"),dataType:r.TEXT},{name:"DESCRICAO",label:dt("snkAttach.attachMetadata.lblDescription"),dataType:r.TEXT,readOnly:!1},{name:"ARQUIVO",label:dt("snkAttach.attachMetadata.lblFileOrLink"),dataType:r.TEXT},{name:"USUARIO",label:dt("snkAttach.attachMetadata.lblUser"),dataType:r.TEXT},{name:"DTALTER",label:dt("snkAttach.attachMetadata.lblDate"),dataType:r.TEXT},{name:"CAMINHO_ARQUIVO",label:dt("snkAttach.attachMetadata.lblFileUpload"),dataType:r.OBJECT,userInterface:h.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:dt("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class vt{constructor(t){this.getMessage=t,this._records=[],this._application=o.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,s){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,e)=>this.saveLoader(e,i).then((t=>(t.length&&s(),t))),t.removeLoader=(t,e)=>this.removeLoader(t,e,i).then((t=>(t.length&&s(),t)))}metadataLoader(t){return Promise.resolve(ut)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},s=await this._application.getDataFetcher(),{anexos:{anexo:e=[]}}=await s.callServiceBroker("Attach.load",JSON.stringify(t)),n=[];e.forEach((t=>{n.push(Object.assign({__record__id__:d.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=n}return c.buildLoadDataResponse(this._records,t,i)}saveLoader(t,i){return new Promise((s=>{const e=Array.isArray(t)?t[0]:{};i.save(e).then(s).catch((t=>t.message===b.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),s([])):t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),s([])):t.message===b.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),s([])):t.message?(this._application.error(t.title||t.name,t.message),s([])):void s([])))}))}removeLoader(t,i,s){return new Promise((e=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(S.REMOVE).then((async n=>{n&&(await s.delete(t),e(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,s){return new Promise((e=>{var n,a,o,r,h,d;switch(i.type){case l.EDITION_CANCELED:return t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(s.goToView(A.GRID),e(i)):e(void 0))):e(i);case l.DATA_SAVED:return t.loadData(void 0,void 0,!1,null===(o=null===(a=null===(n=null==i?void 0:i.payload)||void 0===n?void 0:n.records)||void 0===a?void 0:a[0])||void 0===o?void 0:o.REGISTER_KEY),e(i);case l.RECORDS_REMOVED:return t.loadData(void 0,void 0,!1,null===(d=null===(h=null===(r=null==i?void 0:i.payload)||void 0===r?void 0:r.cachedRecords)||void 0===h?void 0:h[0])||void 0===d?void 0:d.CODATA),e(i)}e(i)}))}}let mt;const ft=t=>{var i;if(!mt){const t=o.getContextValue("__SNK__APPLICATION__");mt=null==t?void 0:t.messagesBuilder}return null===(i=null==mt?void 0:mt.getMessage)||void 0===i?void 0:i.call(mt,t,null)},pt={DOWNLOAD:{hint:ft("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:ft("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},gt=()=>{const t=[O.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,s)=>{const e=s.indexOf(O.REFRESH);if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return s.reverse();-1!==e&&s.splice(e,1);const{selectedRecord:n}=i||{},a=(null==n?void 0:n.LINK)?pt.LINK:pt.DOWNLOAD;s.splice(s.indexOf(O.DIVIDER)+1,0,O.REMOVE,a,O.DIVIDER);const o=[O.CLONE,O.DATA_EXPORTER],r=Array.from(new Set(s.filter((t=>!o.includes(t)))));return r.splice(r.indexOf(a)+1,0,O.DIVIDER),r},isEnabled:(i,s,e)=>{const n=void 0!==(null==s?void 0:s.selectedRecord);return!(t.includes(e)&&!n)}}},bt={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},kt=class{constructor(s){t(this,s),this.ezClosePopup=i(this,"ezClosePopup",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.close()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.close();this.validateAnexoSistema()&&this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.close()}))},this._isOpen=!1,this.gridLegacyConfigName=void 0,this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0,this._appResourceID=void 0}async open(){this._isOpen=!0,this._currentDataUnit||await this.initAttach(),this._refPopup&&(this._refPopup.opened=!0),this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async close(){this._isOpen=!1,this._refPopup&&(this._refPopup.opened=!1)}async registerKeyWatcher(t,i){var s;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof rt&&(this._currentFetcher.registerKey=t),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new rt(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,s,e,n;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(s=this.registerKey)||void 0===s?void 0:s.split("_").length)>1)return;await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadMetadata()),await(null===(n=this._currentDataUnit)||void 0===n?void 0:n.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error(this.getMessage("snkAttach.alertValidation.noRecordSelected.message"));t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var s;let e=!1;(null===(s=null==t?void 0:t.ARQUIVO)||void 0===s?void 0:s.endsWith(".pdf"))||(e=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${e?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;let s;this._currentDataUnit=(new y).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=this.entityName?{form:null==bt?void 0:bt.form}:Object.assign({},bt),s={grid:null==bt?void 0:bt.grid}),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm(s)}async loadAttach(){var t,i;let s;this._currentFetcher=new et,this._currentDataUnit=new u(w.IN_MEMORY_DATA_UNIT_NAME),this._currentDataUnit.pageSize=150,this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===l.METADATA_LOADED&&(this.crudConfig=this.entityName?{form:null==ct?void 0:ct.form}:Object.assign({},ct),s={grid:null==ct?void 0:ct.grid},null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=this.entityName?{form:null==ct?void 0:ct.form}:Object.assign({},ct),s={grid:null==ct?void 0:ct.grid},await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm(s))}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new lt(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new et,this._currentDataUnitBuilder=new vt(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(t){var i,s,e,n,a;const o=(null===(s=null===(i=this._crudElement)||void 0===i?void 0:i.gridConfig)||void 0===s?void 0:s.columns)||(null===(e=null==t?void 0:t.grid)||void 0===e?void 0:e.columns)||(null===(a=null===(n=this.crudConfig)||void 0===n?void 0:n.grid)||void 0===a?void 0:a.columns);this.getGridLegacyConfigName()&&this._currentDataUnit.disableField("ARQUIVOOULINK"),null==o||o.forEach((t=>{var i,s;const e=t.name;(null===(s=null===(i=this.crudConfig)||void 0===i?void 0:i.form)||void 0===s?void 0:s.fields.some((t=>(null==t?void 0:t.name)===e)))||this._currentDataUnit.disableField(e)}))}validateAnexoSistema(){var t;if(this._currentFetcher instanceof rt)try{let i=this._currentDataUnit.getSelectedRecord();i=Object.assign(Object.assign({},i),{NOMEARQUIVO:null===(t=i.NOMEARQUIVO)||void 0===t?void 0:t[0]}),this._currentFetcher.validateFields(i)}catch(t){if(t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME)return this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),!1;if(t.message===b.ANY_LINK_OR_FILE_FILLED)return this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),!1}return!0}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),this._application&&(this._appResourceID=await this._application.getResourceID()),await this.initAttach()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}isScreenVariation(){var t;return!!(null===(t=this._appResourceID)||void 0===t?void 0:t.includes("__"))}getGridLegacyConfigName(){if(!this.isScreenVariation())return this.gridLegacyConfigName?this.gridLegacyConfigName:this.entityName?"GrdCfgHtml5:grdcfg.dynaform.anexo."+this.entityName:this.entityName}render(){var t,i;return s("ez-popup",{ref:t=>this._refPopup=t,size:"x-large",ezTitle:this.getMessage("snkAttach.title"),useHeader:!1,autoClose:!1,onEzClosePopup:()=>this.close()},this._isOpen&&this._currentDataUnit&&s("main",{class:"snk-attach__main"},s("header",{class:"snk-attach__header"},s("section",null,s("ez-button",{class:"ez-padding-right--medium",title:this.getMessage("snkSimpleBar.backTitle"),mode:"icon",iconName:"arrow_back",size:"medium",onClick:()=>this.handleBack()}),s("div",{class:"snk-attach__file-info"},s("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold"},this.getMessage("snkAttach.title")),s("span",{class:"ez-text ez-text--medium ez-text--secondary"},this.getMessage("snkAttach.description")))),s("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})),s("div",{class:"snk-attach__crud-section"},s("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:gt(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this),multipleSelection:!0,configName:this.isScreenVariation()?void 0:this.entityName?"AnexoSistema_"+this.entityName:void 0,ignoreReadOnlyFormFields:!!this.entityName,gridLegacyConfigName:this.getGridLegacyConfigName(),outlineMode:!0}))))}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};kt.style=".snk-attach__header.sc-snk-attach{display:flex;justify-content:space-between;align-items:center;margin-bottom:var(--space--6, 6px)}.snk-attach__header.sc-snk-attach>section.sc-snk-attach{display:flex;align-items:center}.snk-attach__file-info.sc-snk-attach{display:flex;flex-direction:column;justify-content:center;gap:var(--space--8, 8px)}.snk-attach__main.sc-snk-attach{display:flex;flex-direction:column;height:100%}.ez-box__container.sc-snk-attach{height:100%}.snk-attach__crud-section.sc-snk-attach{padding:1px;display:flex;flex-direction:column;height:100%;width:100%}";const _t=class{constructor(s){t(this,s),this.actionSelected=i(this,"actionSelected",7),this.OFFSET_HEIGHT=5,this.getMessage=void 0,this.hasDefaultFilter=!1,this._opened=!1}repositionDropDown(){if(!this._refIcon||!this._refDropdown)return;const t=this._refIcon.getBoundingClientRect(),i=this._refDropdown.getBoundingClientRect();this._refDropdown.style.top=t.y+t.height+this.OFFSET_HEIGHT+"px",this._refDropdown.style.left=t.x+t.width/2-i.width+"px"}toggleDropdown(){this._opened=!this._opened}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest("#dropdown-parent-demo")||(this._opened=!1))}buildItems(){return[{id:F.EDIT,label:this.getMessage("defaultFilter.edit")},{id:F.REMOVE,label:this.getMessage("defaultFilter.remove")}]}onValueSelected({detail:t}){this._opened=!1,this.actionSelected.emit(t.id)}openCreateNewFilter(){this.actionSelected.emit(F.CREATE)}componentDidRender(){this.repositionDropDown()}componentWillLoad(){this._items=this.buildItems(),document.removeEventListener("scroll",this.repositionDropDown.bind(this)),document.addEventListener("scroll",this.repositionDropDown.bind(this))}render(){return this.hasDefaultFilter?s(e,null,s("button",{class:"default_container",onClick:this.toggleDropdown.bind(this)},s("span",null,this.getMessage("defaultFilter.title")),s("ez-icon",{ref:t=>this._refIcon=t,iconName:"dots-vertical"})),this._opened&&s("ez-dropdown",{ref:t=>this._refDropdown=t,items:this._items,onEzClick:this.onValueSelected.bind(this),onEzOutsideClick:this.closeDropdown.bind(this)})):s(e,null,s("button",{class:"default_container new_filter",onClick:this.openCreateNewFilter.bind(this)},s("span",null,this.getMessage("defaultFilter.create"))))}};_t.style=".sc-snk-default-filter-h{display:flex;justify-content:flex-end}.default_container.sc-snk-default-filter{border:none;background:none;display:flex;align-items:center;gap:var(--space--3xs, 4px);font-family:var(--font-pattern);color:var(--title--primary, #2b3a54);font-size:var(--text--medium, 14px);padding:0;outline:none}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter{cursor:pointer}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter:hover{color:var(--color--primary-600)}.new_filter.sc-snk-default-filter{cursor:pointer;margin:0 var(--space--3xs, 4px)}.new_filter.sc-snk-default-filter:hover{color:var(--color--primary-600)}";const yt=class{constructor(e){t(this,e),this.snkContentCardChanged=i(this,"snkContentCardChanged",7),this.snkRequestClearFieldToFocus=i(this,"snkRequestClearFieldToFocus",7),this._customEditors=new Map,this._fieldProps=new Map,this.dataUnitObserver=async t=>{var i;if(t.type===l.RECORDS_COPIED){const s=this.buildSourceRecordPK(t);null===(i=this.getImageField())||void 0===i||i.forEach((async t=>{var i;null===(i=this.dataUnit)||void 0===i||i.setFieldValue(t.name,JSON.stringify(s))}))}},this.customUiBuilders=new Map([[h.IMAGE,t=>{var{name:i}=t,e=function(t,i){var s={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&i.indexOf(e)<0&&(s[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)i.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(s[e[n]]=t[e[n]])}return s}(t,["name"]);return s("snk-image-input",Object.assign({dataUnit:this.dataUnit,maxSize:1/0,fieldName:i,entityName:this.entityPath},e))}]]),this._singleColumn=!1,this._currentFormLayout=void 0,this.fieldSearch=void 0,this.label=void 0,this.name=void 0,this.fields=void 0,this.formMetadata=void 0,this.dataUnit=void 0,this.recordsValidator=void 0,this.fieldToFocus=void 0,this.customEditors=void 0,this.fieldsProps=void 0,this.entityPath=void 0}async showUp(){var t,i;this._formView&&(null===(i=(t=this._formView).showUp)||void 0===i||i.call(t))}async addCustomEditor(t,i,s){var e,n;if(this._formView)return void(null===(n=(e=this._formView).addCustomEditor)||void 0===n||n.call(e,t,i,s));const a=new Map(this._customEditors);a.set(t,{customEditor:i,detailContext:null!=s?s:""}),this._customEditors=a}async setFieldProp(t,i,s){const e=this._fieldProps.get(t)||[];this._fieldProps.set(t,[...e,{propName:i,value:s}])}async showSearchField(){if(!this._headerContainer||!this._ezPopoverFieldColumn)return;const t=this._headerContainer.getBoundingClientRect();this.fieldSearch&&(await E(this.fieldSearch),this._ezPopoverFieldColumn.showUnder(this._headerContainer,{horizontalGap:t.width-P,verticalGap:-1*t.height}))}observePropsCustomEditor(t){for(const i in t)this.addCustomEditor(i,t[i])}async observeFieldsProps(t){for(const i in t){const s=t[i],e=Object.keys(s);for(const t of e)await this.setFieldProp(i,t,s[t])}}async observeDataUnit(t,i){t!==i&&t&&t.subscribe(this.dataUnitObserver)}bindFields(t){var i;null==this._dataBinder&&null!=this.dataUnit&&(this._dataBinder=new j(this.dataUnit)),this._dataBinder&&this.dataUnit&&this.formMetadata&&this._dataBinder.bind(t,null===(i=this.dataUnit)||void 0===i?void 0:i.dataUnitId,this.formMetadata,this.recordsValidator)}disconnectedCallback(){null!=this._dataBinder&&this._dataBinder.onDisconnectedCallback(),this.dataUnit&&this.dataUnit.unsubscribe(this.dataUnitObserver)}componentDidLoad(){this.customEditors&&this.observePropsCustomEditor(this.customEditors),this.fieldsProps&&this.observeFieldsProps(this.fieldsProps),this.initLayoutFormConfig()}async initLayoutFormConfig(){const t=o.getContextValue("__SNK__APPLICATION__"),i=await(null==t?void 0:t.getLayoutFormConfig());i&&(this.setSingleColumn(i),this.registerNotifyListeners(i))}setSingleColumn(t){this._singleColumn=(null==t?void 0:t.config)===N.CASCADE||(null==t?void 0:t.config)===N.CLASSIC_CASCADE,this._currentFormLayout=null==t?void 0:t.config}registerNotifyListeners(t){var i;t&&(null===(i=t.onConfigChange)||void 0===i||i.call(t,(t=>{this._singleColumn=t===N.CASCADE||t===N.CLASSIC_CASCADE,this._currentFormLayout=t})))}componentDidRender(){var t;this.setCustomEditors(),this.setFieldProps(),this.fieldToFocus&&(null===(t=this.fields)||void 0===t?void 0:t.some((t=>t.name===this.fieldToFocus)))&&requestAnimationFrame((()=>{var t,i;null===(t=this._dataBinder)||void 0===t||t.setFocus(this.fieldToFocus),null===(i=this.snkRequestClearFieldToFocus)||void 0===i||i.emit()}))}setCustomEditors(){var t,i;if(this._formView)for(const[s,e]of this._customEditors)null===(i=(t=this._formView).addCustomEditor)||void 0===i||i.call(t,s,e.customEditor,e.detailContext),this._customEditors.delete(s)}setFieldProps(){if(this._formView)for(const[t,i]of this._fieldProps)i.forEach((i=>{var s,e;null===(e=(s=this._formView).setFieldProp)||void 0===e||e.call(s,t,i.propName,i.value),this._fieldProps.delete(t)}))}buildSourceRecordPK(t){var i,s,e;const n=(null===(i=t.payload)||void 0===i?void 0:i[0])||{},a=JSON.parse(atob(n.__record__source__id__||""));if(delete a.__DATA_UNIT_NAME__,!this.dataUnit)return{};const o=null!==(s=R(this.dataUnit))&&void 0!==s?s:{},r=Object.keys(o),l={};for(const t of r)l[t]=null===(e=a[t])||void 0===e?void 0:e.value;return l}getImageField(){var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.metadata.fields.filter((t=>t.userInterface===h.IMAGE))}render(){return s(e,null,s("slot",null),s("ez-form-view",{ref:t=>this._formView=t,fields:this.fields,onEzContentReady:t=>this.bindFields(t.detail),singleColumn:this._singleColumn,customUiBuilders:this.customUiBuilders,formLayout:this._currentFormLayout}),this.fieldSearch&&s("ez-popover",{ref:t=>this._ezPopoverFieldColumn=t,overlayType:"none"},this.fieldSearch))}static get watchers(){return{customEditors:["observePropsCustomEditor"],fieldsProps:["observeFieldsProps"],dataUnit:["observeDataUnit"]}}};yt.style=".sc-snk-dynaform-form-view-h{display:flex;flex-direction:column;width:100%;flex-wrap:wrap;background-color:var(--background--xlight);padding:var(--space--12, 12px);border-radius:var(--border--radius-medium);border:1px solid var(--color--petroleum-100, #C8CCD3);--ez-form-card-summary-field-content-weight:700}ez-form-view.sc-snk-dynaform-form-view{padding:var(--space--6 ,6px) 0;--ez-form-view__item--padding:0}.level-path.sc-snk-dynaform-form-view{color:var(--color--title-primary, #2B3A54);font-weight:var(--text-weight--medium, 400);padding-right:3px}.summary-wrapper.sc-snk-dynaform-form-view{display:flex;overflow:hidden}.summary-header.sc-snk-dynaform-form-view{border-bottom:1px solid var(--color--strokes);margin-bottom:var(--space--medium);padding-bottom:var(--space--medium)}.summary-container.sc-snk-dynaform-form-view{display:flex;flex-direction:column}.summary-container.sc-snk-dynaform-form-view{padding-right:calc(var(--space--extra-large) / 1.5)}.summary-field.sc-snk-dynaform-form-view{min-width:30px;max-width:200px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.summary-field__title.sc-snk-dynaform-form-view{color:var(--text--primary, #626e82);font-size:var(--title--small);white-space:nowrap;font-weight:var(--text-weight--medium)}.summary-field__content.sc-snk-dynaform-form-view{color:var(--title--primary, #2b3a54);font-size:var(--text--large);font-weight:var(--ez-form-card-summary-field-content-weight)}";const wt=class{constructor(s){t(this,s),this.ezExpressionChange=i(this,"ezExpressionChange",7),this.filterAssistent=void 0,this.application=void 0}getMessage(t,i){return this.application.messagesBuilder.getMessage(t,i)}render(){var t;return s(e,null,s("span",{class:"ez-title ez-title--small ez-padding-bottom--small snk-filter-advanced-mode__title"},this.getMessage("snkPersonalizedFilter.info.applyExpression")),s("ez-text-area",{rows:9,label:this.getMessage("snkPersonalizedFilter.info.labelExpression"),value:null===(t=this.filterAssistent)||void 0===t?void 0:t.expression,onEzChange:t=>this.ezExpressionChange.emit(t.detail)}))}};wt.style=".sc-snk-filter-advanced-mode-h{display:block;--snk-personalized-filter--title--color:var(--title--primary, #2B3A54)}.snk-filter-advanced-mode__title.sc-snk-filter-advanced-mode{color:var(--snk-personalized-filter--title--color)}";const Ct=class{constructor(s){t(this,s),this.ezChangeFilter=i(this,"ezChangeFilter",7),this.filterAssistent=void 0,this.messagesBuilder=void 0,this.filterId=void 0,this.entityUri=void 0,this.application=void 0,this.isDefaultFilter=!1}getMessage(t,i){return this.application.messagesBuilder.getMessage(t,i)}async handleFilterGroupChange(){const t=await this._mainExpressionGroup.getExpressionGroup();this.filterAssistent=Object.assign(Object.assign({},this.filterAssistent),{assistent:t}),this.filterAssistent.parameters=K.buildVariableParameters(this.filterAssistent.assistent),this.filterAssistent.expression=K.buildGroupExpression(this.filterAssistent.assistent),this.ezChangeFilter.emit(this.filterAssistent)}render(){var t,i;return s(e,null,s("div",{class:"ez-padding-top--small snk-personalized-filter__group"},s("snk-expression-group",{ref:t=>this._mainExpressionGroup=t,group:null===(t=this.filterAssistent)||void 0===t?void 0:t.assistent,messagesBuilder:this.messagesBuilder,onEzFilterGroupChange:this.handleFilterGroupChange.bind(this),filterId:this.filterId,entityURI:this.entityUri,isDefaultFilter:this.isDefaultFilter})),s("div",{class:"ez-margin-top--auto"},s("div",{class:"snk-personalized-filter__expression-input--line"}),s("ez-collapsible-box",{label:this.getMessage("snkPersonalizedFilter.info.titleCollapsible"),headerSize:"medium",value:!0},s("div",{class:"ez-box"},s("div",{class:"ez-box__container--external"},s("div",{class:"ez-box__container--internal"},s("span",{class:"ez-box__container--title"},this.getMessage("snkPersonalizedFilter.info.labelExpression")),s("span",{class:"ez-box__container--expression"},null===(i=this.filterAssistent)||void 0===i?void 0:i.expression)))))))}};Ct.style=".sc-snk-filter-assistent-mode-h{display:flex;flex-direction:column;height:100%;--text-area--font-family:var(--font-pattern, Arial);--text-area__label--floating--top:var(--space--small, 6px);--snk-filter-assistent-mode__container--border-radius:var(--border--radius-medium, 12px);--snk-filter-assistent-mode__container--background:var(--background--medium, #f0f3f7);--snk-filter-assistent-mode__container--margin:var(--space--small, 6px) var(--space--medium, 12px)}.ez-box__container--external.sc-snk-filter-assistent-mode{height:100px;width:100%;overflow-y:auto;background-color:var(--snk-filter-assistent-mode__container--background);border-radius:var(--snk-filter-assistent-mode__container--border-radius)}.ez-box__container--internal.sc-snk-filter-assistent-mode{margin:var(--snk-filter-assistent-mode__container--margin)}.ez-box__container--title.sc-snk-filter-assistent-mode{display:block;user-select:none;font-family:var(--text-area--font-family);font-size:var(--text--extra-small);color:var(--title--primary);top:var(--text-area__label--floating--top)}.ez-box__container--expression.sc-snk-filter-assistent-mode{display:block;font-family:var(--text-area--font-family);font-size:var(--text--medium);color:var(--title--primary);top:var(--text-area__label--floating--top)}.snk-personalized-filter__expression-input--line.sc-snk-filter-assistent-mode{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}";const zt=class{constructor(s){t(this,s),this.filterChange=i(this,"filterChange",7),this.config=void 0,this.getMessage=void 0,this.showHardFixed=!0,this.removalBlocked=!1}async setFocusField(){var t,i,s,e;this._editor&&(this._editor.setFocus?null===(i=null===(t=this._editor)||void 0===t?void 0:t.setFocus)||void 0===i||i.call(t):this._editor.focus&&(null===(e=null===(s=this._editor)||void 0===s?void 0:s.focus)||void 0===e||e.call(s)))}async clearValue(){this._editor&&this._editor.clearValue&&await this._editor.clearValue()}observeConfig(t){var i,s;this._editor&&(this._editor.config=t),null===(s=null===(i=this._editor)||void 0===i?void 0:i.reloadList)||void 0===s||s.call(i),this._customElementObject=this.getContentEditor()}componentDidLoad(){if(this._element){v.addIDInfo(this._element);const t=this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME);this._idContentEditor=`${t}_${this.config.id}`}}changeConfig(t){this.filterChange.emit(t)}getContentEditor(){switch(this.config.type){case C.BINARY_SELECT:return{tag:"snk-filter-binary-select"};case C.MULTI_SELECT:return{tag:"snk-filter-multi-select"};case C.PERIOD:return{tag:"snk-filter-period"};case C.SEARCH:return{tag:"snk-filter-search"};case C.NUMBER:return{tag:"snk-filter-number"};case C.PERSONALIZED:return{tag:"snk-personalized-filter-editor",props:{presentationMode:q.CHIP,onValueChanged:t=>this.handleValueChanged(t)}};case C.CHECK_BOX_LIST:return{tag:"snk-filter-checkbox-list",props:{onValueChanged:t=>this.config=Object.assign(Object.assign({},this.config),{value:t.detail})}};case C.MULTI_LIST:return{tag:"snk-entity-list",props:{onValueChanged:t=>this.config=Object.assign(Object.assign({},this.config),{value:t.detail})}}}return{tag:"snk-filter-text"}}handleValueChanged({detail:t}){const i=(null==t?void 0:t.items)||this.config.groupedItems;this.config=Object.assign(Object.assign({},this.config),{groupedItems:i,visible:(i||[]).filter((t=>t.visible)).length>0})}removeItem(){const t=this.config.type===C.MULTI_LIST&&Array.isArray(this.config.value)?this.config.value.map((t=>Object.assign(Object.assign({},t),{check:!1}))):void 0,i=Object.assign(Object.assign({},this.config),{visible:!1,fixed:!1,value:t});null!=i.groupedItems&&(i.groupedItems=i.groupedItems.map((t=>Object.assign(Object.assign({},t),{visible:!1,fixed:!1,value:void 0})))),this.changeConfig(i)}removeItemFromGroup(t){return Object.assign(Object.assign({},t),{visible:!1,fixed:!1,value:void 0})}getPopUpHeaderButtons(){return s(n,null,!this.removalBlocked&&!this.config.removalBlocked&&this.buildIcon(this.getMessage("snkFilterBar.removeFilter"),"delete",(()=>this.removeItem())),this.showHardFixed&&!this.config.hardFixed&&this.buildIcon(this.getMessage(this.config.fixed?"snkFilterBar.unpinFilter":"snkFilterBar.pinFilter"),this.config.fixed?"un-pin":"push-pin",(()=>this.changeConfig(Object.assign(Object.assign({},this.config),{fixed:!this.config.fixed})))))}buildIcon(t,i,e){return s("button",{onClick:()=>e(),class:"sc-snk-filter-bar snk-filter-item__editor-header-button",ref:i=>i&&this.buildIdButton(i,t)},s("ez-icon",Object.assign({title:t,iconName:i},{[v.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${v.getInternalIDInfo(`_${t}`)}`})))}buildIdButton(t,i){if(!t)return;const s={id:i};t.removeAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME),v.addIDInfoIfNotExists(t,"button",s)}clearBinarySelectValues(){var t;const i=this._editor||{};null===(t=i.resetValues)||void 0===t||t.call(i),this.config=m.copy(this.originalConfig),this.changeConfig(Object.assign(Object.assign({},this.config),{value:void 0}))}apply(){if(!K.validateVariableValues(this.config,this._editor.value))return T.alert(this.getMessage("snkFilterBar.filterModal.validations.notFullFilled.title"),this.getMessage("snkFilterBar.filterModal.validations.notFullFilled.message"));const t=void 0!==this._editor.value?this._editor.value:this.config.value;this.changeConfig(Object.assign(Object.assign({},this.config),{visible:this.isVisible(),value:t}))}isVisible(){return!(this.config.groupedItems&&this.config.groupedItems.length>0)||this.config.groupedItems.filter((t=>t.visible)).length>0}clear(){var t;if(this.config.type!==C.BINARY_SELECT){if(C.MULTI_LIST===this.config.type){const i=m.copy(this.config);return null===(t=i.value)||void 0===t||t.forEach((t=>!!t&&(t.check=!1))),void(this.config=m.copy(i))}this.changeConfig(Object.assign(Object.assign({},this.config),{value:void 0}))}else this.clearBinarySelectValues()}filterCanBeCleared(){return this.config.type!==C.PERSONALIZED}onKeyDonwListener(t){"Enter"===t.key&&this.apply()}buildRightSlot(t){return s("ez-icon",{iconName:"delete",onClick:()=>this.removeValueFromConfig(t)})}removeValueFromConfig(t){var i,s;if(this.config){const e=m.copy(this.config),n=null===(i=e.value)||void 0===i?void 0:i.findIndex((i=>(null==i?void 0:i.id)===t.id));null===(s=e.value)||void 0===s||s.splice(n,1),this.config=m.copy(e)}}componentWillLoad(){this.originalConfig=m.copy(this.config),this._customElementObject=this.getContentEditor()}render(){const{tag:t,props:i}=this._customElementObject;return s(e,null,s("div",{class:"col ez-col--sd-12 ez-align--right ez-padding-medium ez-flex--align-items-center"},s("div",{class:"ez-text ez-title ez-title--small ez-padding--small sc-snk-filter-bar snk-filter-item__editor-header"},this.config.detailTitle),this.getPopUpHeaderButtons()),s(t,Object.assign({maxHeightList:"240px",ref:t=>this._editor=t,value:this.config.value,config:this.config,onKeyDown:t=>this.onKeyDonwListener(t),"data-element-id":this._idContentEditor,getMessage:this.getMessage,rightListSlotBuilder:t=>this.buildRightSlot(t)},i)),s("hr",{class:"sc-snk-filter-bar snk-filter__popover-rule"}),s("div",{class:"ez-col ez-col--sd-12 ez-align--right"},this.filterCanBeCleared()&&s("ez-button",{label:this.getMessage("snkFilterBar.cleanFilter"),onClick:()=>this.clear(),size:"small"}),s("ez-button",{ref:t=>this._applyButton=t,label:this.getMessage("snkFilterBar.applyFilter"),onClick:()=>this.apply(),size:"small",class:"ez-button--primary ez-padding-left--medium"})))}get _element(){return a(this)}static get watchers(){return{config:["observeConfig"]}}},At=class{constructor(s){t(this,s),this.filterChange=i(this,"filterChange",7),this.editPersonalizedFilter=i(this,"editPersonalizedFilter",7),this.addPersonalizedFilter=i(this,"addPersonalizedFilter",7),this.filterItem=void 0,this.configName=void 0,this.resourceID=void 0}getContentEditorConfig(){const t={presentationMode:q.MODAL};switch(this.filterItem.type){case C.BINARY_SELECT:return{tag:"snk-filter-binary-select",props:t};case C.MULTI_SELECT:return{tag:"snk-filter-multi-select"};case C.PERIOD:return{tag:"snk-filter-period",props:t};case C.SEARCH:return{tag:"snk-filter-search"};case C.NUMBER:return{tag:"snk-filter-number",props:t};case C.PERSONALIZED:return this.buildSnkFilterPersonalizedProps();case C.CHECK_BOX_LIST:return{tag:"snk-filter-checkbox-list",props:t};case C.MULTI_LIST:return{tag:"snk-entity-list",props:{maxHeightList:"640px",rightListSlotBuilder:t=>this.buildRightSlot(t)}}}return{tag:"snk-filter-text"}}buildSnkFilterPersonalizedProps(){return{tag:"snk-personalized-filter-editor",props:{onEditFilter:t=>this.editPersonalizedFilter.emit(t.detail),onAddFilter:()=>this.addPersonalizedFilter.emit()}}}isVisible(t){return!!this.filterItem.visible||void 0!==t}updateFilterValue(t){var i,s;const e=void 0!==(null==t?void 0:t.value)?t.value:t;this.filterItem=Object.assign(Object.assign({},this.filterItem),null!=this.filterItem.groupedItems?{visible:e>0,value:e,groupedItems:t.items}:{value:this.filterItem.type===(C.SEARCH||C.CHECK_BOX_LIST)?t:e,visible:this.isVisible(e)}),this._editor&&(this._editor.config=this.filterItem),null===(s=null===(i=this._editor)||void 0===i?void 0:i.reloadList)||void 0===s||s.call(i),this.filterChange.emit(this.filterItem)}handleDeleteFilter(t,i){i===C.PERSONALIZED&&H.removePersonalizedFilter(t,this.resourceID,this.configName)}componentDidLoad(){if(this._element){v.addIDInfo(this._element);const t=this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME);this._idContentEditor=`${t}_${this.filterItem.id}`}}buildRightSlot(t){return s("ez-icon",{iconName:"delete",onClick:()=>this.removeValueFromConfig(t)})}removeValueFromConfig(t){var i,s,e;const n=null===(s=null===(i=this.filterItem)||void 0===i?void 0:i.value)||void 0===s?void 0:s.findIndex((({id:i})=>i===t.id)),a=m.copy(this.filterItem);null===(e=null==a?void 0:a.value)||void 0===e||e.splice(n,1),this.updateFilterValue(a.value)}canShowDetailModal(){const{CUSTOM_FILTER:t,OTHER_FILTERS:i}=I;return![t,i].includes(this.filterItem.filterType)&&this.filterItem.type!==C.BINARY_SELECT}render(){const{tag:t,props:i}=this.getContentEditorConfig();return s(e,null,s("div",{class:"ez-flex ez-flex--column grow"},this.canShowDetailModal()&&s("label",{class:"ez-text ez-text--medium ez-text--primary ez-margin-bottom--extra-small",htmlFor:`filter-item-${this.filterItem.id}`},this.filterItem.detailModal),s(t,Object.assign({ref:t=>this._editor=t,id:`filter-item-${this.filterItem.id}`,config:this.filterItem,value:this.filterItem.value,onValueChanged:t=>this.updateFilterValue(t.detail),"data-element-id":this._idContentEditor},i))))}get _element(){return a(this)}};At.style=".grow{flex-grow:1}.gap{gap:4px}";const xt=class{constructor(s){t(this,s),this.imageError=i(this,"imageError",7),this.dataUnitObserver=async t=>{var i;if([l.NEXT_SELECTED,l.PREVIOUS_SELECTED].includes(t.type))return void await this.loadImage();const s=(null===(i=t.payload)||void 0===i?void 0:i.selection)||[];t.type===l.SELECTION_CHANGED&&s.length>0?await this.loadImage():t.type!==l.RECORDS_ADDED?t.type!==l.EDITION_CANCELED||await this.loadImage():await this.clearImage()},this.dataUnit=void 0,this.fieldName=void 0,this.entityName=void 0,this.enabled=!0,this.acceptType=void 0,this.maxSize=void 0,this.label=void 0,this.imageValue=void 0,this.loading=!0}async reloadImage(t){await this.loadImage(t)}getMessage(t,i){return this.messagesBuilder||(this.messagesBuilder=new g),this.messagesBuilder.getMessage(t,i)}async clearImage(){var t;null===(t=this._loadAbortController)||void 0===t||t.abort(),this.imageValue=void 0}async handleImageChange(t){const i=t.detail;if(!i)return await this.clearImage(),void await this.updatedataUnitField(!0);const s=await M(i);if(this.maxSize&&s.size>1024*this.maxSize){const t=this.getMessage("snkImageInput.errorImageSize")+this.maxSize+"(KB)";return this.imageError.emit(t),void(this.application&&await this.application.error(this.getMessage("snkImageInput.errorTitle"),t))}this.imageValue=i,await U(s,this.entityName,this.fieldName),await this.updatedataUnitField()}async updatedataUnitField(t=!1){this.dataUnit&&this.dataUnit.getSelectedRecord()&&(t?await this.dataUnit.setFieldValue(this.fieldName,"deletado"):await this.dataUnit.setFieldValue(this.fieldName,`$file.session.key{${V(this.entityName,this.fieldName)}}`))}async handleImageError(t){this.imageError.emit(t.detail),this.application&&await this.application.error(this.getMessage("snkImageInput.errorTitle"),t.detail)}getPksFromDataUnit(){if(!this.dataUnit)return;const t=this.dataUnit.getSelectedRecord();if(!t)return;const i=t[this.fieldName];if(i)try{return JSON.parse(i)}catch(t){return void console.error("Error parsing PK from data unit field:",t)}}async loadImage(t){var i,s;null===(i=this._loadAbortController)||void 0===i||i.abort();const e=new AbortController;if(this._loadAbortController=e,this.loading=!0,this.dataUnit&&this.entityName){t=null!==(s=null!=t?t:this.getPksFromDataUnit())&&void 0!==s?s:R(this.dataUnit);const i=await B(t,this.fieldName,this.entityName,e.signal);if(e.signal.aborted)return;this.imageValue=i}this.loading=!1}async componentWillLoad(){this.application=o.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder||(this.messagesBuilder=new g),this.dataUnit&&this.dataUnit.subscribe(this.dataUnitObserver)}disconnectedCallback(){this.dataUnit&&this.dataUnit.unsubscribe(this.dataUnitObserver)}async componentDidLoad(){await this.loadImage()}render(){return s(e,null,s("ez-image-input",{enabled:this.enabled,label:this.label,name:this.fieldName,value:this.imageValue,maxFileSize:this.maxSize?1024*this.maxSize:void 0,accept:this.acceptType||"image/png,image/jpeg,image/gif",onEzChange:t=>this.handleImageChange(t),onEzError:t=>this.handleImageError(t),loading:this.loading}))}};xt.style=":host{display:block}";const St=class{constructor(s){t(this,s),this.ezCancel=i(this,"ezCancel",7),this.ezSave=i(this,"ezSave",7),this.ezAfterSave=i(this,"ezAfterSave",7),this._personalizedFilterFetcher=new Q,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async t=>{let i=null==t?void 0:t.uri;if(d.isEmpty(i)&&(i=this.entityUri),!this._filterMetadataStorage.has(i)){const t=await this._personalizedFilterFetcher.loadFields(i);this._filterMetadataStorage.set(i,t)}return this._filterMetadataStorage.get(i)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const t={name:"",active:!0,expression:"",parameters:[],assistent:{id:d.generateUUID(),items:[{id:d.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:G.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(t),this._originalFilterAssistent=m.copy(t),this._filterAssistent=m.copy(t)}loadFilter(t,i){null!=t&&i!=t&&null!=this.resourceID&&(t!==$.id?H.loadPersonalizedFilter(t,this.resourceID,this.configName).then((t=>{const i=this.applyDefaultValues(t);this._filterAssistent=i,this._originalFilterAssistent=m.copy(i),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):H.loadDefaultFilter(t,this.resourceID,this.configName).then((t=>{const i=this.applyDefaultValues(t);this._filterAssistent=i,this._originalFilterAssistent=m.copy(i),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var t;null==J.get(`filterFieldsDataSource.${this.entityUri}`)&&J.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=o.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(t=this._application)||void 0===t?void 0:t.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var t;null===(t=this._viewStackRef)||void 0===t||t.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME,v.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(t){t.name=$.name,t.id=$.id}getMessage(t,i){return this._application.messagesBuilder.getMessage(t,i)}async saveFilter(){let t;t=this.isDefaultFilter?await H.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await H.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,T.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const i=Object.assign(Object.assign({},t),this._filterAssistent);i.parameters=K.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=m.copy(i),this._filterAssistent=m.copy(i),this.ezAfterSave.emit()}removeFilter(){H.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!K.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:t,expression:i}=this._filterAssistent,s=t?K.buildGroupExpression(t):i;this._filterAssistent.expression=s,this.ezSave.emit(s),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?T.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((t=>{t&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:t,message:i=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return t||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),i.replace(/.*Exception: /,"")),t}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();T.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((t=>{var i;t&&(this._filterAssistent=m.copy(null!==(i=this._originalFilterAssistent)&&void 0!==i?i:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(t){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:t}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(t){return this.addLabelToItems(t),this.addFilterGroupCondition(t),t}addFilterGroupCondition(t){t.assistent&&!t.assistent.operand&&(t.assistent.operand=G.AND)}addLabelToItems(t){t.assistent&&t.assistent.items&&t.assistent.items.length>0&&t.assistent.items.forEach((i=>{if(null==i.fieldLabel){const s=(t.parameters||[]).find((t=>t.fieldName===i.fieldName));s&&(i.fieldLabel=s.label)}}))}handleExpressionChangeAdvancedMode(t){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(t){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},t)}selectField(t){if(!("name"in t))return;const i=this.buildExpression(t.entityName,t.name,t.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(i)}buildExpression(t,i,s){return s.length>0&&s.shift(),s.length>0?`${s.join("->")}->${i}`:`${t}.${i}`}onAddField(t){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),t.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(t,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return s(n,null,s("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:t=>this.onAddField(t.target)},s("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),s("snk-filter-field-search",{class:"ez-padding-left--medium",ref:t=>this._elFilterFieldSearch=t,onEzSelectFilterItem:t=>this.selectField(t.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return s("ez-view-stack",{ref:t=>this._viewStackRef=t},s("stack-item",null,this._filterAssistentMode&&s("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:t=>this.handleChangeFilterAssistentMode(t.detail),isDefaultFilter:this.isDefaultFilter})),s("stack-item",null,s("snk-filter-advanced-mode",{ref:t=>this._elAdvancedMode=t,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:t=>this.handleExpressionChangeAdvancedMode(t.detail)})))}handleModeChange(){var t,i;if(this._filterAssistentMode)T.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((t=>{if(t&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const t=K.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=t,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(t=this._filterAssistent)||void 0===t?void 0:t.expression)===(null===(i=this._originalFilterAssistent)||void 0===i?void 0:i.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const t=this._filterAssistent.expression,i=K.buildGroupExpression(this._filterAssistent.assistent);t!==i?T.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((t=>{t&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var t,i,n,a;if((null===(t=this._filterAssistent)||void 0===t?void 0:t.assistent)||!this._filterAssistentMode)return s(e,null,s("div",{class:"snk-personalized-filter"},s("div",null,s("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},s("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},s("ez-button",{label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),s("ez-button",{ref:t=>this._elButtonSave=t,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),s("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},s("div",{class:"ez-box__container"},s("div",{class:"ez-flex ez-flex--column ez-size-width--full"},s("div",{class:"ez-flex"},s("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},s("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(i=this._filterAssistent)||void 0===i?void 0:i.name,onEzChange:t=>this.handleTitleChange(t.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),s("ez-button",{ref:t=>this._elButtonMode=t,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(n=this._filterAssistent)||void 0===n?void 0:n.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(a=this._filterAssistent)||void 0===a?void 0:a.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};St.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";const Ot=class{constructor(s){t(this,s),this.clickBreadcrumbItem=i(this,"clickBreadcrumbItem",3),this.exit=i(this,"exit",3),this.label=void 0,this.breadcrumbItens=void 0,this.messagesBuilder=void 0}getMessage(t,i){var s;return this.messagesBuilder?this.messagesBuilder.getMessage(t,i):(null===(s=this._application)||void 0===s?void 0:s.messagesBuilder)?this._application.messagesBuilder.getMessage(t,i):void 0}componentDidLoad(){this._element&&(v.addIDInfo(this._element),this._application=o.getContextValue("__SNK__APPLICATION__"))}render(){return s("div",{class:"simple-bar__container ez-margin-vertical--small ez-padding--extra-small"},s("div",{class:"simple-bar__left-slot"},s("ez-button",{class:"ez-padding-right--medium",title:this.getMessage("snkSimpleBar.backTitle"),mode:"icon",iconName:"arrow_back",size:"medium",onClick:()=>this.exit.emit()}),s("div",{class:"simple-bar__column"},s("h1",{class:"ez-title ez-title--primary ez-title--extra-large"},this.label),s("ez-breadcrumb",{items:this.breadcrumbItens,onSelectedItem:({detail:t})=>this.clickBreadcrumbItem.emit(t)}))),s("div",{class:"simple-bar__right-slot"},s("slot",{name:"rightSlot"})))}get _element(){return a(this)}};Ot.style=".sc-snk-simple-bar-h{display:flex;height:100%;width:100%}.simple-bar__container.sc-snk-simple-bar{flex:1;display:flex;align-items:stretch;gap:var(--space--small)}.simple-bar__left-slot.sc-snk-simple-bar{min-width:280px;flex:1;display:flex;align-items:center}.simple-bar__right-slot.sc-snk-simple-bar{flex:1;display:flex;align-items:center;justify-content:flex-end}.simple-bar__column.sc-snk-simple-bar{flex:1;display:flex;flex-direction:column}";const Ft=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],It=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"],Et=class{constructor(s){t(this,s),this.dataStateChange=i(this,"dataStateChange",3),this.dataUnitReady=i(this,"dataUnitReady",3),this.actionClick=i(this,"actionClick",7),this.formItemsReady=i(this,"formItemsReady",7),this.configuratorSave=i(this,"configuratorSave",7),this.configuratorCancel=i(this,"configuratorCancel",7),this._multiSelectionListDataSource=new W,this._formConfigFetcher=new z,this._customEditors=new Map,this._customRenders=new Map,this._container=void 0,this._showPopUpGridConfig=!1,this._currentViewMode=A.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${d.generateUUID()}`,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=x.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this.enableContinuousInsert=!1,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.paginationCounterMode="auto",this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=!1,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.multipleEditionEnabled=!0,this.layoutFormConfig=!0,this.disableGridEdition=!1,this.autoLoad=void 0,this.outlineMode=!1}async addCustomEditor(t,i){if(this._grid&&this._form)return this._grid.addCustomEditor(t,i),void this._form.addCustomEditor(t,i);const s=new Map(this._customEditors);s.set(t,i),this._customEditors=s}async addGridCustomRender(t,i){if(this._grid)return void this._grid.addGridCustomRender(t,i);const s=new Map(this._customRenders);s.set(t,i),this._customRenders=s}async handleResourceIDChanged(t,i){d.isEmpty(t)||t!==i&&(await this.loadFormConfig(!0),await this.loadGridConfig(!0))}async addCustomValueFormatter(t,i){this._grid.addCustomValueFormatter(t,i)}async removeCustomValueFormatter(t){this._grid.removeCustomValueFormatter(t)}async setFieldProp(t,i,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(t);e.set(t,Object.assign(Object.assign({},n),{[i]:s})),this._fieldsProps=e}loadTaskbarProcessor(){const t={};t[Pt.FORM_REGULAR]=this.getButtons(!1,[O.GRID_MODE],!0),t[Pt.GRID_REGULAR]=this.getButtons(!1,[O.DATA_EXPORTER,O.FORM_MODE]),t[Pt.FORM_SELECTED]=this.getButtons(!0,[O.GRID_MODE],!0),t[Pt.GRID_SELECTED]=this.getGridSelectedButtonsCallBack.bind(this),t[Pt.FINISH_EDITION]=this.getFinishEditionButtonsCallback.bind(this),t[Pt.MULTIPLE_EDITION]=[O.CANCEL],this._taskbarProcessor=new X(t)}getGridSelectedButtonsCallBack(){var t,i,s;return this.multipleEditionEnabled&&1!==(null===(s=null===(i=null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)||void 0===i?void 0:i.records)||void 0===s?void 0:s.length)?this.getButtons(!0,[O.UPDATE_MULTIPLE,O.DATA_EXPORTER,O.FORM_MODE]):this.getButtons(!0,[O.DATA_EXPORTER,O.FORM_MODE])}getFinishEditionButtonsCallback(){const t=[O.CANCEL,O.SAVE];return this.enableGridInsert&&this._currentViewMode!==A.ATTACHMENT&&t.push(this._currentViewMode===A.GRID?O.FORM_MODE:O.GRID_MODE),t}getButtons(t,i,s){let e=t?It:Ft;return(s||this.mode===x.IN_MEMORY)&&(e=e.filter((t=>t!==O.REFRESH))),this.addConfigButton(e.concat(i))}addConfigButton(t){return void 0===this.configName||this.configName&&this.gridLegacyConfigName?t:t.concat(O.CONFIGURATOR)}get application(){return o.getContextValue("__SNK__APPLICATION__")}async goToView(t){this._currentViewMode=t,this._viewStack&&(t===A.GRID&&(this.dataUnit.isMultipleEdition=!1),this._viewStack.show(t)),t===A.GRID&&requestAnimationFrame((()=>this.focusToGrid())),t===A.FORM&&requestAnimationFrame((()=>this.focusToForm()))}actionClickListener(t){this.handleTaskbarAction(t.detail),t.stopPropagation()}handleTaskbarAction(t){switch(t){case O.CONFIGURATOR:this._snkConfigurator.open();break;case O.GRID_MODE:this.goToView(A.GRID);break;case O.FORM_MODE:this.goToView(A.FORM);break;case O.UPDATE_MULTIPLE:this.dataUnit.isMultipleEdition=!0,this.goToView(A.FORM)}}async onChangeEntityName(t){if(this.dataUnit)return;const i=o.getContextValue("__SNK__APPLICATION__");this.dataUnit=await i.getDataUnit(t,null,null,this.configName)}onModeChange(){this.mode==x.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(t,i){this.handleDataStateChange(t,i)}async observeFormLegacy(t,i){await this.handleUpdateFormLegacyConfig(t,i)}async observeGridLegacy(t,i){await this.handleUpdateGridLegacyConfig(t,i)}async handleDataStateChange(t,i){m.objectToString(i)!=m.objectToString(t)&&this.dataStateChange.emit(t),await this.processRmPrecision()}async processRmPrecision(){var t,i;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(i=null===(t=this.dataState)||void 0===t?void 0:t.rowMetadata)||void 0===i?void 0:i.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(t,i){null!=t&&t!=i&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(t,i){null!=t&&t!=i&&this._formConfigAlreadyLoaded&&await this.loadFormConfig(!0)}async openConfig(t){await this._snkConfigurator.close(),t===A.GRID?await this.openGridConfig():t===A.FORM&&await this.openFormConfig()}async openGridConfig(){var t,i,s,e;const n=null!==(i=await(null===(t=this._grid)||void 0===t?void 0:t.getColumns()))&&void 0!==i?i:[],a=null!==(e=await(null===(s=this._grid)||void 0===s?void 0:s.getColumnsState()))&&void 0!==e?e:[];this._snkGridConfig.columns=a.filter((t=>t.name)),this._snkGridConfig.originalColumns=n.filter((t=>t.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}async openFormConfig(){(this.formLegacyConfigName||this.configName)&&await this._snkSimpleFormConfig.show()}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&H.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(t){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||t))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((t,i)=>{H.loadGridConfig(this.configName,this.resolveResourceID()).then((i=>{this.setGridConfig(i),t()})).catch((t=>{i(t)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(t=!1,i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!t)return;this._formConfigAlreadyLoaded=!0;let s=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=s)return this._formConfigManager.setConfig(s),void this.setFormConfig(s,i);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this.loadTaskbarProcessor(),this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),await this.loadGridConfig(),await this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new Y,this._continuousInsertUtils=new st(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((t=>this.enableContinuousInsert=t))}componentDidLoad(){L.applyVarsGrid(this._element,this._grid),this.initKeyboardManager(),this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}async dataUnitActionHandler(t){t.type!==l.EDITION_CANCELED&&t.type!==l.DATA_SAVED||this.dataUnit.isMultipleEdition&&this.goToView(A.GRID)}getMessage(t,i){var s;return null===(s=this.messagesBuilder)||void 0===s?void 0:s.getMessage(t,i)}disconnectedCallback(){var t;null===(t=this._keyboardManager)||void 0===t||t.unbindAllShortcutKeys()}setCustomRenders(){if(this._grid)for(const[t,i]of this._customRenders)this._grid.addGridCustomRender(t,i),this._customRenders.delete(t)}setCustomEditors(){if(this._grid&&this._form)for(const[t,i]of this._customEditors)this._grid.addCustomEditor(t,i),this._form.addCustomEditor(t,i),this._customEditors.delete(t)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[t,i]of this._fieldsProps){for(const s in i)this._form.setFieldProp(t,s,i[s]);this._fieldsProps.delete(t)}}getTaskBarId(){var t,i;return(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?Pt.FINISH_EDITION:this.dataUnit.isMultipleEdition?Pt.MULTIPLE_EDITION:(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===A.GRID?Pt.GRID_SELECTED:Pt.FORM_SELECTED:this._currentViewMode===A.GRID?Pt.GRID_REGULAR:Pt.FORM_REGULAR}initInMemoryDataUnit(){this._inMemoryLoader=new w(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(t){return this._inMemoryLoader?this._inMemoryLoader.metadata=t:this.dataUnit&&(this.dataUnit.metadata=t),Promise.resolve()}setRecords(t){return this._inMemoryLoader?this._inMemoryLoader.records=t:this.dataUnit&&(this.dataUnit.records=t),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.open()}async closeConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const t=this._element.querySelectorAll("snk-field-metadata"),i=[],s={fields:[],emptyConfig:!1};t.forEach((t=>{const e={name:t.getAttribute("name")||t.getAttribute("label"),label:t.getAttribute("label"),dataType:r[t.getAttribute("dataType")]||r.TEXT,userInterface:h[t.getAttribute("userInterface")]||h.SHORTTEXT,readOnly:"true"==t.getAttribute("readOnly"),required:"true"==t.getAttribute("required"),tab:t.getAttribute("tab")||void 0,visible:"false"!=t.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),i.push(e)})),i.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:i})}addGridCustomValueFormattters(){var t,i,s;const e=(null===(t=this._metadata)||void 0===t?void 0:t.fields)||(null===(s=null===(i=this.dataUnit)||void 0===i?void 0:i.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rm_precision)&&!n.includes(t.name)&&n.push(t.name)})),n.forEach((t=>{this.addCustomValueFormatter(t,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(t){this.dataState=Object.assign({},t.detail)}getTaskBarDisabledButtons(){var t,i,s,e,n,a;const o=[];return(null===(t=this.dataState)||void 0===t?void 0:t.hasNext)||o.push(O.NEXT),(null===(i=this.dataState)||void 0===i?void 0:i.hasPrevious)||o.push(O.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&o.push(O.FORM_MODE),(null===(a=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===a?void 0:a.length)>1&&o.push(O.CLONE),o}handleCancelEdit(){var t;(null===(t=this.dataState)||void 0===t?void 0:t.recordsIsEmpty)&&(this.goToView(A.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(t,i){t.stopImmediatePropagation(),"SAVE"!==i?this.configuratorCancel.emit():this.configuratorSave.emit()}onSelectField(t){null!=t&&(this._fieldToGetFocus=t.value)}getFieldSearch(t,i){return null!=this._fieldSearch||(this._splitButtonForm=t,this._fieldSearch=D(i,(({argument:t})=>this.fieldsOptionLoader(t)),(t=>this.onSelectField(t)))),this._fieldSearch}getFormFields(){var t,i;return null!==(i=null===(t=this.formConfig)||void 0===t?void 0:t.fields)&&void 0!==i?i:this._formFields}handleFormSetFields(t){m.equals(this._formFields,t)||(this._formFields=null!=t?t:[])}fieldsOptionLoader(t){const i=null==t?void 0:t.toLowerCase(),s=this.getFormFields().map((t=>{var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getField(t.name)})).filter((t=>{var s,e;return(null===(s=t.name)||void 0===s?void 0:s.toLowerCase().includes(i))||(null===(e=t.label)||void 0===e?void 0:e.toLowerCase().includes(i))})).map((t=>({value:t.name,label:t.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getColumnSearch(t,i){return null!=this._columnSearch||(this._splitButton=t,this._columnSearch=D(i,(({argument:t})=>new Promise((i=>{this._grid.filterColumns(t).then((t=>{i(t.filter((t=>!t.hidden)).map((t=>({label:t.label,value:t.name}))))}))}))),(t=>{null!=t&&this._grid.locateColumn(t.value)}))),this._columnSearch}getActionsList(){const t=[];if(this.enableGridInsert&&t.push(this._continuousInsertUtils.actionContinuousInsert(this.enableContinuousInsert,(()=>{this.enableContinuousInsert=!this.enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this.enableContinuousInsert)}))),this.isGridInsertActive())return t;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return t.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return t.concat(this.actionsList)}getSettingsListGrid(){return[{value:d.generateUUID(),label:this.getMessage("snkSimpleCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(t,i)=>this.getColumnSearch(t,i)}]}getSettingsListForm(){return[{value:d.generateUUID(),label:this.getMessage("snkSimpleCrud.findFields"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(t,i)=>this.getFieldSearch(t,i)}]}getTopTaskBarId(){var t;return(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?`snkGridTopTaskbar.finish_edition${k.PRIMARY}`:`snkGridTopTaskbar.regular${k.PRIMARY}`}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}gridConfigChangeHandler(t){t.stopPropagation(),this.configName&&H.saveGridConfig(t.detail,this.configName,this.resolveResourceID())}modalConfigChangeHandler(t){const i=t.detail;this._grid.setColumnsState(i.columns).then((()=>{this.setGridConfig(i),this.closeGridConfig(),this.dataExporterProviderStore()})),t.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const t=new tt(this.dataUnit,this._grid);J.set("exporterProviders",Object.assign(Object.assign({},J.get("exporterProviders")),{[this.getDataExporterStoreKey()]:t}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(t){this.gridConfig=t,Z.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(t,i){this.formConfig&&!i||(this.formConfig=t)}closeGridConfig(){this._showPopUpGridConfig=!1}getPageSize(){return this.mode===x.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}resolveResourceID(){return d.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var t;const i=null===(t=this._formConfigManager)||void 0===t?void 0:t.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||i?i:this.formConfig}updateFormConfig(){let t=this.formConfig;null==this.formLegacyConfigName&&(t=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields})),this.setFormConfig(t,!0),null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(A.FORM)}async initKeyboardManager(){var t;this._keyboardManager=new f({propagate:!1,element:this._element});const i=this.dataUnit||await(null===(t=this._snkDataUnit)||void 0===t?void 0:t.getDataUnit());null!=i&&this._keyboardManager.bind("F7",(()=>i.saveData()),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.saveData"),element:this._element}).bind("F8",i.addRecord.bind(i),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.addRecord"),element:this._element}).bind("F9",i.removeSelectedRecords.bind(i),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.removeRecord"),element:this._element}).bind("Escape",(()=>{i.isDirty()&&i.cancelEdition()}),{debounceTime:1e3,description:this.getMessage("snkSimpleCrud.keyboardShortcuts.cancelAction"),element:this._element})}async handleFormConfigSaved(){await this.loadFormConfig(!0,!0)}focusToGrid(){this._grid.focus()}focusToForm(){this._form.focus()}renderTaskbarContent(t){var i;return s("snk-taskbar",{class:"ez-box--no-outline ez-box "+(this._currentViewMode===A.FORM?(this.outlineMode?"ez-box--outline":"ez-box--shadow-xsmall")+" ez-padding--small":""),dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),actionsSettingsList:t===A.GRID?this.getSettingsListGrid():this.getSettingsListForm(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:k.SECONDARY,tabindex:"0"},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}))}render(){var t;if(null!=this.dataUnit)return s("snk-data-unit",{ref:t=>this._snkDataUnit=t,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:t=>this.onDataStateChange(t),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:t=>this.dataUnitReady.emit(t.detail),onMessagesBuilderUpdated:t=>this.messagesBuilder=t.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:`ez-box ez-box--no-outline ${this.outlineMode?"ez-box--outline":"ez-box--shadow"} simple-crud__container-section`,ref:t=>this._container=t,tabindex:"0"},s("ez-view-stack",{ref:t=>this._viewStack=t,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large ez-box--no-outline",ref:t=>this._grid=t,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(A.FORM),onConfigChange:t=>this.gridConfigChangeHandler(t),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(w.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this.enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode,tabindex:"0",paginationCounterMode:this.paginationCounterMode,canEdit:!this.disableGridEdition},this.renderTaskbarContent(A.GRID),s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,this.renderTaskbarContent(A.FORM),s("ez-form",{ref:t=>this._form=t,class:"ez-margin-top--large ez-box--no-outline",dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:t=>this.handleFormSetFields(t.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),elementFocusSearchField:this._container,tabindex:"0"}),s("slot",{name:"snkSimpleCrudFormFooter"}),s("snk-simple-form-config",{ref:t=>this._snkSimpleFormConfig=t,dataUnit:this.dataUnit,onSnkConfigSaved:this.handleFormConfigSaved.bind(this),configName:null!==(t=this.formLegacyConfigName)&&void 0!==t?t:this.configName,messagesBuilder:this.messagesBuilder})),this.messagesBuilder&&s("snk-configurator",{ref:t=>this._snkConfigurator=t,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:t=>this.goToView(t.detail),onOpenConfig:t=>this.openConfig(t.detail),showActionButtons:this.showConfiguratorButtons,onSave:t=>this.handleConfiguratorEvent(t,"SAVE"),onCancel:t=>this.handleConfiguratorEvent(t,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId,layoutFormConfig:this.layoutFormConfig})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-popup",{size:"medium",heightMode:"auto",useHeader:!1,opened:this._showPopUpGridConfig,onEzClosePopup:()=>this.closeGridConfig()},s("snk-grid-config",{ref:t=>this._snkGridConfig=t,config:this.gridConfig,"data-element-id":this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:t=>this.modalConfigChangeHandler(t),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return a(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};var Pt;!function(t){t.FORM_REGULAR="snkSimpleCrudTaskbar.form_regular",t.GRID_REGULAR="snkSimpleCrudTaskbar.grid_regular",t.FORM_SELECTED="snkSimpleCrudTaskbar.form_selected",t.GRID_SELECTED="snkSimpleCrudTaskbar.grid_selected",t.FINISH_EDITION="snkSimpleCrudTaskbar.finish_edition",t.MULTIPLE_EDITION="snkSimpleCrudTaskbar.multiple_edition"}(Pt||(Pt={})),Et.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid__container--shadow--outline:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{kt as snk_attach,_t as snk_default_filter,yt as snk_dynaform_form_view,wt as snk_filter_advanced_mode,Ct as snk_filter_assistent_mode,zt as snk_filter_detail,At as snk_filter_modal_item,xt as snk_image_input,St as snk_personalized_filter,Ot as snk_simple_bar,Et as snk_simple_crud}
1
+ import{r as t,e as i,h as s,f as e,F as n,g as a}from"./p-2c9d0870.js";import{ApplicationContext as o,DataType as r,Action as l,UserInterface as h,StringUtils as d,DataUnitLoaderUtils as c,DataUnit as u,ElementIDUtils as v,ObjectUtils as m,KeyboardManager as f}from"@sankhyalabs/core";import{D as p,S as g}from"./p-10d883b0.js";import{S as b}from"./p-3190ac29.js";import{P as k}from"./p-0f3698af.js";import{P as _,D as y,I as w}from"./p-c1e168a2.js";import{F as C}from"./p-ff1990ad.js";import{F as z}from"./p-d7657667.js";import{V as A,S as x}from"./p-9019a32f.js";import{A as S}from"./p-c3bc693a.js";import{T as O}from"./p-3072136e.js";import{A as F,F as I}from"./p-0dbd53d9.js";import{focusOnFieldSerch as E,SEARCH_FIELD_FULL_WIDTH as P,FormLayout as N,ApplicationUtils as T,CSSVarsUtils as L,buildFieldSearch as D}from"@sankhyalabs/ezui/dist/collection/utils";import{DataBinder as j}from"@sankhyalabs/ezui/dist/collection/utils/form";import{g as R,b as M,s as U,a as V,d as B}from"./p-af673291.js";import{P as K,a as G,D as $}from"./p-58709cf9.js";import{E as q}from"./p-1a68fb59.js";import{C as H,P as Q}from"./p-13f91e7e.js";import{s as J}from"./p-a73b6b00.js";import{S as W,T as X,R as Y,a as Z,b as tt}from"./p-4cc1d58b.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{S as it}from"./p-8d513b64.js";import{C as st}from"./p-e5a3711f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-7dd49d15.js";import"./p-8f3f2306.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";class et{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:s,operation:e}){var n,a;const o="INSERT"==e,r=o?s:i;if(!o&&(null==s?void 0:s.DESCRICAO)&&(null==s?void 0:s.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(b.DESCRIPTION_CANNOT_BE_CHANGED);const l={anexo:{codata:o?null==s?void 0:s.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(a=null===(n=s.CAMINHO_ARQUIVO)||void 0===n?void 0:n[0])||void 0===a?void 0:a.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,e)=>{p.get().callServiceBroker("Attach.save",JSON.stringify(l)).then((e=>{var n;return i([Object.assign(Object.assign(Object.assign({},e),s),{__owner__dataunit__name__:null!==(n=this.dataUnitName)&&void 0!==n?n:t})])})).catch((t=>e(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const s=await p.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(s)}async getDownloadKey(t){var i,s,e;if("S"==t.EHARQUIVOREPOSITORIO){const e={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},n=await p.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(e));return Promise.resolve({chave:{valor:null===(s=null===(i=null==n?void 0:n.responseBody)||void 0===i?void 0:i.chave)||void 0===s?void 0:s.valor}})}const n={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},a=await p.get().callServiceBroker("Attach.view",JSON.stringify(n));return(null==a?void 0:a.chaveAnexo)?Promise.resolve({chave:{valor:null===(e=null==a?void 0:a.chaveAnexo)||void 0===e?void 0:e.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const nt="AnexoSistemaSP.salvar",at="AnexoSistemaSP.excluir",ot="AnexoSistemaSP.baixar";class rt{constructor(t,i){var s;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(b.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(b.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(s=window.workspace)||void 0===s?void 0:s.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,s;let{updatingFields:e}=t;e=Object.assign(Object.assign({},e),{NOMEARQUIVO:null===(i=e.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(e);const t=e.LINK?null:e.NOMEARQUIVO,i={serviceName:nt,requestBody:{params:{resourceID:this.resourceID,description:e.DESCRICAO,fileSelect:t?1:0,keySession:null===(s=null==t?void 0:t.properties)||void 0===s?void 0:s.fileNameTmp,nameAttach:null==t?void 0:t.name,link:e.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:e.TIPOACESSO,typeApres:e.TIPOAPRES}}},n=await p.get().callServiceBroker(nt,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},n),e),{ARQUIVOOULINK:e.LINK?e.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,s,e;let{updatingFields:n,record:a}=t;const o=t=>void 0!==n[t]?n[t]:a[t],r=o("NOMEARQUIVO"),l=null===(s=null===(i=n.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===s?void 0:s.downloadURL;n=Object.assign(Object.assign({},n),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:a.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const h=n.LINK?null:n.NOMEARQUIVO;try{this.validateFields(n);const t={serviceName:nt,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==a?void 0:a.NUATTACH,description:n.DESCRICAO,fileSelect:l?1:0,keySession:null===(e=null==h?void 0:h.properties)||void 0===e?void 0:e.fileNameTmp,keyAttach:n.CHAVEARQUIVO,nameAttach:null==h?void 0:h.name,link:n.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:n.TIPOACESSO,typeApres:n.TIPOAPRES}}},i=await p.get().callServiceBroker(nt,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),n),{ARQUIVOOULINK:n.LINK?n.LINK:null==h?void 0:h.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},e={serviceName:at,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{p.get().callServiceBroker(at,JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},e={serviceName:ot,requestBody:{paramsDown:{nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{p.get().callServiceBroker(ot,JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}}class lt{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=o.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,s){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,e)=>this.saveLoader(e,i).then((t=>(t.length&&s(),t))),t.removeLoader=(t,e)=>this.removeLoader(t,e,i).then((t=>(t.length&&s(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((s=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));s(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((s=>{var e;const n=Array.isArray(t)?t[0]:{};((null===(e=null==n?void 0:n.record)||void 0===e?void 0:e.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(n).then((t=>{s(t)})).catch((t=>t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),s([])):t.message===b.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),s([])):t.message?(this._application.error(t.title||t.name,t.message),s([])):void s([])))}))}removeLoader(t,i,s){return new Promise((e=>{const{records:n}=t.getSelectionInfo(),a=n[0];s.delete(a).then((()=>(_.removeRecords(t,[a]),e(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:r.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,s){return new Promise((e=>i.type===l.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(s.goToView(A.GRID),e(i)):e(void 0))):e(i):i.type===l.DATA_SAVED?(t.loadData(),e(i)):void e(i)))}}let ht;const dt=t=>(ht||(ht=new g),ht.getMessage(t)),ct={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:dt("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:dt("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},ut={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:dt("snkAttach.attachMetadata.lblCode"),dataType:r.TEXT},{name:"DESCRICAO",label:dt("snkAttach.attachMetadata.lblDescription"),dataType:r.TEXT,readOnly:!1},{name:"ARQUIVO",label:dt("snkAttach.attachMetadata.lblFileOrLink"),dataType:r.TEXT},{name:"USUARIO",label:dt("snkAttach.attachMetadata.lblUser"),dataType:r.TEXT},{name:"DTALTER",label:dt("snkAttach.attachMetadata.lblDate"),dataType:r.TEXT},{name:"CAMINHO_ARQUIVO",label:dt("snkAttach.attachMetadata.lblFileUpload"),dataType:r.OBJECT,userInterface:h.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:dt("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class vt{constructor(t){this.getMessage=t,this._records=[],this._application=o.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,s){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,e)=>this.saveLoader(e,i).then((t=>(t.length&&s(),t))),t.removeLoader=(t,e)=>this.removeLoader(t,e,i).then((t=>(t.length&&s(),t)))}metadataLoader(t){return Promise.resolve(ut)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},s=await this._application.getDataFetcher(),{anexos:{anexo:e=[]}}=await s.callServiceBroker("Attach.load",JSON.stringify(t)),n=[];e.forEach((t=>{n.push(Object.assign({__record__id__:d.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=n}return c.buildLoadDataResponse(this._records,t,i)}saveLoader(t,i){return new Promise((s=>{const e=Array.isArray(t)?t[0]:{};i.save(e).then(s).catch((t=>t.message===b.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),s([])):t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),s([])):t.message===b.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),s([])):t.message?(this._application.error(t.title||t.name,t.message),s([])):void s([])))}))}removeLoader(t,i,s){return new Promise((e=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(S.REMOVE).then((async n=>{n&&(await s.delete(t),e(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,s){return new Promise((e=>{var n,a,o,r,h,d;switch(i.type){case l.EDITION_CANCELED:return t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(s.goToView(A.GRID),e(i)):e(void 0))):e(i);case l.DATA_SAVED:return t.loadData(void 0,void 0,!1,null===(o=null===(a=null===(n=null==i?void 0:i.payload)||void 0===n?void 0:n.records)||void 0===a?void 0:a[0])||void 0===o?void 0:o.REGISTER_KEY),e(i);case l.RECORDS_REMOVED:return t.loadData(void 0,void 0,!1,null===(d=null===(h=null===(r=null==i?void 0:i.payload)||void 0===r?void 0:r.cachedRecords)||void 0===h?void 0:h[0])||void 0===d?void 0:d.CODATA),e(i)}e(i)}))}}let mt;const ft=t=>{var i;if(!mt){const t=o.getContextValue("__SNK__APPLICATION__");mt=null==t?void 0:t.messagesBuilder}return null===(i=null==mt?void 0:mt.getMessage)||void 0===i?void 0:i.call(mt,t,null)},pt={DOWNLOAD:{hint:ft("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:ft("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},gt=()=>{const t=[O.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,s)=>{const e=s.indexOf(O.REFRESH);if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return s.reverse();-1!==e&&s.splice(e,1);const{selectedRecord:n}=i||{},a=(null==n?void 0:n.LINK)?pt.LINK:pt.DOWNLOAD;s.splice(s.indexOf(O.DIVIDER)+1,0,O.REMOVE,a,O.DIVIDER);const o=[O.CLONE,O.DATA_EXPORTER],r=Array.from(new Set(s.filter((t=>!o.includes(t)))));return r.splice(r.indexOf(a)+1,0,O.DIVIDER),r},isEnabled:(i,s,e)=>{const n=void 0!==(null==s?void 0:s.selectedRecord);return!(t.includes(e)&&!n)}}},bt={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},kt=class{constructor(s){t(this,s),this.ezClosePopup=i(this,"ezClosePopup",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.close()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.close();this.validateAnexoSistema()&&this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.close()}))},this._isOpen=!1,this.gridLegacyConfigName=void 0,this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0,this._appResourceID=void 0}async open(){this._isOpen=!0,this._currentDataUnit||await this.initAttach(),this._refPopup&&(this._refPopup.opened=!0),this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async close(){this._isOpen=!1,this._refPopup&&(this._refPopup.opened=!1)}async registerKeyWatcher(t,i){var s;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof rt&&(this._currentFetcher.registerKey=t),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new rt(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,s,e,n;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(s=this.registerKey)||void 0===s?void 0:s.split("_").length)>1)return;await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadMetadata()),await(null===(n=this._currentDataUnit)||void 0===n?void 0:n.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error(this.getMessage("snkAttach.alertValidation.noRecordSelected.message"));t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var s;let e=!1;(null===(s=null==t?void 0:t.ARQUIVO)||void 0===s?void 0:s.endsWith(".pdf"))||(e=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${e?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;let s;this._currentDataUnit=(new y).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=this.entityName?{form:null==bt?void 0:bt.form}:Object.assign({},bt),s={grid:null==bt?void 0:bt.grid}),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm(s)}async loadAttach(){var t,i;let s;this._currentFetcher=new et,this._currentDataUnit=new u(w.IN_MEMORY_DATA_UNIT_NAME),this._currentDataUnit.pageSize=150,this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===l.METADATA_LOADED&&(this.crudConfig=this.entityName?{form:null==ct?void 0:ct.form}:Object.assign({},ct),s={grid:null==ct?void 0:ct.grid},null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=this.entityName?{form:null==ct?void 0:ct.form}:Object.assign({},ct),s={grid:null==ct?void 0:ct.grid},await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm(s))}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new lt(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new et,this._currentDataUnitBuilder=new vt(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(t){var i,s,e,n,a;const o=(null===(s=null===(i=this._crudElement)||void 0===i?void 0:i.gridConfig)||void 0===s?void 0:s.columns)||(null===(e=null==t?void 0:t.grid)||void 0===e?void 0:e.columns)||(null===(a=null===(n=this.crudConfig)||void 0===n?void 0:n.grid)||void 0===a?void 0:a.columns);this.getGridLegacyConfigName()&&this._currentDataUnit.disableField("ARQUIVOOULINK"),null==o||o.forEach((t=>{var i,s;const e=t.name;(null===(s=null===(i=this.crudConfig)||void 0===i?void 0:i.form)||void 0===s?void 0:s.fields.some((t=>(null==t?void 0:t.name)===e)))||this._currentDataUnit.disableField(e)}))}validateAnexoSistema(){var t;if(this._currentFetcher instanceof rt)try{let i=this._currentDataUnit.getSelectedRecord();i=Object.assign(Object.assign({},i),{NOMEARQUIVO:null===(t=i.NOMEARQUIVO)||void 0===t?void 0:t[0]}),this._currentFetcher.validateFields(i)}catch(t){if(t.message===b.LINK_AND_FILE_AT_THE_SAME_TIME)return this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),!1;if(t.message===b.ANY_LINK_OR_FILE_FILLED)return this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),!1}return!0}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),this._application&&(this._appResourceID=await this._application.getResourceID()),await this.initAttach()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}isScreenVariation(){var t;return!!(null===(t=this._appResourceID)||void 0===t?void 0:t.includes("__"))}getGridLegacyConfigName(){if(!this.isScreenVariation())return this.gridLegacyConfigName?this.gridLegacyConfigName:this.entityName?"GrdCfgHtml5:grdcfg.dynaform.anexo."+this.entityName:this.entityName}render(){var t,i;return s("ez-popup",{ref:t=>this._refPopup=t,size:"x-large",ezTitle:this.getMessage("snkAttach.title"),useHeader:!1,autoClose:!1,onEzClosePopup:()=>this.close()},this._isOpen&&this._currentDataUnit&&s("main",{class:"snk-attach__main"},s("header",{class:"snk-attach__header"},s("section",null,s("ez-button",{class:"ez-padding-right--medium",title:this.getMessage("snkSimpleBar.backTitle"),mode:"icon",iconName:"arrow_back",size:"medium",onClick:()=>this.handleBack()}),s("div",{class:"snk-attach__file-info"},s("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold"},this.getMessage("snkAttach.title")),s("span",{class:"ez-text ez-text--medium ez-text--secondary"},this.getMessage("snkAttach.description")))),s("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})),s("div",{class:"snk-attach__crud-section"},s("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:gt(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this),multipleSelection:!0,configName:this.isScreenVariation()?void 0:this.entityName?"AnexoSistema_"+this.entityName:void 0,ignoreReadOnlyFormFields:!!this.entityName,gridLegacyConfigName:this.getGridLegacyConfigName(),outlineMode:!0}))))}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};kt.style=".snk-attach__header.sc-snk-attach{display:flex;justify-content:space-between;align-items:center;margin-bottom:var(--space--6, 6px)}.snk-attach__header.sc-snk-attach>section.sc-snk-attach{display:flex;align-items:center}.snk-attach__file-info.sc-snk-attach{display:flex;flex-direction:column;justify-content:center;gap:var(--space--8, 8px)}.snk-attach__main.sc-snk-attach{display:flex;flex-direction:column;height:100%}.ez-box__container.sc-snk-attach{height:100%}.snk-attach__crud-section.sc-snk-attach{padding:1px;display:flex;flex-direction:column;height:100%;width:100%}";const _t=class{constructor(s){t(this,s),this.actionSelected=i(this,"actionSelected",7),this.OFFSET_HEIGHT=5,this.getMessage=void 0,this.hasDefaultFilter=!1,this._opened=!1}repositionDropDown(){if(!this._refIcon||!this._refDropdown)return;const t=this._refIcon.getBoundingClientRect(),i=this._refDropdown.getBoundingClientRect();this._refDropdown.style.top=t.y+t.height+this.OFFSET_HEIGHT+"px",this._refDropdown.style.left=t.x+t.width/2-i.width+"px"}toggleDropdown(){this._opened=!this._opened}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest("#dropdown-parent-demo")||(this._opened=!1))}buildItems(){return[{id:F.EDIT,label:this.getMessage("defaultFilter.edit")},{id:F.REMOVE,label:this.getMessage("defaultFilter.remove")}]}onValueSelected({detail:t}){this._opened=!1,this.actionSelected.emit(t.id)}openCreateNewFilter(){this.actionSelected.emit(F.CREATE)}componentDidRender(){this.repositionDropDown()}componentWillLoad(){this._items=this.buildItems(),document.removeEventListener("scroll",this.repositionDropDown.bind(this)),document.addEventListener("scroll",this.repositionDropDown.bind(this))}render(){return this.hasDefaultFilter?s(e,null,s("button",{class:"default_container",onClick:this.toggleDropdown.bind(this)},s("span",null,this.getMessage("defaultFilter.title")),s("ez-icon",{ref:t=>this._refIcon=t,iconName:"dots-vertical"})),this._opened&&s("ez-dropdown",{ref:t=>this._refDropdown=t,items:this._items,onEzClick:this.onValueSelected.bind(this),onEzOutsideClick:this.closeDropdown.bind(this)})):s(e,null,s("button",{class:"default_container new_filter",onClick:this.openCreateNewFilter.bind(this)},s("span",null,this.getMessage("defaultFilter.create"))))}};_t.style=".sc-snk-default-filter-h{display:flex;justify-content:flex-end}.default_container.sc-snk-default-filter{border:none;background:none;display:flex;align-items:center;gap:var(--space--3xs, 4px);font-family:var(--font-pattern);color:var(--title--primary, #2b3a54);font-size:var(--text--medium, 14px);padding:0;outline:none}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter{cursor:pointer}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter:hover{color:var(--color--primary-600)}.new_filter.sc-snk-default-filter{cursor:pointer;margin:0 var(--space--3xs, 4px)}.new_filter.sc-snk-default-filter:hover{color:var(--color--primary-600)}";const yt=class{constructor(e){t(this,e),this.snkContentCardChanged=i(this,"snkContentCardChanged",7),this.snkRequestClearFieldToFocus=i(this,"snkRequestClearFieldToFocus",7),this._customEditors=new Map,this._fieldProps=new Map,this.dataUnitObserver=async t=>{var i;if(t.type===l.RECORDS_COPIED){const s=this.buildSourceRecordPK(t);null===(i=this.getImageField())||void 0===i||i.forEach((async t=>{var i;null===(i=this.dataUnit)||void 0===i||i.setFieldValue(t.name,JSON.stringify(s))}))}},this.customUiBuilders=new Map([[h.IMAGE,t=>{var{name:i}=t,e=function(t,i){var s={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&i.indexOf(e)<0&&(s[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)i.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(s[e[n]]=t[e[n]])}return s}(t,["name"]);return s("snk-image-input",Object.assign({dataUnit:this.dataUnit,maxSize:1/0,fieldName:i,entityName:this.entityPath},e))}]]),this._singleColumn=!1,this._currentFormLayout=void 0,this.fieldSearch=void 0,this.label=void 0,this.name=void 0,this.fields=void 0,this.formMetadata=void 0,this.dataUnit=void 0,this.recordsValidator=void 0,this.fieldToFocus=void 0,this.customEditors=void 0,this.fieldsProps=void 0,this.entityPath=void 0}async showUp(){var t,i;this._formView&&(null===(i=(t=this._formView).showUp)||void 0===i||i.call(t))}async addCustomEditor(t,i,s){var e,n;if(this._formView)return void(null===(n=(e=this._formView).addCustomEditor)||void 0===n||n.call(e,t,i,s));const a=new Map(this._customEditors);a.set(t,{customEditor:i,detailContext:null!=s?s:""}),this._customEditors=a}async setFieldProp(t,i,s){const e=this._fieldProps.get(t)||[];this._fieldProps.set(t,[...e,{propName:i,value:s}])}async showSearchField(){if(!this._headerContainer||!this._ezPopoverFieldColumn)return;const t=this._headerContainer.getBoundingClientRect();this.fieldSearch&&(await E(this.fieldSearch),this._ezPopoverFieldColumn.showUnder(this._headerContainer,{horizontalGap:t.width-P,verticalGap:-1*t.height}))}observePropsCustomEditor(t){for(const i in t)this.addCustomEditor(i,t[i])}async observeFieldsProps(t){for(const i in t){const s=t[i],e=Object.keys(s);for(const t of e)await this.setFieldProp(i,t,s[t])}}async observeDataUnit(t,i){t!==i&&t&&t.subscribe(this.dataUnitObserver)}bindFields(t){var i;null==this._dataBinder&&null!=this.dataUnit&&(this._dataBinder=new j(this.dataUnit)),this._dataBinder&&this.dataUnit&&this.formMetadata&&this._dataBinder.bind(t,null===(i=this.dataUnit)||void 0===i?void 0:i.dataUnitId,this.formMetadata,this.recordsValidator)}disconnectedCallback(){null!=this._dataBinder&&this._dataBinder.onDisconnectedCallback(),this.dataUnit&&this.dataUnit.unsubscribe(this.dataUnitObserver)}componentDidLoad(){this.customEditors&&this.observePropsCustomEditor(this.customEditors),this.fieldsProps&&this.observeFieldsProps(this.fieldsProps),this.initLayoutFormConfig()}async initLayoutFormConfig(){const t=o.getContextValue("__SNK__APPLICATION__"),i=await(null==t?void 0:t.getLayoutFormConfig());i&&(this.setSingleColumn(i),this.registerNotifyListeners(i))}setSingleColumn(t){this._singleColumn=(null==t?void 0:t.config)===N.CASCADE||(null==t?void 0:t.config)===N.CLASSIC_CASCADE,this._currentFormLayout=null==t?void 0:t.config}registerNotifyListeners(t){var i;t&&(null===(i=t.onConfigChange)||void 0===i||i.call(t,(t=>{this._singleColumn=t===N.CASCADE||t===N.CLASSIC_CASCADE,this._currentFormLayout=t})))}componentDidRender(){var t;this.setCustomEditors(),this.setFieldProps(),this.fieldToFocus&&(null===(t=this.fields)||void 0===t?void 0:t.some((t=>t.name===this.fieldToFocus)))&&requestAnimationFrame((()=>{var t,i;null===(t=this._dataBinder)||void 0===t||t.setFocus(this.fieldToFocus),null===(i=this.snkRequestClearFieldToFocus)||void 0===i||i.emit()}))}setCustomEditors(){var t,i;if(this._formView)for(const[s,e]of this._customEditors)null===(i=(t=this._formView).addCustomEditor)||void 0===i||i.call(t,s,e.customEditor,e.detailContext),this._customEditors.delete(s)}setFieldProps(){if(this._formView)for(const[t,i]of this._fieldProps)i.forEach((i=>{var s,e;null===(e=(s=this._formView).setFieldProp)||void 0===e||e.call(s,t,i.propName,i.value),this._fieldProps.delete(t)}))}buildSourceRecordPK(t){var i,s,e;const n=(null===(i=t.payload)||void 0===i?void 0:i[0])||{},a=JSON.parse(atob(n.__record__source__id__||""));if(delete a.__DATA_UNIT_NAME__,!this.dataUnit)return{};const o=null!==(s=R(this.dataUnit))&&void 0!==s?s:{},r=Object.keys(o),l={};for(const t of r)l[t]=null===(e=a[t])||void 0===e?void 0:e.value;return l}getImageField(){var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.metadata.fields.filter((t=>t.userInterface===h.IMAGE))}render(){return s(e,null,s("slot",null),s("ez-form-view",{ref:t=>this._formView=t,fields:this.fields,onEzContentReady:t=>this.bindFields(t.detail),singleColumn:this._singleColumn,customUiBuilders:this.customUiBuilders,formLayout:this._currentFormLayout}),this.fieldSearch&&s("ez-popover",{ref:t=>this._ezPopoverFieldColumn=t,overlayType:"none"},this.fieldSearch))}static get watchers(){return{customEditors:["observePropsCustomEditor"],fieldsProps:["observeFieldsProps"],dataUnit:["observeDataUnit"]}}};yt.style=".sc-snk-dynaform-form-view-h{display:flex;flex-direction:column;width:100%;flex-wrap:wrap;background-color:var(--background--xlight);padding:var(--space--12, 12px);border-radius:var(--border--radius-medium);border:1px solid var(--color--petroleum-100, #C8CCD3);--ez-form-card-summary-field-content-weight:700}ez-form-view.sc-snk-dynaform-form-view{padding:var(--space--6 ,6px) 0;--ez-form-view__item--padding:0}.level-path.sc-snk-dynaform-form-view{color:var(--color--title-primary, #2B3A54);font-weight:var(--text-weight--medium, 400);padding-right:3px}.summary-wrapper.sc-snk-dynaform-form-view{display:flex;overflow:hidden}.summary-header.sc-snk-dynaform-form-view{border-bottom:1px solid var(--color--strokes);margin-bottom:var(--space--medium);padding-bottom:var(--space--medium)}.summary-container.sc-snk-dynaform-form-view{display:flex;flex-direction:column}.summary-container.sc-snk-dynaform-form-view{padding-right:calc(var(--space--extra-large) / 1.5)}.summary-field.sc-snk-dynaform-form-view{min-width:30px;max-width:200px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.summary-field__title.sc-snk-dynaform-form-view{color:var(--text--primary, #626e82);font-size:var(--title--small);white-space:nowrap;font-weight:var(--text-weight--medium)}.summary-field__content.sc-snk-dynaform-form-view{color:var(--title--primary, #2b3a54);font-size:var(--text--large);font-weight:var(--ez-form-card-summary-field-content-weight)}";const wt=class{constructor(s){t(this,s),this.ezExpressionChange=i(this,"ezExpressionChange",7),this.filterAssistent=void 0,this.application=void 0}getMessage(t,i){return this.application.messagesBuilder.getMessage(t,i)}render(){var t;return s(e,null,s("span",{class:"ez-title ez-title--small ez-padding-bottom--small snk-filter-advanced-mode__title"},this.getMessage("snkPersonalizedFilter.info.applyExpression")),s("ez-text-area",{rows:9,label:this.getMessage("snkPersonalizedFilter.info.labelExpression"),value:null===(t=this.filterAssistent)||void 0===t?void 0:t.expression,onEzChange:t=>this.ezExpressionChange.emit(t.detail)}))}};wt.style=".sc-snk-filter-advanced-mode-h{display:block;--snk-personalized-filter--title--color:var(--title--primary, #2B3A54)}.snk-filter-advanced-mode__title.sc-snk-filter-advanced-mode{color:var(--snk-personalized-filter--title--color)}";const Ct=class{constructor(s){t(this,s),this.ezChangeFilter=i(this,"ezChangeFilter",7),this.filterAssistent=void 0,this.messagesBuilder=void 0,this.filterId=void 0,this.entityUri=void 0,this.application=void 0,this.isDefaultFilter=!1}getMessage(t,i){return this.application.messagesBuilder.getMessage(t,i)}async handleFilterGroupChange(){const t=await this._mainExpressionGroup.getExpressionGroup();this.filterAssistent=Object.assign(Object.assign({},this.filterAssistent),{assistent:t}),this.filterAssistent.parameters=K.buildVariableParameters(this.filterAssistent.assistent),this.filterAssistent.expression=K.buildGroupExpression(this.filterAssistent.assistent),this.ezChangeFilter.emit(this.filterAssistent)}render(){var t,i;return s(e,null,s("div",{class:"ez-padding-top--small snk-personalized-filter__group"},s("snk-expression-group",{ref:t=>this._mainExpressionGroup=t,group:null===(t=this.filterAssistent)||void 0===t?void 0:t.assistent,messagesBuilder:this.messagesBuilder,onEzFilterGroupChange:this.handleFilterGroupChange.bind(this),filterId:this.filterId,entityURI:this.entityUri,isDefaultFilter:this.isDefaultFilter})),s("div",{class:"ez-margin-top--auto"},s("div",{class:"snk-personalized-filter__expression-input--line"}),s("ez-collapsible-box",{label:this.getMessage("snkPersonalizedFilter.info.titleCollapsible"),headerSize:"medium",value:!0},s("div",{class:"ez-box"},s("div",{class:"ez-box__container--external"},s("div",{class:"ez-box__container--internal"},s("span",{class:"ez-box__container--title"},this.getMessage("snkPersonalizedFilter.info.labelExpression")),s("span",{class:"ez-box__container--expression"},null===(i=this.filterAssistent)||void 0===i?void 0:i.expression)))))))}};Ct.style=".sc-snk-filter-assistent-mode-h{display:flex;flex-direction:column;height:100%;--text-area--font-family:var(--font-pattern, Arial);--text-area__label--floating--top:var(--space--small, 6px);--snk-filter-assistent-mode__container--border-radius:var(--border--radius-medium, 12px);--snk-filter-assistent-mode__container--background:var(--background--medium, #f0f3f7);--snk-filter-assistent-mode__container--margin:var(--space--small, 6px) var(--space--medium, 12px)}.ez-box__container--external.sc-snk-filter-assistent-mode{height:100px;width:100%;overflow-y:auto;background-color:var(--snk-filter-assistent-mode__container--background);border-radius:var(--snk-filter-assistent-mode__container--border-radius)}.ez-box__container--internal.sc-snk-filter-assistent-mode{margin:var(--snk-filter-assistent-mode__container--margin)}.ez-box__container--title.sc-snk-filter-assistent-mode{display:block;user-select:none;font-family:var(--text-area--font-family);font-size:var(--text--extra-small);color:var(--title--primary);top:var(--text-area__label--floating--top)}.ez-box__container--expression.sc-snk-filter-assistent-mode{display:block;font-family:var(--text-area--font-family);font-size:var(--text--medium);color:var(--title--primary);top:var(--text-area__label--floating--top)}.snk-personalized-filter__expression-input--line.sc-snk-filter-assistent-mode{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}";const zt=class{constructor(s){t(this,s),this.filterChange=i(this,"filterChange",7),this.config=void 0,this.getMessage=void 0,this.showHardFixed=!0,this.removalBlocked=!1}async setFocusField(){var t,i,s,e;this._editor&&(this._editor.setFocus?null===(i=null===(t=this._editor)||void 0===t?void 0:t.setFocus)||void 0===i||i.call(t):this._editor.focus&&(null===(e=null===(s=this._editor)||void 0===s?void 0:s.focus)||void 0===e||e.call(s)))}async clearValue(){this._editor&&this._editor.clearValue&&await this._editor.clearValue()}observeConfig(t){var i,s;this._editor&&(this._editor.config=t),null===(s=null===(i=this._editor)||void 0===i?void 0:i.reloadList)||void 0===s||s.call(i),this._customElementObject=this.getContentEditor()}componentDidLoad(){if(this._element){v.addIDInfo(this._element);const t=this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME);this._idContentEditor=`${t}_${this.config.id}`}}changeConfig(t){this.filterChange.emit(t)}getContentEditor(){switch(this.config.type){case C.BINARY_SELECT:return{tag:"snk-filter-binary-select"};case C.MULTI_SELECT:return{tag:"snk-filter-multi-select"};case C.PERIOD:return{tag:"snk-filter-period"};case C.SEARCH:return{tag:"snk-filter-search"};case C.NUMBER:return{tag:"snk-filter-number"};case C.PERSONALIZED:return{tag:"snk-personalized-filter-editor",props:{presentationMode:q.CHIP,onValueChanged:t=>this.handleValueChanged(t)}};case C.CHECK_BOX_LIST:return{tag:"snk-filter-checkbox-list",props:{onValueChanged:t=>this.config=Object.assign(Object.assign({},this.config),{value:t.detail})}};case C.MULTI_LIST:return{tag:"snk-entity-list",props:{onValueChanged:t=>this.config=Object.assign(Object.assign({},this.config),{value:t.detail})}}}return{tag:"snk-filter-text"}}handleValueChanged({detail:t}){const i=(null==t?void 0:t.items)||this.config.groupedItems;this.config=Object.assign(Object.assign({},this.config),{groupedItems:i,visible:(i||[]).filter((t=>t.visible)).length>0})}removeItem(){const t=this.config.type===C.MULTI_LIST&&Array.isArray(this.config.value)?this.config.value.map((t=>Object.assign(Object.assign({},t),{check:!1}))):void 0,i=Object.assign(Object.assign({},this.config),{visible:!1,fixed:!1,value:t});null!=i.groupedItems&&(i.groupedItems=i.groupedItems.map((t=>Object.assign(Object.assign({},t),{visible:!1,fixed:!1,value:void 0})))),this.changeConfig(i)}removeItemFromGroup(t){return Object.assign(Object.assign({},t),{visible:!1,fixed:!1,value:void 0})}getPopUpHeaderButtons(){return s(n,null,!this.removalBlocked&&!this.config.removalBlocked&&this.buildIcon(this.getMessage("snkFilterBar.removeFilter"),"delete",(()=>this.removeItem())),this.showHardFixed&&!this.config.hardFixed&&this.buildIcon(this.getMessage(this.config.fixed?"snkFilterBar.unpinFilter":"snkFilterBar.pinFilter"),this.config.fixed?"un-pin":"push-pin",(()=>this.changeConfig(Object.assign(Object.assign({},this.config),{fixed:!this.config.fixed})))))}buildIcon(t,i,e){return s("button",{onClick:()=>e(),class:"sc-snk-filter-bar snk-filter-item__editor-header-button",ref:i=>i&&this.buildIdButton(i,t)},s("ez-icon",Object.assign({title:t,iconName:i},{[v.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${v.getInternalIDInfo(`_${t}`)}`})))}buildIdButton(t,i){if(!t)return;const s={id:i};t.removeAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME),v.addIDInfoIfNotExists(t,"button",s)}clearBinarySelectValues(){var t;const i=this._editor||{};null===(t=i.resetValues)||void 0===t||t.call(i),this.config=m.copy(this.originalConfig),this.changeConfig(Object.assign(Object.assign({},this.config),{value:void 0}))}apply(){if(!K.validateVariableValues(this.config,this._editor.value))return T.alert(this.getMessage("snkFilterBar.filterModal.validations.notFullFilled.title"),this.getMessage("snkFilterBar.filterModal.validations.notFullFilled.message"));const t=void 0!==this._editor.value?this._editor.value:this.config.value;this.changeConfig(Object.assign(Object.assign({},this.config),{visible:this.isVisible(),value:t}))}isVisible(){return!(this.config.groupedItems&&this.config.groupedItems.length>0)||this.config.groupedItems.filter((t=>t.visible)).length>0}clear(){var t;if(this.config.type!==C.BINARY_SELECT){if(C.MULTI_LIST===this.config.type){const i=m.copy(this.config);return null===(t=i.value)||void 0===t||t.forEach((t=>!!t&&(t.check=!1))),void(this.config=m.copy(i))}this.changeConfig(Object.assign(Object.assign({},this.config),{value:void 0}))}else this.clearBinarySelectValues()}filterCanBeCleared(){return this.config.type!==C.PERSONALIZED}onKeyDonwListener(t){"Enter"===t.key&&this.apply()}buildRightSlot(t){return s("ez-icon",{iconName:"delete",onClick:()=>this.removeValueFromConfig(t)})}removeValueFromConfig(t){var i,s;if(this.config){const e=m.copy(this.config),n=null===(i=e.value)||void 0===i?void 0:i.findIndex((i=>(null==i?void 0:i.id)===t.id));null===(s=e.value)||void 0===s||s.splice(n,1),this.config=m.copy(e)}}componentWillLoad(){this.originalConfig=m.copy(this.config),this._customElementObject=this.getContentEditor()}render(){const{tag:t,props:i}=this._customElementObject;return s(e,null,s("div",{class:"col ez-col--sd-12 ez-align--right ez-padding-medium ez-flex--align-items-center"},s("div",{class:"ez-text ez-title ez-title--small ez-padding--small sc-snk-filter-bar snk-filter-item__editor-header"},this.config.detailTitle),this.getPopUpHeaderButtons()),s(t,Object.assign({maxHeightList:"240px",ref:t=>this._editor=t,value:this.config.value,config:this.config,onKeyDown:t=>this.onKeyDonwListener(t),"data-element-id":this._idContentEditor,getMessage:this.getMessage,rightListSlotBuilder:t=>this.buildRightSlot(t)},i)),s("hr",{class:"sc-snk-filter-bar snk-filter__popover-rule"}),s("div",{class:"ez-col ez-col--sd-12 ez-align--right"},this.filterCanBeCleared()&&s("ez-button",{label:this.getMessage("snkFilterBar.cleanFilter"),onClick:()=>this.clear(),size:"small"}),s("ez-button",{ref:t=>this._applyButton=t,label:this.getMessage("snkFilterBar.applyFilter"),onClick:()=>this.apply(),size:"small",class:"ez-button--primary ez-padding-left--medium"})))}get _element(){return a(this)}static get watchers(){return{config:["observeConfig"]}}},At=class{constructor(s){t(this,s),this.filterChange=i(this,"filterChange",7),this.editPersonalizedFilter=i(this,"editPersonalizedFilter",7),this.addPersonalizedFilter=i(this,"addPersonalizedFilter",7),this.filterItem=void 0,this.configName=void 0,this.resourceID=void 0}getContentEditorConfig(){const t={presentationMode:q.MODAL};switch(this.filterItem.type){case C.BINARY_SELECT:return{tag:"snk-filter-binary-select",props:t};case C.MULTI_SELECT:return{tag:"snk-filter-multi-select"};case C.PERIOD:return{tag:"snk-filter-period",props:t};case C.SEARCH:return{tag:"snk-filter-search"};case C.NUMBER:return{tag:"snk-filter-number",props:t};case C.PERSONALIZED:return this.buildSnkFilterPersonalizedProps();case C.CHECK_BOX_LIST:return{tag:"snk-filter-checkbox-list",props:t};case C.MULTI_LIST:return{tag:"snk-entity-list",props:{maxHeightList:"640px",rightListSlotBuilder:t=>this.buildRightSlot(t)}}}return{tag:"snk-filter-text"}}buildSnkFilterPersonalizedProps(){return{tag:"snk-personalized-filter-editor",props:{onEditFilter:t=>this.editPersonalizedFilter.emit(t.detail),onAddFilter:()=>this.addPersonalizedFilter.emit()}}}isVisible(t){return!!this.filterItem.visible||void 0!==t}updateFilterValue(t){var i,s;const e=void 0!==(null==t?void 0:t.value)?t.value:t;this.filterItem=Object.assign(Object.assign({},this.filterItem),null!=this.filterItem.groupedItems?{visible:e>0,value:e,groupedItems:t.items}:{value:this.filterItem.type===(C.SEARCH||C.CHECK_BOX_LIST)?t:e,visible:this.isVisible(e)}),this._editor&&(this._editor.config=this.filterItem),null===(s=null===(i=this._editor)||void 0===i?void 0:i.reloadList)||void 0===s||s.call(i),this.filterChange.emit(this.filterItem)}handleDeleteFilter(t,i){i===C.PERSONALIZED&&H.removePersonalizedFilter(t,this.resourceID,this.configName)}componentDidLoad(){if(this._element){v.addIDInfo(this._element);const t=this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME);this._idContentEditor=`${t}_${this.filterItem.id}`}}buildRightSlot(t){return s("ez-icon",{iconName:"delete",onClick:()=>this.removeValueFromConfig(t)})}removeValueFromConfig(t){var i,s,e;const n=null===(s=null===(i=this.filterItem)||void 0===i?void 0:i.value)||void 0===s?void 0:s.findIndex((({id:i})=>i===t.id)),a=m.copy(this.filterItem);null===(e=null==a?void 0:a.value)||void 0===e||e.splice(n,1),this.updateFilterValue(a.value)}canShowDetailModal(){const{CUSTOM_FILTER:t,OTHER_FILTERS:i}=I;return![t,i].includes(this.filterItem.filterType)&&this.filterItem.type!==C.BINARY_SELECT}render(){const{tag:t,props:i}=this.getContentEditorConfig();return s(e,null,s("div",{class:"ez-flex ez-flex--column grow"},this.canShowDetailModal()&&s("label",{class:"ez-text ez-text--medium ez-text--primary ez-margin-bottom--extra-small",htmlFor:`filter-item-${this.filterItem.id}`},this.filterItem.detailModal),s(t,Object.assign({ref:t=>this._editor=t,id:`filter-item-${this.filterItem.id}`,config:this.filterItem,value:this.filterItem.value,onValueChanged:t=>this.updateFilterValue(t.detail),"data-element-id":this._idContentEditor},i))))}get _element(){return a(this)}};At.style=".grow{flex-grow:1}.gap{gap:4px}";const xt=class{constructor(s){t(this,s),this.imageError=i(this,"imageError",7),this.dataUnitObserver=async t=>{var i;if([l.NEXT_SELECTED,l.PREVIOUS_SELECTED].includes(t.type))return void await this.loadImage();const s=(null===(i=t.payload)||void 0===i?void 0:i.selection)||[];t.type===l.SELECTION_CHANGED&&s.length>0?await this.loadImage():t.type!==l.RECORDS_ADDED?t.type!==l.EDITION_CANCELED||await this.loadImage():await this.clearImage()},this.dataUnit=void 0,this.fieldName=void 0,this.entityName=void 0,this.enabled=!0,this.acceptType=void 0,this.maxSize=void 0,this.label=void 0,this.imageValue=void 0,this.loading=!0}async reloadImage(t){await this.loadImage(t)}getMessage(t,i){return this.messagesBuilder||(this.messagesBuilder=new g),this.messagesBuilder.getMessage(t,i)}async clearImage(){var t;null===(t=this._loadAbortController)||void 0===t||t.abort(),this.imageValue=void 0}async handleImageChange(t){const i=t.detail;if(!i)return await this.clearImage(),void await this.updatedataUnitField(!0);const s=await M(i);if(this.maxSize&&s.size>1024*this.maxSize){const t=this.getMessage("snkImageInput.errorImageSize")+this.maxSize+"(KB)";return this.imageError.emit(t),void(this.application&&await this.application.error(this.getMessage("snkImageInput.errorTitle"),t))}this.imageValue=i,await U(s,this.entityName,this.fieldName),await this.updatedataUnitField()}async updatedataUnitField(t=!1){this.dataUnit&&this.dataUnit.getSelectedRecord()&&(t?await this.dataUnit.setFieldValue(this.fieldName,"deletado"):await this.dataUnit.setFieldValue(this.fieldName,`$file.session.key{${V(this.entityName,this.fieldName)}}`))}async handleImageError(t){this.imageError.emit(t.detail),this.application&&await this.application.error(this.getMessage("snkImageInput.errorTitle"),t.detail)}getPksFromDataUnit(){if(!this.dataUnit)return;const t=this.dataUnit.getSelectedRecord();if(!t)return;const i=t[this.fieldName];if(i)try{return JSON.parse(i)}catch(t){return void console.error("Error parsing PK from data unit field:",t)}}async loadImage(t){var i,s;null===(i=this._loadAbortController)||void 0===i||i.abort();const e=new AbortController;if(this._loadAbortController=e,this.loading=!0,this.dataUnit&&this.entityName){t=null!==(s=null!=t?t:this.getPksFromDataUnit())&&void 0!==s?s:R(this.dataUnit);const i=await B(t,this.fieldName,this.entityName,e.signal);if(e.signal.aborted)return;this.imageValue=i}this.loading=!1}async componentWillLoad(){this.application=o.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder||(this.messagesBuilder=new g),this.dataUnit&&this.dataUnit.subscribe(this.dataUnitObserver)}disconnectedCallback(){this.dataUnit&&this.dataUnit.unsubscribe(this.dataUnitObserver)}async componentDidLoad(){await this.loadImage()}render(){return s(e,null,s("ez-image-input",{enabled:this.enabled,label:this.label,name:this.fieldName,value:this.imageValue,maxFileSize:this.maxSize?1024*this.maxSize:void 0,accept:this.acceptType||"image/png,image/jpeg,image/gif",onEzChange:t=>this.handleImageChange(t),onEzError:t=>this.handleImageError(t),loading:this.loading}))}};xt.style=":host{display:block}";const St=class{constructor(s){t(this,s),this.ezCancel=i(this,"ezCancel",7),this.ezSave=i(this,"ezSave",7),this.ezAfterSave=i(this,"ezAfterSave",7),this._personalizedFilterFetcher=new Q,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async t=>{let i=null==t?void 0:t.uri;if(d.isEmpty(i)&&(i=this.entityUri),!this._filterMetadataStorage.has(i)){const t=await this._personalizedFilterFetcher.loadFields(i);this._filterMetadataStorage.set(i,t)}return this._filterMetadataStorage.get(i)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const t={name:"",active:!0,expression:"",parameters:[],assistent:{id:d.generateUUID(),items:[{id:d.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:G.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(t),this._originalFilterAssistent=m.copy(t),this._filterAssistent=m.copy(t)}loadFilter(t,i){null!=t&&i!=t&&null!=this.resourceID&&(t!==$.id?H.loadPersonalizedFilter(t,this.resourceID,this.configName).then((t=>{const i=this.applyDefaultValues(t);this._filterAssistent=i,this._originalFilterAssistent=m.copy(i),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):H.loadDefaultFilter(t,this.resourceID,this.configName).then((t=>{const i=this.applyDefaultValues(t);this._filterAssistent=i,this._originalFilterAssistent=m.copy(i),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var t;null==J.get(`filterFieldsDataSource.${this.entityUri}`)&&J.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=o.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(t=this._application)||void 0===t?void 0:t.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var t;null===(t=this._viewStackRef)||void 0===t||t.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME,v.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(t){t.name=$.name,t.id=$.id}getMessage(t,i){return this._application.messagesBuilder.getMessage(t,i)}async saveFilter(){let t;t=this.isDefaultFilter?await H.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await H.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,T.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const i=Object.assign(Object.assign({},t),this._filterAssistent);i.parameters=K.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=m.copy(i),this._filterAssistent=m.copy(i),this.ezAfterSave.emit()}removeFilter(){H.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!K.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:t,expression:i}=this._filterAssistent,s=t?K.buildGroupExpression(t):i;this._filterAssistent.expression=s,this.ezSave.emit(s),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?T.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((t=>{t&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:t,message:i=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return t||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),i.replace(/.*Exception: /,"")),t}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();T.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((t=>{var i;t&&(this._filterAssistent=m.copy(null!==(i=this._originalFilterAssistent)&&void 0!==i?i:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(t){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:t}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(t){return this.addLabelToItems(t),this.addFilterGroupCondition(t),t}addFilterGroupCondition(t){t.assistent&&!t.assistent.operand&&(t.assistent.operand=G.AND)}addLabelToItems(t){t.assistent&&t.assistent.items&&t.assistent.items.length>0&&t.assistent.items.forEach((i=>{if(null==i.fieldLabel){const s=(t.parameters||[]).find((t=>t.fieldName===i.fieldName));s&&(i.fieldLabel=s.label)}}))}handleExpressionChangeAdvancedMode(t){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(t){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},t)}selectField(t){if(!("name"in t))return;const i=this.buildExpression(t.entityName,t.name,t.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(i)}buildExpression(t,i,s){return s.length>0&&s.shift(),s.length>0?`${s.join("->")}->${i}`:`${t}.${i}`}onAddField(t){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),t.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(t,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return s(n,null,s("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:t=>this.onAddField(t.target)},s("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),s("snk-filter-field-search",{class:"ez-padding-left--medium",ref:t=>this._elFilterFieldSearch=t,onEzSelectFilterItem:t=>this.selectField(t.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return s("ez-view-stack",{ref:t=>this._viewStackRef=t},s("stack-item",null,this._filterAssistentMode&&s("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:t=>this.handleChangeFilterAssistentMode(t.detail),isDefaultFilter:this.isDefaultFilter})),s("stack-item",null,s("snk-filter-advanced-mode",{ref:t=>this._elAdvancedMode=t,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:t=>this.handleExpressionChangeAdvancedMode(t.detail)})))}handleModeChange(){var t,i;if(this._filterAssistentMode)T.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((t=>{if(t&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const t=K.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=t,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(t=this._filterAssistent)||void 0===t?void 0:t.expression)===(null===(i=this._originalFilterAssistent)||void 0===i?void 0:i.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const t=this._filterAssistent.expression,i=K.buildGroupExpression(this._filterAssistent.assistent);t!==i?T.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((t=>{t&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var t,i,n,a;if((null===(t=this._filterAssistent)||void 0===t?void 0:t.assistent)||!this._filterAssistentMode)return s(e,null,s("div",{class:"snk-personalized-filter"},s("div",null,s("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},s("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},s("ez-button",{label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),s("ez-button",{ref:t=>this._elButtonSave=t,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),s("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},s("div",{class:"ez-box__container"},s("div",{class:"ez-flex ez-flex--column ez-size-width--full"},s("div",{class:"ez-flex"},s("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},s("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(i=this._filterAssistent)||void 0===i?void 0:i.name,onEzChange:t=>this.handleTitleChange(t.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),s("ez-button",{ref:t=>this._elButtonMode=t,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(n=this._filterAssistent)||void 0===n?void 0:n.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(a=this._filterAssistent)||void 0===a?void 0:a.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};St.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";const Ot=class{constructor(s){t(this,s),this.clickBreadcrumbItem=i(this,"clickBreadcrumbItem",3),this.exit=i(this,"exit",3),this.label=void 0,this.breadcrumbItens=void 0,this.messagesBuilder=void 0}getMessage(t,i){var s;return this.messagesBuilder?this.messagesBuilder.getMessage(t,i):(null===(s=this._application)||void 0===s?void 0:s.messagesBuilder)?this._application.messagesBuilder.getMessage(t,i):void 0}componentDidLoad(){this._element&&(v.addIDInfo(this._element),this._application=o.getContextValue("__SNK__APPLICATION__"))}render(){return s("div",{class:"simple-bar__container ez-margin-vertical--small ez-padding--extra-small"},s("div",{class:"simple-bar__left-slot"},s("ez-button",{class:"ez-padding-right--medium",title:this.getMessage("snkSimpleBar.backTitle"),mode:"icon",iconName:"arrow_back",size:"medium",onClick:()=>this.exit.emit()}),s("div",{class:"simple-bar__column"},s("h1",{class:"ez-title ez-title--primary ez-title--extra-large"},this.label),s("ez-breadcrumb",{items:this.breadcrumbItens,onSelectedItem:({detail:t})=>this.clickBreadcrumbItem.emit(t)}))),s("div",{class:"simple-bar__right-slot"},s("slot",{name:"rightSlot"})))}get _element(){return a(this)}};Ot.style=".sc-snk-simple-bar-h{display:flex;height:100%;width:100%}.simple-bar__container.sc-snk-simple-bar{flex:1;display:flex;align-items:stretch;gap:var(--space--small)}.simple-bar__left-slot.sc-snk-simple-bar{min-width:280px;flex:1;display:flex;align-items:center}.simple-bar__right-slot.sc-snk-simple-bar{flex:1;display:flex;align-items:center;justify-content:flex-end}.simple-bar__column.sc-snk-simple-bar{flex:1;display:flex;flex-direction:column}";const Ft=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],It=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"],Et=class{constructor(s){t(this,s),this.dataStateChange=i(this,"dataStateChange",3),this.dataUnitReady=i(this,"dataUnitReady",3),this.actionClick=i(this,"actionClick",7),this.formItemsReady=i(this,"formItemsReady",7),this.configuratorSave=i(this,"configuratorSave",7),this.configuratorCancel=i(this,"configuratorCancel",7),this._multiSelectionListDataSource=new W,this._formConfigFetcher=new z,this._customEditors=new Map,this._customRenders=new Map,this._container=void 0,this._showPopUpGridConfig=!1,this._currentViewMode=A.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${d.generateUUID()}`,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=x.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this.enableContinuousInsert=!1,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.paginationCounterMode="auto",this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=!1,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.multipleEditionEnabled=!0,this.layoutFormConfig=!0,this.disableGridEdition=!1,this.autoLoad=void 0,this.outlineMode=!1}async addCustomEditor(t,i){if(this._grid&&this._form)return this._grid.addCustomEditor(t,i),void this._form.addCustomEditor(t,i);const s=new Map(this._customEditors);s.set(t,i),this._customEditors=s}async addGridCustomRender(t,i){if(this._grid)return void this._grid.addGridCustomRender(t,i);const s=new Map(this._customRenders);s.set(t,i),this._customRenders=s}async handleResourceIDChanged(t,i){d.isEmpty(t)||t!==i&&(await this.loadFormConfig(!0),await this.loadGridConfig(!0))}async addCustomValueFormatter(t,i){this._grid.addCustomValueFormatter(t,i)}async removeCustomValueFormatter(t){this._grid.removeCustomValueFormatter(t)}async setFieldProp(t,i,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(t);e.set(t,Object.assign(Object.assign({},n),{[i]:s})),this._fieldsProps=e}loadTaskbarProcessor(){const t={};t[Pt.FORM_REGULAR]=this.getButtons(!1,[O.GRID_MODE],!0),t[Pt.GRID_REGULAR]=this.getButtons(!1,[O.DATA_EXPORTER,O.FORM_MODE]),t[Pt.FORM_SELECTED]=this.getButtons(!0,[O.GRID_MODE],!0),t[Pt.GRID_SELECTED]=this.getGridSelectedButtonsCallBack.bind(this),t[Pt.FINISH_EDITION]=this.getFinishEditionButtonsCallback.bind(this),t[Pt.MULTIPLE_EDITION]=[O.CANCEL],this._taskbarProcessor=new X(t)}getGridSelectedButtonsCallBack(){var t,i,s;return this.multipleEditionEnabled&&1!==(null===(s=null===(i=null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)||void 0===i?void 0:i.records)||void 0===s?void 0:s.length)?this.getButtons(!0,[O.UPDATE_MULTIPLE,O.DATA_EXPORTER,O.FORM_MODE]):this.getButtons(!0,[O.DATA_EXPORTER,O.FORM_MODE])}getFinishEditionButtonsCallback(){const t=[O.CANCEL,O.SAVE];return this.enableGridInsert&&this._currentViewMode!==A.ATTACHMENT&&t.push(this._currentViewMode===A.GRID?O.FORM_MODE:O.GRID_MODE),t}getButtons(t,i,s){let e=t?It:Ft;return(s||this.mode===x.IN_MEMORY)&&(e=e.filter((t=>t!==O.REFRESH))),this.addConfigButton(e.concat(i))}addConfigButton(t){return void 0===this.configName||this.configName&&this.gridLegacyConfigName?t:t.concat(O.CONFIGURATOR)}get application(){return o.getContextValue("__SNK__APPLICATION__")}async goToView(t){this._currentViewMode=t,this._viewStack&&(t===A.GRID&&(this.dataUnit.isMultipleEdition=!1),this._viewStack.show(t)),t===A.GRID&&requestAnimationFrame((()=>this.focusToGrid())),t===A.FORM&&requestAnimationFrame((()=>this.focusToForm()))}actionClickListener(t){this.handleTaskbarAction(t.detail),t.stopPropagation()}handleTaskbarAction(t){switch(t){case O.CONFIGURATOR:this._snkConfigurator.open();break;case O.GRID_MODE:this.goToView(A.GRID);break;case O.FORM_MODE:this.goToView(A.FORM);break;case O.UPDATE_MULTIPLE:this.dataUnit.isMultipleEdition=!0,this.goToView(A.FORM)}}async onChangeEntityName(t){if(this.dataUnit)return;const i=o.getContextValue("__SNK__APPLICATION__");this.dataUnit=await i.getDataUnit(t,null,null,this.configName)}onModeChange(){this.mode==x.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(t,i){this.handleDataStateChange(t,i)}async observeFormLegacy(t,i){await this.handleUpdateFormLegacyConfig(t,i)}async observeGridLegacy(t,i){await this.handleUpdateGridLegacyConfig(t,i)}async handleDataStateChange(t,i){m.objectToString(i)!=m.objectToString(t)&&this.dataStateChange.emit(t),await this.processRmPrecision()}async processRmPrecision(){var t,i;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(i=null===(t=this.dataState)||void 0===t?void 0:t.rowMetadata)||void 0===i?void 0:i.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(t,i){null!=t&&t!=i&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(t,i){null!=t&&t!=i&&this._formConfigAlreadyLoaded&&await this.loadFormConfig(!0)}async openConfig(t){await this._snkConfigurator.close(),t===A.GRID?await this.openGridConfig():t===A.FORM&&await this.openFormConfig()}async openGridConfig(){var t,i,s,e;const n=null!==(i=await(null===(t=this._grid)||void 0===t?void 0:t.getColumns()))&&void 0!==i?i:[],a=null!==(e=await(null===(s=this._grid)||void 0===s?void 0:s.getColumnsState()))&&void 0!==e?e:[];this._snkGridConfig.columns=a.filter((t=>t.name)),this._snkGridConfig.originalColumns=n.filter((t=>t.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}async openFormConfig(){(this.formLegacyConfigName||this.configName)&&await this._snkSimpleFormConfig.show()}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&H.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(t){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||t))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((t,i)=>{H.loadGridConfig(this.configName,this.resolveResourceID()).then((i=>{this.setGridConfig(i),t()})).catch((t=>{i(t)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(t=!1,i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!t)return;this._formConfigAlreadyLoaded=!0;let s=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=s)return this._formConfigManager.setConfig(s),void this.setFormConfig(s,i);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this.loadTaskbarProcessor(),this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),await this.loadGridConfig(),await this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new Y,this._continuousInsertUtils=new st(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((t=>this.enableContinuousInsert=t))}componentDidLoad(){L.applyVarsGrid(this._element,this._grid),this.initKeyboardManager(),this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}async dataUnitActionHandler(t){t.type!==l.EDITION_CANCELED&&t.type!==l.DATA_SAVED||this.dataUnit.isMultipleEdition&&this.goToView(A.GRID)}getMessage(t,i){var s;return null===(s=this.messagesBuilder)||void 0===s?void 0:s.getMessage(t,i)}disconnectedCallback(){var t;null===(t=this._keyboardManager)||void 0===t||t.unbindAllShortcutKeys()}setCustomRenders(){if(this._grid)for(const[t,i]of this._customRenders)this._grid.addGridCustomRender(t,i),this._customRenders.delete(t)}setCustomEditors(){if(this._grid&&this._form)for(const[t,i]of this._customEditors)this._grid.addCustomEditor(t,i),this._form.addCustomEditor(t,i),this._customEditors.delete(t)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[t,i]of this._fieldsProps){for(const s in i)this._form.setFieldProp(t,s,i[s]);this._fieldsProps.delete(t)}}getTaskBarId(){var t,i;return(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?Pt.FINISH_EDITION:this.dataUnit.isMultipleEdition?Pt.MULTIPLE_EDITION:(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===A.GRID?Pt.GRID_SELECTED:Pt.FORM_SELECTED:this._currentViewMode===A.GRID?Pt.GRID_REGULAR:Pt.FORM_REGULAR}initInMemoryDataUnit(){this._inMemoryLoader=new w(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(t){return this._inMemoryLoader?this._inMemoryLoader.metadata=t:this.dataUnit&&(this.dataUnit.metadata=t),Promise.resolve()}setRecords(t){return this._inMemoryLoader?this._inMemoryLoader.records=t:this.dataUnit&&(this.dataUnit.records=t),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.open()}async closeConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const t=this._element.querySelectorAll("snk-field-metadata"),i=[],s={fields:[],emptyConfig:!1};t.forEach((t=>{const e={name:t.getAttribute("name")||t.getAttribute("label"),label:t.getAttribute("label"),dataType:r[t.getAttribute("dataType")]||r.TEXT,userInterface:h[t.getAttribute("userInterface")]||h.SHORTTEXT,readOnly:"true"==t.getAttribute("readOnly"),required:"true"==t.getAttribute("required"),tab:t.getAttribute("tab")||void 0,visible:"false"!=t.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),i.push(e)})),i.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:i})}addGridCustomValueFormattters(){var t,i,s;const e=(null===(t=this._metadata)||void 0===t?void 0:t.fields)||(null===(s=null===(i=this.dataUnit)||void 0===i?void 0:i.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rm_precision)&&!n.includes(t.name)&&n.push(t.name)})),n.forEach((t=>{this.addCustomValueFormatter(t,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(t){this.dataState=Object.assign({},t.detail)}getTaskBarDisabledButtons(){var t,i,s,e,n,a;const o=[];return(null===(t=this.dataState)||void 0===t?void 0:t.hasNext)||o.push(O.NEXT),(null===(i=this.dataState)||void 0===i?void 0:i.hasPrevious)||o.push(O.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&o.push(O.FORM_MODE),(null===(a=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===a?void 0:a.length)>1&&o.push(O.CLONE),o}handleCancelEdit(){var t;(null===(t=this.dataState)||void 0===t?void 0:t.recordsIsEmpty)&&(this.goToView(A.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(t,i){t.stopImmediatePropagation(),"SAVE"!==i?this.configuratorCancel.emit():this.configuratorSave.emit()}onSelectField(t){null!=t&&(this._fieldToGetFocus=t.value)}getFieldSearch(t,i){return null!=this._fieldSearch||(this._splitButtonForm=t,this._fieldSearch=D(i,(({argument:t})=>this.fieldsOptionLoader(t)),(t=>this.onSelectField(t)))),this._fieldSearch}getFormFields(){var t,i;return null!==(i=null===(t=this.formConfig)||void 0===t?void 0:t.fields)&&void 0!==i?i:this._formFields}handleFormSetFields(t){m.equals(this._formFields,t)||(this._formFields=null!=t?t:[])}fieldsOptionLoader(t){const i=null==t?void 0:t.toLowerCase(),s=this.getFormFields().map((t=>{var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getField(t.name)})).filter((t=>{var s,e;return(null===(s=t.name)||void 0===s?void 0:s.toLowerCase().includes(i))||(null===(e=t.label)||void 0===e?void 0:e.toLowerCase().includes(i))})).map((t=>({value:t.name,label:t.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getColumnSearch(t,i){return null!=this._columnSearch||(this._splitButton=t,this._columnSearch=D(i,(({argument:t})=>new Promise((i=>{this._grid.filterColumns(t).then((t=>{i(t.filter((t=>!t.hidden)).map((t=>({label:t.label,value:t.name}))))}))}))),(t=>{null!=t&&this._grid.locateColumn(t.value)}))),this._columnSearch}getActionsList(){const t=[];if(this.enableGridInsert&&t.push(this._continuousInsertUtils.actionContinuousInsert(this.enableContinuousInsert,(()=>{this.enableContinuousInsert=!this.enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this.enableContinuousInsert)}))),this.isGridInsertActive())return t;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return t.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return t.concat(this.actionsList)}getSettingsListGrid(){return[{value:d.generateUUID(),label:this.getMessage("snkSimpleCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(t,i)=>this.getColumnSearch(t,i)}]}getSettingsListForm(){return[{value:d.generateUUID(),label:this.getMessage("snkSimpleCrud.findFields"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(t,i)=>this.getFieldSearch(t,i)}]}getTopTaskBarId(){var t;return(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?`snkGridTopTaskbar.finish_edition${k.PRIMARY}`:`snkGridTopTaskbar.regular${k.PRIMARY}`}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}gridConfigChangeHandler(t){t.stopPropagation(),this.configName&&H.saveGridConfig(t.detail,this.configName,this.resolveResourceID())}modalConfigChangeHandler(t){const i=t.detail;this._grid.setColumnsState(i.columns).then((()=>{this.setGridConfig(i),this.closeGridConfig(),this.dataExporterProviderStore()})),t.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const t=new tt(this.dataUnit,this._grid);J.set("exporterProviders",Object.assign(Object.assign({},J.get("exporterProviders")),{[this.getDataExporterStoreKey()]:t}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(t){this.gridConfig=t,Z.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(t,i){this.formConfig&&!i||(this.formConfig=t)}closeGridConfig(){this._showPopUpGridConfig=!1}getPageSize(){return this.mode===x.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}resolveResourceID(){return d.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var t;const i=null===(t=this._formConfigManager)||void 0===t?void 0:t.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||i?i:this.formConfig}updateFormConfig(){let t=this.formConfig;null==this.formLegacyConfigName&&(t=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields})),this.setFormConfig(t,!0),null==this._formConfigManager&&(this._formConfigManager=new it(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(A.FORM)}async initKeyboardManager(){var t;this._keyboardManager=new f({propagate:!1,element:this._element});const i=this.dataUnit||await(null===(t=this._snkDataUnit)||void 0===t?void 0:t.getDataUnit());null!=i&&this._keyboardManager.bind("F7",(()=>i.saveData()),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.saveData"),element:this._element}).bind("F8",i.addRecord.bind(i),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.addRecord"),element:this._element}).bind("F9",i.removeSelectedRecords.bind(i),{description:this.getMessage("snkSimpleCrud.keyboardShortcuts.removeRecord"),element:this._element}).bind("Escape",(()=>{i.isDirty()&&i.cancelEdition()}),{debounceTime:1e3,description:this.getMessage("snkSimpleCrud.keyboardShortcuts.cancelAction"),element:this._element})}async handleFormConfigSaved(){await this.loadFormConfig(!0,!0)}focusToGrid(){this._grid.focus()}focusToForm(){this._form.focus()}renderTaskbarContent(t){var i;return s("snk-taskbar",{class:"ez-box--no-outline ez-box "+(this._currentViewMode===A.FORM?(this.outlineMode?"ez-box--outline":"ez-box--shadow-xsmall")+" ez-padding--small":""),dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),actionsSettingsList:t===A.GRID?this.getSettingsListGrid():this.getSettingsListForm(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:k.SECONDARY,tabindex:"0"},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}))}render(){var t;if(null!=this.dataUnit)return s("snk-data-unit",{ref:t=>this._snkDataUnit=t,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:t=>this.onDataStateChange(t),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:t=>this.dataUnitReady.emit(t.detail),onMessagesBuilderUpdated:t=>this.messagesBuilder=t.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:`ez-box ez-box--no-outline ${this.outlineMode?"ez-box--outline":"ez-box--shadow"} simple-crud__container-section`,ref:t=>this._container=t,tabindex:"0"},s("ez-view-stack",{ref:t=>this._viewStack=t,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large ez-box--no-outline",ref:t=>this._grid=t,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(A.FORM),onConfigChange:t=>this.gridConfigChangeHandler(t),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(w.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this.enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode,tabindex:"0",paginationCounterMode:this.paginationCounterMode,canEdit:!this.disableGridEdition},this.renderTaskbarContent(A.GRID),s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,this.renderTaskbarContent(A.FORM),s("ez-form",{ref:t=>this._form=t,class:"ez-margin-top--large ez-box--no-outline",dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:t=>this.handleFormSetFields(t.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),elementFocusSearchField:this._container,tabindex:"0"}),s("slot",{name:"snkSimpleCrudFormFooter"}),s("snk-simple-form-config",{ref:t=>this._snkSimpleFormConfig=t,dataUnit:this.dataUnit,onSnkConfigSaved:this.handleFormConfigSaved.bind(this),configName:null!==(t=this.formLegacyConfigName)&&void 0!==t?t:this.configName,messagesBuilder:this.messagesBuilder})),this.messagesBuilder&&s("snk-configurator",{ref:t=>this._snkConfigurator=t,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:t=>this.goToView(t.detail),onOpenConfig:t=>this.openConfig(t.detail),showActionButtons:this.showConfiguratorButtons,onSave:t=>this.handleConfiguratorEvent(t,"SAVE"),onCancel:t=>this.handleConfiguratorEvent(t,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId,layoutFormConfig:this.layoutFormConfig})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-popup",{size:"medium",heightMode:"auto",useHeader:!1,opened:this._showPopUpGridConfig,onEzClosePopup:()=>this.closeGridConfig()},s("snk-grid-config",{ref:t=>this._snkGridConfig=t,config:this.gridConfig,"data-element-id":this._element.getAttribute(v.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:t=>this.modalConfigChangeHandler(t),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return a(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};var Pt;!function(t){t.FORM_REGULAR="snkSimpleCrudTaskbar.form_regular",t.GRID_REGULAR="snkSimpleCrudTaskbar.grid_regular",t.FORM_SELECTED="snkSimpleCrudTaskbar.form_selected",t.GRID_SELECTED="snkSimpleCrudTaskbar.grid_selected",t.FINISH_EDITION="snkSimpleCrudTaskbar.finish_edition",t.MULTIPLE_EDITION="snkSimpleCrudTaskbar.multiple_edition"}(Pt||(Pt={})),Et.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid__container--shadow--outline:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{kt as snk_attach,_t as snk_default_filter,yt as snk_dynaform_form_view,wt as snk_filter_advanced_mode,Ct as snk_filter_assistent_mode,zt as snk_filter_detail,At as snk_filter_modal_item,xt as snk_image_input,St as snk_personalized_filter,Ot as snk_simple_bar,Et as snk_simple_crud}
@@ -1,6 +1,6 @@
1
- import{UserInterface as e,DataType as t,ApplicationContext as n,ErrorException as i}from"@sankhyalabs/core";import{d as o,D as r}from"./p-5d02c032.js";function a(e){const t=(n=e.fieldsMetadata)&&n.length?n.map((e=>({name:e.fieldName,label:e.description,dataType:u(e.type),userInterface:l(e),properties:s(e)}))):[];var n;return{label:e.entityDescription,name:e.descriptionField,fields:t}}function s(e){const t={};return t.options=function(e){const t=e.options;if(!t)return;const n=[];return Object.keys(t).forEach((e=>{n.push({label:e,value:t[e]})})),n}(e),t.mask=function(e){const t=e.uiType;return t?String(t).toLowerCase():void 0}(e),t}function l(t){const n=t.options;return n&&Object.keys(n).length>0?e.OPTIONSELECTOR:"D"===t.type?e.DATE:"H"===t.type?e.DATETIME:"T"===t.type?e.TIME:"I"===t.type?e.INTEGERNUMBER:void 0}function u(e){switch(e){case"F":case"I":return t.NUMBER;case"D":case"H":return t.DATE;case"B":return t.OBJECT;default:return t.TEXT}}function c(e){return Object.assign({id:e.codigo,label:`${e.caminho} - ${e.descricao}`,bold:"N"===e.analitico,props:{analitico:"S"===e.analitico}},e.no&&{children:e.no.map(c)})}var d,v,f;!function(e){e[e.GRID=0]="GRID",e[e.CARDS=1]="CARDS",e[e.TREE=2]="TREE"}(d||(d={}));class m{constructor(){this._defaultPageSize=100,this._templateByQuery=new Map,this._searchListenersByDataUnit=new Map,this.buldTemplates()}buldTemplates(){this._templateByQuery.set("search",o.gql`query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
1
+ import{UserInterface as e,DataType as t,ApplicationContext as n,ErrorException as i}from"@sankhyalabs/core";import{d as o,D as r}from"./p-10d883b0.js";function a(e){const t=(n=e.fieldsMetadata)&&n.length?n.map((e=>({name:e.fieldName,label:e.description,dataType:u(e.type),userInterface:l(e),properties:s(e)}))):[];var n;return{label:e.entityDescription,name:e.descriptionField,fields:t}}function s(e){const t={};return t.options=function(e){const t=e.options;if(!t)return;const n=[];return Object.keys(t).forEach((e=>{n.push({label:e,value:t[e]})})),n}(e),t.mask=function(e){const t=e.uiType;return t?String(t).toLowerCase():void 0}(e),t}function l(t){const n=t.options;return n&&Object.keys(n).length>0?e.OPTIONSELECTOR:"D"===t.type?e.DATE:"H"===t.type?e.DATETIME:"T"===t.type?e.TIME:"I"===t.type?e.INTEGERNUMBER:void 0}function u(e){switch(e){case"F":case"I":return t.NUMBER;case"D":case"H":return t.DATE;case"B":return t.OBJECT;default:return t.TEXT}}function c(e){return Object.assign({id:e.codigo,label:`${e.caminho} - ${e.descricao}`,bold:"N"===e.analitico,props:{analitico:"S"===e.analitico}},e.no&&{children:e.no.map(c)})}var d,v,f;!function(e){e[e.GRID=0]="GRID",e[e.CARDS=1]="CARDS",e[e.TREE=2]="TREE"}(d||(d={}));class m{constructor(){this._defaultPageSize=100,this._templateByQuery=new Map,this._searchListenersByDataUnit=new Map,this.buldTemplates()}buldTemplates(){this._templateByQuery.set("search",o.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(e,n,i,o){var a;const s=(null==n?void 0:n.toString().trim())||void 0;n=isNaN(Number(s))&&s?`%${s}`:s,null==i||i.params.forEach((e=>{e.dataType===t.OBJECT&&(e.value=JSON.stringify(e.value))}));const l=this.applySearchListener(v.beforeSearch,e,n,i,o),u={argument:(null==l?void 0:l.argument)||n,entityName:e,criteria:(null==l?void 0:l.criteria)||i,options:(null==l?void 0:l.searchOptions)||o};return u.options&&(null===(a=u.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{r.get().callGraphQL({values:u,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}buildDescriptionCacheKey(e,t){return`${e}__${t}`}async loadByCode(e,t,n,i){const o=this.buildDescriptionCacheKey(e,t),r=m.DESCRIPTIONS_BY_CODE[o];if(r)return Promise.resolve(r);const a=await this.loadAdvancedSearch(e,void 0,n,i,t);return m.DESCRIPTIONS_BY_CODE[o]=a,a}loadAdvancedSearch(e,o,a,s,l){var u,c,d,f,m,p;const h=this.applySearchListener(v.beforeSearch,e,o,a,s),N={argument:(null==h?void 0:h.argument)||o,criteria:(null==h?void 0:h.criteria)||a,searchOptions:Object.assign(Object.assign({},s),null==h?void 0:h.searchOptions)},S={query:{$:null===(u=N.criteria)||void 0===u?void 0:u.expression}};(null===(d=null===(c=N.criteria)||void 0===c?void 0:c.params)||void 0===d?void 0:d.length)>0&&(S.params={param:N.criteria.params.map((e=>{let o=e.value;if("string"==typeof o){const e=/CTX\{([^}]+)\}/.exec(o);e&&(o=n.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${e[1]})__`))}if(e.dataType===t.NUMBER&&void 0===o)throw new i("Falha detectada",`O campo ${e.name} deve ser informado.`);let r=e.dataType;return r===t.OBJECT?(o=o.value,r="S"):r=g(e.dataType),{$:o,type:r}}))});const y=null!=s?Object.assign(Object.assign({},null==N?void 0:N.searchOptions),{pkFieldName:s.codeFieldName,label:s.descriptionFieldName,fieldName:s.codeFieldName,useDescriptionOptions:!1,enableRowsCounter:!0,limit:s.limit}):void 0,O={serviceName:"PesquisaSP.getSuggestion",requestBody:{criteria:Object.assign({entityName:e,compacted:!1,ignoreEntityCriteria:null!==(f=null==y?void 0:y.ignoreEntityCriteria)&&void 0!==f&&f,limit:null!==(m=null==y?void 0:y.limit)&&void 0!==m?m:this._defaultPageSize,orderByDesc:!1,externalCriteria:S,localEntityName:null===(p=N.searchOptions)||void 0===p?void 0:p.rootEntity},{options:y}),clientEventList:{clientEvent:[]}}};null==l?O.requestBody.criteria.query={$:o}:O.requestBody.criteria.pk={$:l};const C={urlParams:{quietMode:!0}};return new Promise(((e,t)=>{r.get().callServiceBroker("PesquisaSP.getSuggestion",JSON.stringify(O),C).then((t=>e(t))).catch((e=>t(e)))}))}addSearchListener(e,t,n){var i;const o=this._searchListenersByDataUnit.get(t)||[],r=o.find((t=>t.entity===e));if(r){for(const e of Object.keys(n))if(e in r.listener){if((null===(i=r.listener[e])||void 0===i?void 0:i.toString())===n[e].toString())continue;r.listener[e]=n[e]}}else this._searchListenersByDataUnit.set(t,[...o,{entity:e,listener:n}]);return()=>{const n=o.filter((t=>t.entity!==e));n.length?this._searchListenersByDataUnit.set(t,n):this._searchListenersByDataUnit.delete(t)}}applySearchListener(e,t,n,i,o){var r;const a=null==o?void 0:o.dataUnitId;if(!a)return;const s=null===(r=this._searchListenersByDataUnit.get(a))||void 0===r?void 0:r.find((({entity:e})=>e===t));if(!s)return;const{listener:l}=s;return e in l?l[e]({argument:n,criteria:i,searchOptions:o}):void 0}async loadPresentationConfig(e){var t,n;let i=function(e){return{config:{chave:`PesquisaContent:${e}`,tipo:"T"}}}(e);const o=await r.get().callServiceBroker("SystemUtilsSP.getConf",JSON.stringify(i));return null!==(n=null===(t=null==o?void 0:o.config)||void 0===t?void 0:t.lastUsedMode)&&void 0!==n?n:"list"}async savePresentationConfig(e,t){let n=function(e,t){return{config:{lastUsedMode:t,chave:`PesquisaContent:${e}`,tipo:"T"}}}(e,t);await r.get().callServiceBroker("SystemUtilsSP.saveConf",JSON.stringify(n))}async loadPesquisaGridConfig(e){const t=function(e){return{gridConfig:{configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`}}}(e);return function(e){var t,n;const i=[],o=null!==(n=null===(t=null==e?void 0:e.gridConfig)||void 0===t?void 0:t.field)&&void 0!==n?n:{};if(Object.keys(o).forEach((e=>i.push(o[e]))),i.length)return{columns:i}}(await r.get().callServiceBroker("GridConfig.getGridConfigFromJson",JSON.stringify(t)))}async savePesquisaGridConfig(e,t){const n=function(e,t){const n={};return null==t||t.forEach(((e,t)=>n[`field${t}`]=e)),{gridConfig:{compactMode:!0,configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`,field:n}}}(e,t);await r.get().callServiceBroker("GridConfig.saveGridConfigFromJSON",JSON.stringify(n))}async loadTree(e,t,n,i){const o=this.buildLoadTreeRequestBody(e,t,n,i);return(null!==(s=null===(a=(await r.get().callServiceBroker("Pesquisa.getStructuredData",JSON.stringify(o))).arvore)||void 0===a?void 0:a.no)&&void 0!==s?s:[]).map(c);var a,s}buildLoadTreeRequestBody(e,t,n,i){var o,r;const a=this.applySearchListener(v.beforeSearch,e,t,n,i),s=null!==(o=null==a?void 0:a.searchOptions)&&void 0!==o?o:i,l=null==s?void 0:s.rootEntity,u=null==s?void 0:s.codeFieldName,c=null===(r=null==a?void 0:a.criteria)||void 0===r?void 0:r.expression,d=this.buildParams(a),f={nome:e,nomeInstanciaLocal:l,codeFieldName:u};return c&&(f.criterioLiteral={expressao:{$:c},parametro:d}),{instancia:f}}buildParams(e){var t,n;let i=null!==(n=null===(t=null==e?void 0:e.criteria)||void 0===t?void 0:t.params)&&void 0!==n?n:[];return i=i.map((e=>Object.assign(Object.assign({},e),{tipo:g(e.dataType),$:e.value}))),i}}function g(e){switch(e){case t.NUMBER:return"I";case t.DATE:return"D";default:return"S"}}m.DESCRIPTIONS_BY_CODE={},function(e){e.beforeSearch="beforeSearch"}(v||(v={})),function(e){e.LINK_AND_FILE_AT_THE_SAME_TIME="LINK_AND_FILE_AT_THE_SAME_TIME",e.ANY_LINK_OR_FILE_FILLED="ANY_LINK_OR_FILE_FILLED",e.UNKNOWN="UNKNOWN",e.DESCRIPTION_CANNOT_BE_CHANGED="DESCRIPTION_CANNOT_BE_CHANGED"}(f||(f={}));export{m as P,f as S,d as a,a as b}
6
+ }`)}loadSearchOptions(e,n,i,o){var a;const s=(null==n?void 0:n.toString().trim())||void 0;n=isNaN(Number(s))&&s?`%${s}`:s,null==i||i.params.forEach((e=>{e.dataType===t.OBJECT&&(e.value=JSON.stringify(e.value))}));const l=this.applySearchListener(v.beforeSearch,e,n,i,o),u={argument:(null==l?void 0:l.argument)||n,entityName:e,criteria:(null==l?void 0:l.criteria)||i,options:(null==l?void 0:l.searchOptions)||o};return u.options&&(null===(a=u.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{r.get().callGraphQL({values:u,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}buildDescriptionCacheKey(e,t){return`${e}__${t}`}async loadByCode(e,t,n,i){const o=this.buildDescriptionCacheKey(e,t),r=m.DESCRIPTIONS_BY_CODE[o];if(r)return Promise.resolve(r);const a=await this.loadAdvancedSearch(e,void 0,n,i,t);return m.DESCRIPTIONS_BY_CODE[o]=a,a}loadAdvancedSearch(e,o,a,s,l){var u,c,d,f,m,p;const h=this.applySearchListener(v.beforeSearch,e,o,a,s),N={argument:(null==h?void 0:h.argument)||o,criteria:(null==h?void 0:h.criteria)||a,searchOptions:Object.assign(Object.assign({},s),null==h?void 0:h.searchOptions)},S={query:{$:null===(u=N.criteria)||void 0===u?void 0:u.expression}};(null===(d=null===(c=N.criteria)||void 0===c?void 0:c.params)||void 0===d?void 0:d.length)>0&&(S.params={param:N.criteria.params.map((e=>{let o=e.value;if("string"==typeof o){const e=/CTX\{([^}]+)\}/.exec(o);e&&(o=n.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${e[1]})__`))}if(e.dataType===t.NUMBER&&void 0===o)throw new i("Falha detectada",`O campo ${e.name} deve ser informado.`);let r=e.dataType;return r===t.OBJECT?(o=o.value,r="S"):r=g(e.dataType),{$:o,type:r}}))});const y=null!=s?Object.assign(Object.assign({},null==N?void 0:N.searchOptions),{pkFieldName:s.codeFieldName,label:s.descriptionFieldName,fieldName:s.codeFieldName,useDescriptionOptions:!1,enableRowsCounter:!0,limit:s.limit}):void 0,O={serviceName:"PesquisaSP.getSuggestion",requestBody:{criteria:Object.assign({entityName:e,compacted:!1,ignoreEntityCriteria:null!==(f=null==y?void 0:y.ignoreEntityCriteria)&&void 0!==f&&f,limit:null!==(m=null==y?void 0:y.limit)&&void 0!==m?m:this._defaultPageSize,orderByDesc:!1,externalCriteria:S,localEntityName:null===(p=N.searchOptions)||void 0===p?void 0:p.rootEntity},{options:y}),clientEventList:{clientEvent:[]}}};null==l?O.requestBody.criteria.query={$:o}:O.requestBody.criteria.pk={$:l};const b={urlParams:{quietMode:!0}};return new Promise(((e,t)=>{r.get().callServiceBroker("PesquisaSP.getSuggestion",JSON.stringify(O),b).then((t=>e(t))).catch((e=>t(e)))}))}addSearchListener(e,t,n){var i;const o=this._searchListenersByDataUnit.get(t)||[],r=o.find((t=>t.entity===e));if(r){for(const e of Object.keys(n))if(e in r.listener){if((null===(i=r.listener[e])||void 0===i?void 0:i.toString())===n[e].toString())continue;r.listener[e]=n[e]}}else this._searchListenersByDataUnit.set(t,[...o,{entity:e,listener:n}]);return()=>{const n=o.filter((t=>t.entity!==e));n.length?this._searchListenersByDataUnit.set(t,n):this._searchListenersByDataUnit.delete(t)}}applySearchListener(e,t,n,i,o){var r;const a=null==o?void 0:o.dataUnitId;if(!a)return;const s=null===(r=this._searchListenersByDataUnit.get(a))||void 0===r?void 0:r.find((({entity:e})=>e===t));if(!s)return;const{listener:l}=s;return e in l?l[e]({argument:n,criteria:i,searchOptions:o}):void 0}async loadPresentationConfig(e){var t,n;let i=function(e){return{config:{chave:`PesquisaContent:${e}`,tipo:"T"}}}(e);const o=await r.get().callServiceBroker("SystemUtilsSP.getConf",JSON.stringify(i));return null!==(n=null===(t=null==o?void 0:o.config)||void 0===t?void 0:t.lastUsedMode)&&void 0!==n?n:"list"}async savePresentationConfig(e,t){let n=function(e,t){return{config:{lastUsedMode:t,chave:`PesquisaContent:${e}`,tipo:"T"}}}(e,t);await r.get().callServiceBroker("SystemUtilsSP.saveConf",JSON.stringify(n))}async loadPesquisaGridConfig(e){const t=function(e){return{gridConfig:{configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`}}}(e);return function(e){var t,n;const i=[],o=null!==(n=null===(t=null==e?void 0:e.gridConfig)||void 0===t?void 0:t.field)&&void 0!==n?n:{};if(Object.keys(o).forEach((e=>i.push(o[e]))),i.length)return{columns:i}}(await r.get().callServiceBroker("GridConfig.getGridConfigFromJson",JSON.stringify(t)))}async savePesquisaGridConfig(e,t){const n=function(e,t){const n={};return null==t||t.forEach(((e,t)=>n[`field${t}`]=e)),{gridConfig:{compactMode:!0,configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`,field:n}}}(e,t);await r.get().callServiceBroker("GridConfig.saveGridConfigFromJSON",JSON.stringify(n))}async loadTree(e,t,n,i){const o=this.buildLoadTreeRequestBody(e,t,n,i);return(null!==(s=null===(a=(await r.get().callServiceBroker("Pesquisa.getStructuredData",JSON.stringify(o))).arvore)||void 0===a?void 0:a.no)&&void 0!==s?s:[]).map(c);var a,s}buildLoadTreeRequestBody(e,t,n,i){var o,r;const a=this.applySearchListener(v.beforeSearch,e,t,n,i),s=null!==(o=null==a?void 0:a.searchOptions)&&void 0!==o?o:i,l=null==s?void 0:s.rootEntity,u=null==s?void 0:s.codeFieldName,c=null===(r=null==a?void 0:a.criteria)||void 0===r?void 0:r.expression,d=this.buildParams(a),f={nome:e,nomeInstanciaLocal:l,codeFieldName:u};return c&&(f.criterioLiteral={expressao:{$:c},parametro:d}),{instancia:f}}buildParams(e){var t,n;let i=null!==(n=null===(t=null==e?void 0:e.criteria)||void 0===t?void 0:t.params)&&void 0!==n?n:[];return i=i.map((e=>Object.assign(Object.assign({},e),{tipo:g(e.dataType),$:e.value}))),i}}function g(e){switch(e){case t.NUMBER:return"I";case t.DATE:return"D";default:return"S"}}m.DESCRIPTIONS_BY_CODE={},function(e){e.beforeSearch="beforeSearch"}(v||(v={})),function(e){e.LINK_AND_FILE_AT_THE_SAME_TIME="LINK_AND_FILE_AT_THE_SAME_TIME",e.ANY_LINK_OR_FILE_FILLED="ANY_LINK_OR_FILE_FILLED",e.UNKNOWN="UNKNOWN",e.DESCRIPTION_CANNOT_BE_CHANGED="DESCRIPTION_CANNOT_BE_CHANGED"}(f||(f={}));export{m as P,f as S,d as a,a as b}
@@ -1 +1 @@
1
- import{r as i,e as t,h as s,g as e,f as h}from"./p-2c9d0870.js";import{ElementIDUtils as o,ObjectUtils as a,ApplicationContext as n}from"@sankhyalabs/core";import{S as d}from"./p-1cc4cf61.js";import{R as l}from"./p-688dcb4c.js";import{buildFormConfigFromDataUnit as r}from"@sankhyalabs/ezui/dist/collection/utils/form";import{ApplicationUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{U as f}from"./p-d88278f8.js";import{a as g,G as u}from"./p-9019a32f.js";import{b as m,a as v,c as p,d as C,g as y,u as b,e as k}from"./p-8b4d6719.js";import"./p-51e853f2.js";import"./p-5d02c032.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";const w=class{constructor(s){i(this,s),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 s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async setFieldProp(i,t,s){await this._form.setFieldProp(i,t,s)}async validate(){await this._form.validate()}closeConfig(){this.hideConfig()}dataunitReady(){o.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 l.getResourceID()),this._configManager=new d(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of s||[]){if(!i)continue;const s=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(s||0===s)&&(await this.setFieldProp(i,"precision",s),await this.setFieldProp(i,"prettyPrecision",s))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return s("section",null,s("div",{class:"ez-row"},s("div",{class:"ez-col ez-col--sd-12"},s("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&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return e(this)}};w.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const F=class{constructor(s){i(this,s),this.configClose=t(this,"configClose",7),this.configChange=t(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0,this.customGuidesConfig=[]}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,await this.loadConfigByUser(),this.selectedGuide=void 0,this.optionConfigChanged=!a.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===f.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t;this.selectedGuide?this.selectedGuide.isCustom||this.selectedGuide.isDetail?this.showCanNotAddFieldToGuideDialog():(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i))):this.showNoGuideSelectedDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t;const s=null!==(t=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==t?t:[];this.groupsList=[...s]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");c.alert(i,t)}showCanNotAddFieldToGuideDialog(){const i=this.getMessage("snkFormConfig.canNotAddFieldToGuide.title"),t=this.getMessage("snkFormConfig.canNotAddFieldToGuide.message");c.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?f.DEFAULT:f.USER;this.configSelected=null==i?void 0:i.find((i=>i.origin===t)),this.originalConfigSelected=null==i?void 0:i.find((i=>i.origin===t))}catch(i){console.error(this.getMessage("snkFormConfig.errors.failFetchUserConfig")),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===f.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const h=t.some((({name:t})=>t===i));return h||!0!==e.visibleOnConfig||s?!0===s&&!1===h:e.visibleOnConfig}))}getInitialOrder(i){var t,s;return Array.isArray(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?null===(s=this._formConfig.tabs)||void 0===s?void 0:s.length:i.length>0?Math.max(...i.map((i=>i.order))):0}loadGuides(){var i;this.guidesList=[],this.guidesList.push(...m(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"))),this.guidesList.push(...v(this.dataUnit,this.getInitialOrder(this.guidesList),this.guidesList)),this.guidesList.push(...p(this.customGuidesConfig,this.guidesList)),this.guidesMap=C(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,this.getMessage("snkFormConfig.form.tabGeneral"))}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=r(this.dataUnit)),a.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i])}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===f.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===g.main?i.name:i.label,order:i.name===g.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?f.USER:f.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,c.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){if(this.getIsDefaultConfig()){const i=this._formConfig;return i.defaultConfiguration=!0,i}const i=a.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=y(this.guidesMap),i.defaultConfiguration=!1,i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,h=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],o=[];h.forEach((i=>o.push(...i.fields))),this.availableFields=[...this.availableFields,...o],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=null!==(t=this.guidesMap.get(this.selectedGuide.name))&&void 0!==t?t:[],e=b(s,i);this.guidesMap.delete(this.selectedGuide.name),this.guidesMap.set(i,e);const h={name:i,label:i,visible:this.selectedGuide.visible,order:this.selectedGuide.order};this.guidesList=[...this.guidesList.map((i=>i.name===this.selectedGuide.name?h:i))],this.groupsList=[...e],this.selectedGuide=h,this.hasChanges=!0}handleCreateNewGuide(){const i=k(this.guidesList,this.getMessage.bind(this)),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:u.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=n.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){return s(h,null,s("config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"ez-padding--medium"},s("div",{class:"ez-flex sidebarNavigator__container"},s("guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)}),s("fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this),messagesBuilder:this.messagesBuilder}))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};F.style='.sc-snk-form-config-h{display:flex;flex-direction:column;height:100vh;width:100vw;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.sidebarNavigator__container.sc-snk-form-config{height:var(--snk-form-config-container-height);gap:20px;align-items:flex-start}.guide-header.sc-snk-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{w as snk_form,F as snk_form_config}
1
+ import{r as i,e as t,h as s,g as e,f as h}from"./p-2c9d0870.js";import{ElementIDUtils as o,ObjectUtils as a,ApplicationContext as n}from"@sankhyalabs/core";import{S as d}from"./p-8d513b64.js";import{R as l}from"./p-688dcb4c.js";import{buildFormConfigFromDataUnit as r}from"@sankhyalabs/ezui/dist/collection/utils/form";import{ApplicationUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{U as f}from"./p-d7657667.js";import{a as g,G as u}from"./p-9019a32f.js";import{b as m,a as v,c as p,d as C,g as b,u as y,e as k}from"./p-8b4d6719.js";import"./p-13f91e7e.js";import"./p-10d883b0.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";const w=class{constructor(s){i(this,s),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 s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async setFieldProp(i,t,s){await this._form.setFieldProp(i,t,s)}async validate(){await this._form.validate()}closeConfig(){this.hideConfig()}dataunitReady(){o.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 l.getResourceID()),this._configManager=new d(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of s||[]){if(!i)continue;const s=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(s||0===s)&&(await this.setFieldProp(i,"precision",s),await this.setFieldProp(i,"prettyPrecision",s))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return s("section",null,s("div",{class:"ez-row"},s("div",{class:"ez-col ez-col--sd-12"},s("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&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return e(this)}};w.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const F=class{constructor(s){i(this,s),this.configClose=t(this,"configClose",7),this.configChange=t(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0,this.customGuidesConfig=[]}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,await this.loadConfigByUser(),this.selectedGuide=void 0,this.optionConfigChanged=!a.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===f.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t;this.selectedGuide?this.selectedGuide.isCustom||this.selectedGuide.isDetail?this.showCanNotAddFieldToGuideDialog():(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i))):this.showNoGuideSelectedDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t;const s=null!==(t=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==t?t:[];this.groupsList=[...s]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");c.alert(i,t)}showCanNotAddFieldToGuideDialog(){const i=this.getMessage("snkFormConfig.canNotAddFieldToGuide.title"),t=this.getMessage("snkFormConfig.canNotAddFieldToGuide.message");c.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?f.DEFAULT:f.USER;this.configSelected=null==i?void 0:i.find((i=>i.origin===t)),this.originalConfigSelected=null==i?void 0:i.find((i=>i.origin===t))}catch(i){console.error(this.getMessage("snkFormConfig.errors.failFetchUserConfig")),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===f.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const h=t.some((({name:t})=>t===i));return h||!0!==e.visibleOnConfig||s?!0===s&&!1===h:e.visibleOnConfig}))}getInitialOrder(i){var t,s;return Array.isArray(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?null===(s=this._formConfig.tabs)||void 0===s?void 0:s.length:i.length>0?Math.max(...i.map((i=>i.order))):0}loadGuides(){var i;this.guidesList=[],this.guidesList.push(...m(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"))),this.guidesList.push(...v(this.dataUnit,this.getInitialOrder(this.guidesList),this.guidesList)),this.guidesList.push(...p(this.customGuidesConfig,this.guidesList)),this.guidesMap=C(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,this.getMessage("snkFormConfig.form.tabGeneral"))}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=r(this.dataUnit)),a.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i])}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===f.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===g.main?i.name:i.label,order:i.name===g.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?f.USER:f.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,c.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){if(this.getIsDefaultConfig()){const i=this._formConfig;return i.defaultConfiguration=!0,i}const i=a.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=b(this.guidesMap),i.defaultConfiguration=!1,i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,h=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],o=[];h.forEach((i=>o.push(...i.fields))),this.availableFields=[...this.availableFields,...o],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=null!==(t=this.guidesMap.get(this.selectedGuide.name))&&void 0!==t?t:[],e=y(s,i);this.guidesMap.delete(this.selectedGuide.name),this.guidesMap.set(i,e);const h={name:i,label:i,visible:this.selectedGuide.visible,order:this.selectedGuide.order};this.guidesList=[...this.guidesList.map((i=>i.name===this.selectedGuide.name?h:i))],this.groupsList=[...e],this.selectedGuide=h,this.hasChanges=!0}handleCreateNewGuide(){const i=k(this.guidesList,this.getMessage.bind(this)),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:u.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=n.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){return s(h,null,s("config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"ez-padding--medium"},s("div",{class:"ez-flex sidebarNavigator__container"},s("guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)}),s("fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this),messagesBuilder:this.messagesBuilder}))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};F.style='.sc-snk-form-config-h{display:flex;flex-direction:column;height:100vh;width:100vw;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.sidebarNavigator__container.sc-snk-form-config{height:var(--snk-form-config-container-height);gap:20px;align-items:flex-start}.guide-header.sc-snk-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{w as snk_form,F as snk_form_config}