@sankhyalabs/sankhyablocks 8.16.0-dev.73 → 8.16.0-dev.75

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/dist/cjs/{ContinuousInsertUtils-6e536e37.js → ContinuousInsertUtils-b5de47db.js} +2 -2
  2. package/dist/cjs/{dataunit-fetcher-8ea97d88.js → dataunit-fetcher-c32fdff7.js} +171 -17
  3. package/dist/cjs/{pesquisa-fetcher-3b86b6c4.js → pesquisa-fetcher-36d039c4.js} +4 -0
  4. package/dist/cjs/pesquisa-grid_2.cjs.entry.js +2 -2
  5. package/dist/cjs/snk-actions-button_5.cjs.entry.js +2 -2
  6. package/dist/cjs/snk-application.cjs.entry.js +2 -2
  7. package/dist/cjs/snk-attach.cjs.entry.js +2 -2
  8. package/dist/cjs/snk-crud.cjs.entry.js +2 -2
  9. package/dist/cjs/snk-data-exporter.cjs.entry.js +3 -3
  10. package/dist/cjs/{snk-data-unit-72ef8777.js → snk-data-unit-2c7c1964.js} +1 -1
  11. package/dist/cjs/snk-data-unit.cjs.entry.js +2 -2
  12. package/dist/cjs/snk-detail-view.cjs.entry.js +3 -3
  13. package/dist/cjs/snk-grid.cjs.entry.js +3 -3
  14. package/dist/cjs/{snk-guides-viewer-84cb012b.js → snk-guides-viewer-a651b9b8.js} +2 -2
  15. package/dist/cjs/snk-guides-viewer.cjs.entry.js +3 -3
  16. package/dist/cjs/snk-pesquisa.cjs.entry.js +2 -2
  17. package/dist/cjs/snk-simple-crud.cjs.entry.js +3 -3
  18. package/dist/collection/components/snk-pesquisa/pesquisaHelper.js +4 -0
  19. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +57 -12
  20. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.js +108 -0
  21. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +9 -8
  22. package/dist/components/ISave.js +4 -0
  23. package/dist/components/dataunit-fetcher.js +171 -17
  24. package/dist/esm/{ContinuousInsertUtils-91011e01.js → ContinuousInsertUtils-213385f5.js} +2 -2
  25. package/dist/esm/{dataunit-fetcher-8dd93d8b.js → dataunit-fetcher-26c2bed4.js} +171 -17
  26. package/dist/esm/{pesquisa-fetcher-767abffa.js → pesquisa-fetcher-aab1fe14.js} +4 -0
  27. package/dist/esm/pesquisa-grid_2.entry.js +2 -2
  28. package/dist/esm/snk-actions-button_5.entry.js +2 -2
  29. package/dist/esm/snk-application.entry.js +2 -2
  30. package/dist/esm/snk-attach.entry.js +2 -2
  31. package/dist/esm/snk-crud.entry.js +2 -2
  32. package/dist/esm/snk-data-exporter.entry.js +3 -3
  33. package/dist/esm/{snk-data-unit-11a49fc3.js → snk-data-unit-a36df23f.js} +1 -1
  34. package/dist/esm/snk-data-unit.entry.js +2 -2
  35. package/dist/esm/snk-detail-view.entry.js +3 -3
  36. package/dist/esm/snk-grid.entry.js +3 -3
  37. package/dist/esm/{snk-guides-viewer-45ee10ff.js → snk-guides-viewer-cbd8511f.js} +2 -2
  38. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  39. package/dist/esm/snk-pesquisa.entry.js +2 -2
  40. package/dist/esm/snk-simple-crud.entry.js +3 -3
  41. package/dist/sankhyablocks/{p-1a91d1f3.entry.js → p-045398fb.entry.js} +1 -1
  42. package/dist/sankhyablocks/{p-853074f4.entry.js → p-167ac365.entry.js} +3 -3
  43. package/dist/sankhyablocks/{p-cfd229f4.entry.js → p-2098a093.entry.js} +1 -1
  44. package/dist/sankhyablocks/{p-1bab295e.entry.js → p-3b2e5822.entry.js} +1 -1
  45. package/dist/sankhyablocks/{p-6cfa8913.js → p-4ec70a7b.js} +1 -1
  46. package/dist/sankhyablocks/{p-035c63df.entry.js → p-70a546e9.entry.js} +1 -1
  47. package/dist/sankhyablocks/{p-60e4db34.js → p-70ae0779.js} +1 -1
  48. package/dist/sankhyablocks/{p-0e6874ca.entry.js → p-76041b30.entry.js} +1 -1
  49. package/dist/sankhyablocks/p-78d49c74.js +60 -0
  50. package/dist/sankhyablocks/{p-6e0adddc.entry.js → p-7a95cbc7.entry.js} +1 -1
  51. package/dist/sankhyablocks/{p-e74eb86d.entry.js → p-92dd432c.entry.js} +1 -1
  52. package/dist/sankhyablocks/{p-1c2d8a9a.entry.js → p-9f9128d3.entry.js} +1 -1
  53. package/dist/sankhyablocks/{p-dd7fb984.entry.js → p-b5ebc20a.entry.js} +1 -1
  54. package/dist/sankhyablocks/{p-03e37897.entry.js → p-b738af3a.entry.js} +1 -1
  55. package/dist/sankhyablocks/{p-935aa4fa.entry.js → p-bfdc08f2.entry.js} +1 -1
  56. package/dist/sankhyablocks/{p-4fe8bb73.js → p-c9f22653.js} +1 -1
  57. package/dist/sankhyablocks/{p-ee759111.js → p-dd37be7e.js} +1 -1
  58. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  59. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.d.ts +9 -1
  60. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.d.ts +6 -0
  61. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.d.ts +4 -0
  62. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +3 -3
  63. package/package.json +1 -1
  64. package/dist/sankhyablocks/p-ddefbbc7.js +0 -60
@@ -1,11 +1,11 @@
1
- import{r as t,c as i,h as e,H as s,g as n}from"./p-d2d301a6.js";import{DateUtils as r,StringUtils as a,ObjectUtils as o,WaitingChangeException as c,WarningException as h,ErrorException as l,KeyboardManager as u,OnboardingUtils as d,DependencyType as p,ArrayUtils as m,SearchUtils as w,ElementIDUtils as y,ApplicationContext as f,DataType as g,ErrorTracking as v,UserAgentUtils as P,LockManager as _,LockManagerOperation as A}from"@sankhyalabs/core";import{ApplicationUtils as I}from"@sankhyalabs/ezui/dist/collection/utils";import{C as k}from"./p-19dc71e9.js";import{d as S,D as b,U as T}from"./p-d62228fb.js";import{A as L,a as C}from"./p-f0b9303b.js";import{P as N,D as E}from"./p-ddefbbc7.js";import{P as D}from"./p-4fe8bb73.js";import{S as O}from"./p-17425c72.js";import"./p-1435701f.js";import"./p-ff1990ad.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class z{static webConnectionCaller(t,i,e){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,i,e)}}const R=x;function x(t,i){const e=M();return(x=function(t){return e[t-=378]})(t,i)}function M(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(M=function(){return t})()}!function(){const t=x,i=M();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;i.push(i.shift())}catch(t){i.push(i.shift())}}();class U{[R(397)](t){const i=R;if(typeof(t=utxt(t[i(390)]))==i(392)&&(t=JSON[i(400)](t)),null==t)throw Error(i(395));const e=new j("S"===t[i(402)]||!0===t[i(402)]);return Array[i(394)](t[i(391)])&&t[i(391)][i(385)]((t=>e.putAccess(t[i(382)],String(t.status)==i(398)))),e}}class j{constructor(t){const i=R;this.isSup=t,this[i(384)]={}}[R(378)](t,i){this[R(384)][t]=i}[R(393)](t){const i=R;if(this[i(402)])return!0;let e=!0;return this[i(384)][i(380)](t)&&(e=this.actions[t]),e}isUserSup(){return this.isSup}}class F{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[i,e]=t.split("__=__");this._embeddedParams.set(i,e)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",S.gql`query($name: String!) {
1
+ import{r as t,c as i,h as e,H as s,g as n}from"./p-d2d301a6.js";import{DateUtils as r,StringUtils as a,ObjectUtils as o,WaitingChangeException as c,WarningException as h,ErrorException as l,KeyboardManager as u,OnboardingUtils as d,DependencyType as p,ArrayUtils as m,SearchUtils as w,ElementIDUtils as y,ApplicationContext as f,DataType as g,ErrorTracking as v,UserAgentUtils as P,LockManager as _,LockManagerOperation as A}from"@sankhyalabs/core";import{ApplicationUtils as I}from"@sankhyalabs/ezui/dist/collection/utils";import{C as k}from"./p-19dc71e9.js";import{d as S,D as T,U as L}from"./p-d62228fb.js";import{A as b,a as C}from"./p-f0b9303b.js";import{P as N,D as E}from"./p-78d49c74.js";import{P as D}from"./p-c9f22653.js";import{S as O}from"./p-17425c72.js";import"./p-1435701f.js";import"./p-ff1990ad.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class z{static webConnectionCaller(t,i,e){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,i,e)}}const R=x;function x(t,i){const e=M();return(x=function(t){return e[t-=378]})(t,i)}function M(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(M=function(){return t})()}!function(){const t=x,i=M();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;i.push(i.shift())}catch(t){i.push(i.shift())}}();class U{[R(397)](t){const i=R;if(typeof(t=utxt(t[i(390)]))==i(392)&&(t=JSON[i(400)](t)),null==t)throw Error(i(395));const e=new j("S"===t[i(402)]||!0===t[i(402)]);return Array[i(394)](t[i(391)])&&t[i(391)][i(385)]((t=>e.putAccess(t[i(382)],String(t.status)==i(398)))),e}}class j{constructor(t){const i=R;this.isSup=t,this[i(384)]={}}[R(378)](t,i){this[R(384)][t]=i}[R(393)](t){const i=R;if(this[i(402)])return!0;let e=!0;return this[i(384)][i(380)](t)&&(e=this.actions[t]),e}isUserSup(){return this.isSup}}class F{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[i,e]=t.split("__=__");this._embeddedParams.set(i,e)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",S.gql`query($name: String!) {
2
2
  $queryAlias$: fetchResource(name: $name){
3
3
  name
4
4
  resource
5
5
  }
6
- }`)}async getParam(t){if(this._embeddedParams.has(t))return Promise.resolve(this._embeddedParams.get(t));if(this._cachedParams.has(t))return this._cachedParams.get(t);const i=`param://application?params=${t}`,e=await b.get().callGraphQL({values:{name:i},query:this.templateByQuery.get("fetchParam")});return this._cachedParams.set(t,e),e}async asString(t){const i=await this.getParam(t);return this.getValue(i)}async asInteger(t){const i=await this.getParam(t);return parseInt(this.getValue(i))}async asFloat(t){const i=await this.getParam(t);return parseFloat(this.getValue(i))}async asBoolean(t){const i=await this.getParam(t);return"S"===this.getValue(i)}async asDate(t){const i=await this.getParam(t);return r.strToDate(this.getValue(i))}async getBatchParams(t){const i=await this.getParam(t.join(",")),e={};return i.forEach((t=>e[t.name]=t.resource)),e}getValue(t={}){if(Array.isArray(t)&&t.length>0&&(t=t[0]),"string"==typeof t)return t;if(a.isEmpty(t.resource))return"";try{const i=o.stringToObject(t.resource),[e]=Object.keys(i);return i[e]}catch(t){console.warn("Erro ao converter string JSON.")}}}class ${constructor(){this.templateByQuery=new Map,this.cancel=[],this.buildTemplates()}buildTemplates(){this.templateByQuery.set("fetchTotals",S.gql`query($filters: [InputFilter!] $name: String!) {
6
+ }`)}async getParam(t){if(this._embeddedParams.has(t))return Promise.resolve(this._embeddedParams.get(t));if(this._cachedParams.has(t))return this._cachedParams.get(t);const i=`param://application?params=${t}`,e=await T.get().callGraphQL({values:{name:i},query:this.templateByQuery.get("fetchParam")});return this._cachedParams.set(t,e),e}async asString(t){const i=await this.getParam(t);return this.getValue(i)}async asInteger(t){const i=await this.getParam(t);return parseInt(this.getValue(i))}async asFloat(t){const i=await this.getParam(t);return parseFloat(this.getValue(i))}async asBoolean(t){const i=await this.getParam(t);return"S"===this.getValue(i)}async asDate(t){const i=await this.getParam(t);return r.strToDate(this.getValue(i))}async getBatchParams(t){const i=await this.getParam(t.join(",")),e={};return i.forEach((t=>e[t.name]=t.resource)),e}getValue(t={}){if(Array.isArray(t)&&t.length>0&&(t=t[0]),"string"==typeof t)return t;if(a.isEmpty(t.resource))return"";try{const i=o.stringToObject(t.resource),[e]=Object.keys(i);return i[e]}catch(t){console.warn("Erro ao converter string JSON.")}}}class ${constructor(){this.templateByQuery=new Map,this.cancel=[],this.buildTemplates()}buildTemplates(){this.templateByQuery.set("fetchTotals",S.gql`query($filters: [InputFilter!] $name: String!) {
7
7
  $queryAlias$: fetchTotals(name: $name, filters: $filters ){
8
8
  name
9
9
  value
10
10
  }
11
- }`)}fetchTotals(t,i,e=[]){const s=`${t}_${i}`,n=this.cancel.findIndex((t=>t[s]));return n>=0&&(this.cancel[n][s](),this.cancel.splice(n,1)),Promise.race([new Promise((t=>this.cancel.push({[s]:t}))),this.getTotals(t,i,e)]).then((t=>{let i=new Map;if(t){i=t;const e=this.cancel.findIndex((t=>t[s]));e>=0&&this.cancel.splice(e,1)}return i}))}getTotals(t,i,e=[]){return new Promise(((s,n)=>{b.get().callGraphQL({query:this.templateByQuery.get("fetchTotals"),values:{name:`totals://${t}/${i}`,filters:e}}).then((t=>{if(t.length>0){const i=new Map;return t.forEach((t=>i.set(t.name,parseFloat(t.value)))),s(i)}return n("Não foi possível recuperar os totalizadores")})).catch(n)}))}}function q(){const t=["2909523kXwted","CompanyName=Sankhya Jiva Tecnologia e Inovao Ltda,LicensedApplication=Sankhya Gestao,LicenseType=SingleApplication,LicensedConcurrentDeveloperCount=2,LicensedProductionInstancesCount=0,AssetReference=AG-019460,ExpiryDate=9_November_2022_[v2]_MTY2Nzk1MjAwMDAwMA==10487151e296ee4360f80961ca960869","1131048CARoeW","502909mLEPmu","447255iQEXuN","428UHbJwW","270AFTxAV","194369jhGqTI","1540nWuTrj","2044062GicUQI","30CkXPWg"];return(q=function(){return t})()}const B=H;function H(t,i){const e=q();return(H=function(t){return e[t-=392]})(t,i)}!function(){const t=H,i=q();for(;;)try{if(951926==-parseInt(t(398))/1+-parseInt(t(393))/2+parseInt(t(395))/3+-parseInt(t(400))/4*(parseInt(t(392))/5)+-parseInt(t(401))/6*(-parseInt(t(402))/7)+parseInt(t(397))/8+-parseInt(t(399))/9*(-parseInt(t(394))/10))break;i.push(i.shift())}catch(t){i.push(i.shift())}}();const K=B(396);var V;class G{static openAppActivity(t,i){var e;null===(e=window.workspace)||void 0===e||e.openAppActivity(t,i)}static getAppLabel(t){if(null!=(null===window||void 0===window?void 0:window.workspace))return null==window.workspace.getAppLabel&&(window.workspace.getAppLabel=t=>(t||"").split(".").pop()),window.workspace.getAppLabel(t)}static setScreenToUseV3Layout(){var t;null===(t=window.workspace)||void 0===t||t.setScreenToUseV3Layout()}static setScreenToUseOldLayout(){var t;null===(t=window.workspace)||void 0===t||t.setScreenToUseOldLayout()}static showDesktop(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.showDesktop)||void 0===i||i.call(t)}static searchApp(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.searchApp)||void 0===i||i.call(t)}static openHelp(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.openHelp)||void 0===i||i.call(t)}static applicationClick(){var t,i;(null===(t=window.workspace)||void 0===t?void 0:t.applicationClick)&&(null===(i=window.workspace)||void 0===i||i.applicationClick())}}G.resourceID=null===(V=window.workspace)||void 0===V?void 0:V.resourceID;class W{constructor(t){this._app=t,window.addEventListener("error",(t=>this.errorHandler(t))),window.addEventListener("unhandledrejection",(t=>this.rejectionHandler(t)))}rejectionHandler(t){const i=t.reason;i instanceof c||(i?this.processException(i):this._app.isDebugMode().then((t=>{t&&this._app.error("Promise rejeitada","Erro interno: Uma promise foi rejeitada sem razão determinada.")})))}errorHandler(t){this.processException(t.error)}buildErrorCodeHTML(t){return'<br><a href="#" onclick="try{window.workspace.openHelp(\'_tbcode:'+t+"')} catch(e){alert('Não é possível abrir a ajuda fora do workspace Sankhya');}\">Código: "+t+"</a>"}processException(t){t.errorCode&&(t.message+=this.buildErrorCodeHTML(t.errorCode)),t instanceof c||t instanceof h?this._app.alert(t.title,t.message):t instanceof l?this._app.error(t.title,t.message):this._app.isDebugMode().then((i=>{if(i)if(t instanceof Error)this._app.error(t.name,t.message);else{const i=(null==t?void 0:t.title)||"Erro detectado",e="string"==typeof t?t:t.message||`Erro interno "${o.objectToString(t)}"`;this._app.error(i,e)}}))}}class J{constructor(){this._debounceTime=1500,this.requests=new Map,this.requestsLoadingBar=[]}onRequestStart(t){if(t.url.includes("quietMode=true"))return;this.requestsLoadingBar.push(t.requestId);const i=setTimeout((()=>{this.ezLoadingBar.show()}),this._debounceTime);this.requests.set(t.requestId,i)}onRequestEnd(t){var i,e,s;const n=this.requests.get(t.requestId);clearTimeout(n),(null===(i=this.requestsLoadingBar)||void 0===i?void 0:i.includes(t.requestId))&&(this.requestsLoadingBar=null===(e=this.requestsLoadingBar)||void 0===e?void 0:e.filter((i=>i!==t.requestId)),!this.requestsLoadingBar.length&&(null===(s=this.ezLoadingBar)||void 0===s||s.hide()))}}class Y{constructor(){this._debounceTime=1e3,this._ignoredNameTypes=["totals"],this._countRequest=0}onRequestStart(t){this.isIgnoreLoadingOnRequest(t)||(this._countRequest++,this.ezLoadingBar.show(),this._timerLoading&&clearTimeout(this._timerLoading))}onRequestEnd(t){this.isIgnoreLoadingOnRequest(t)||(this._countRequest--,this._timerLoading=setTimeout((()=>{this._countRequest<=0&&this.ezLoadingBar.hide()}),this._debounceTime))}isIgnoreLoadingOnRequest(t){if(null==t)return!1;if(t.url.includes("quietMode=true"))return!0;if(null==t.requestBody)return!1;if(1==t.requestBody.length){const{name:i}=t.requestBody[0].variables;if(i){const t=i.split(":");return this._ignoredNameTypes.indexOf(t[0])>=0}}return!1}}class X{static create({strategy:t}){switch(t){case"request_name":return new Y;case"request_time":return new J;default:throw new Error("Strategy not found")}}}const Z=class{constructor(e){t(this,e),this.applicationLoaded=i(this,"applicationLoaded",7),this.applicationLoading=i(this,"applicationLoading",7),this.NEW_VERSION_POPUP_LOCKER="NEW_VERSION_POPUP_LOCKER",this._authPromises=[],this._keyboardManager=new u,this._waitingAppReady=new Array,this._duCache=new Map,this._duPromises=new Map,this._requestListener=X.create({strategy:"request_time"}),this._maxTimeLockAppLoading=1e4,this._isBrowserTypeElectron=!1,this._pendingActions=new Map,this._loadPkParameter=null,this._isLoadedByPk=!1,this._applicationReady=!1,this.enableLockManagerLoadingApp=void 0,this.messagesBuilder=void 0,this.configName=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.loadByPK=void 0}async processPendingActions(t){const i=this._pendingActions.get(t);i&&i.length&&(i.forEach((t=>t())),this._pendingActions.set(t,[]))}get parameters(){return this._parameters||(this._parameters=new F),this._parameters}async getAuth(t){return null==t?this.getApplicationAuth():new Promise(((i,e)=>{this.authFetcher.getData(t).then((t=>{i(t)})).catch((t=>{e(t)}))}))}async getApplicationAuth(){return this._auth?Promise.resolve(this._auth):new Promise(((t,i)=>{const e=this._authPromises.length>0;this._authPromises.push(new Q(t,i)),e||this.authFetcher.getData(this.applicationResourceID).then((t=>{for(this._auth=t;this._authPromises.length>0;)this._authPromises.pop().resolve(this._auth)})).catch((t=>{for(;this._authPromises.length>0;)this._authPromises.pop().reject(t)}))}))}watchPropHandler(t,i){t&&this._loadPkParameter&&(this.loadByPK(this._loadPkParameter.pk,this._loadPkParameter.redirect),this._loadPkParameter=null)}async getKeyboardManager(){return Promise.resolve(this._keyboardManager)}async isUserSup(){return new Promise(((t,i)=>{this.getAuth().then((e=>{this.getAuthList(e).then((i=>{t(i.isSup)})).catch((t=>i(t)))}))}))}async addPendingAction(t,i){var e;const s=null!==(e=this._pendingActions.get(t))&&void 0!==e?e:[];this._pendingActions.set(t,[...s,i])}async callServiceBroker(t,i,e){return b.get().callServiceBroker(t,i,e)}async initOnboarding(t){this.hasToShowNewVersionPopup()?await this.addPendingAction(this.NEW_VERSION_POPUP_LOCKER,(()=>this.doInitOnboarding(t))):this.doInitOnboarding(t)}doInitOnboarding(t){d.getInstance().init(t,window.envContext)}async hasAccess(t,i){return new Promise(((e,s)=>{this.getAuth(i).then((i=>{this.getAuthList(i).then((i=>{e(i.isSup||i.actions[t])})).catch((t=>s(t)))}))}))}async getAllAccess(t){return new Promise(((i,e)=>{this.getAuth(t).then((t=>{this.getAuthList(t).then((t=>{const e={};e.isSup=t.isSup,Object.entries(L).forEach((i=>{e[i[0]]=t.actions[i[1]]||!1})),i(e)})).catch((t=>e(t)))}))}))}async getStringParam(t){return this.parameters.asString(t)}async getIntParam(t){return this.parameters.asInteger(t)}async getFloatParam(t){return this.parameters.asFloat(t)}async getBooleanParam(t){return this.parameters.asBoolean(t)}async getDateParam(t){return this.parameters.asDate(t)}async showPopUp(t,i="full",e=!0,s){this.clearContent(this._popUp),this._popUp.addEventListener("ezClosePopup",(()=>{s()}),{once:!0}),this._popUp.appendChild(t),this._popUp.opened=!0,this._popUp.heightMode=i,this._popUp.useHeader=e,"EZ-MODAL-CONTAINER"===t.tagName&&(this._popUp.useHeader=!1)}async showModal(t){this.clearContent(this._rightModal),this._rightModal.appendChild(t),this._rightModal.opened=!0}showAlerts(t){return I.showAlerts({alerts:t})}async closeModal(){this.clearContent(this._rightModal),this._rightModal.opened=!1}async closePopUp(){this.clearContent(this._popUp),this._popUp.opened=!1,this._popUp.useHeader=!0,this._popUp.heightMode="full"}async temOpcional(t){const i=t.split(",");return new Promise(((t,e)=>{this.getAttributeFromHTMLWrapper("opc0009").then((s=>{"1"===s?t(!0):Promise.all(i.map((t=>this.getAttributeFromHTMLWrapper("opc"+t)))).then((i=>{t(i.includes("1"))})).catch((t=>{e(t)}))})).catch((t=>{e(t)}))}))}async getConfig(t){let i={serviceName:"SystemUtilsSP.getConf",requestBody:{config:{chave:t,tipo:"T"}}};return new Promise(((t,e)=>{b.get().callServiceBroker("SystemUtilsSP.getConf",JSON.stringify(i)).then((i=>{var e;return t(null===(e=i.config)||void 0===e?void 0:e.data)})).catch((t=>e(t)))}))}async saveConfig(t,i){let e={serviceName:"SystemUtilsSP.saveConf",requestBody:{config:{chave:t,tipo:"T",data:i}}};return new Promise(((t,i)=>{b.get().callServiceBroker("SystemUtilsSP.saveConf",JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}async getAttributeFromHTMLWrapper(t){return Promise.resolve(window[t])}async openApp(t,i){G.openAppActivity(t,i)}async webConnection(t,i,e){this.getStringParam(t).then((t=>{z.webConnectionCaller(t,i,e)}))}getDuPromissesStack(t){let i;return t&&(i=this._duPromises.get(t),i||(i=[],this._duPromises.set(t,i))),i||[]}async createDataunit(t,i,e,s,n){return null==n&&(n=this.applicationResourceID),new Promise(((r,a)=>{const o=this.getDuPromissesStack(i),c=o.length>0;if(o.push(new Q(r,a)),!c){const r=this.dataUnitFetcher.getDataUnit(t,n,e,s);r.loadMetadata().then((()=>{this.processResolveDataUnit(r,i,o)})).catch((t=>{for(;o.length>0;)o.pop().reject(t)}))}}))}processResolveDataUnit(t,i,e){for(i&&this.updateDataunitCache(void 0,i,t);e.length>0;)e.pop().resolve(t)}async updateDataunitCache(t,i,e){t&&this._duCache.delete(t),this._duCache.set(i,e)}async getDataUnit(t,i,e,s,n){return new Promise(((r,a)=>{const o=this._duCache.get(i);o?r(o):this.createDataunit(t,i,e,s,n).then((t=>{r(t)})).catch((t=>a(t)))}))}async addClientEvent(t,i){return new Promise((e=>{b.addClientEvent(t,i),e()}))}async removeClientEvent(t){return new Promise((i=>{b.removeClientEvent(t),i()}))}async hasClientEvent(t){return new Promise((i=>{i(b.hasClientEvent(t))}))}get applicationResourceID(){return this._applicationResourceID||(this._applicationResourceID=this.urlParams.get("workspaceResourceID")||this.urlParams.get("resourceID")||G.resourceID||"unknown.resource.id"),this._applicationResourceID}async getResourceID(){return Promise.resolve(this.applicationResourceID)}async getUserID(){return Promise.resolve(window.UID)}async alert(t,i,e,s){return I.alert(t,i,e,s)}async error(t,i,e,s){return I.error(t,i,e,s)}async success(t,i,e,s){return I.success(t,i,e,s)}async message(t,i,e,s){return I.message(t,i,e,s)}async confirm(t,i,e,s,n){return I.confirm(t,i,e,s,n)}async info(t,i){return I.info(t,i)}async loadTotals(t,i,e){return this.totalsFetcher.fetchTotals(t,i,e)}async isLoadedByPk(){return Promise.resolve(this._isLoadedByPk)}async preloadMangerRemoveRecord(t,i){const e=i.map((t=>({__record__id__:t})));N.removeRecords(t,e)}getCountSkeleton(t,i,e){let s=window.innerHeight-350;return e=e||20,Math.floor(s/(i+e))||1}async getAuthList(t){return await(new U).parseFromJSON(t)}get urlParams(){return this._urlParams||(this._urlParams=T.getQueryParams(location.search)),this._urlParams}getMessage(t,i){var e;return null===(e=this.messagesBuilder)||void 0===e?void 0:e.getMessage(t,i)}get dataUnitFetcher(){return this._dataUnitFetcher||(this._dataUnitFetcher=new E),this._dataUnitFetcher}get totalsFetcher(){return this._totalsFetcher||(this._totalsFetcher=new $),this._totalsFetcher}get pesquisaFetcher(){return this._pesquisaFetcher||(this._pesquisaFetcher=new D),this._pesquisaFetcher}get authFetcher(){return this._authFetcher||(this._authFetcher=new C),this._authFetcher}async executeSearch(t,i,e,s){const n=null==e?void 0:e.getField(i);if(n){const{mode:i,argument:r}=t,{ENTITYNAME:a,CODEFIELD:o,DESCRIPTIONFIELD:c,ROOTENTITY:h,DESCRIPTIONENTITY:l,ISHIERARCHYENTITY:u}=n.properties,d=n.dependencies;let m;const w={rootEntity:h,descriptionFieldName:c,codeFieldName:o,showInactives:!1,dataUnitId:e.dataUnitId};return null==d||d.filter((t=>t.masterFields)).forEach((t=>{var i;t.type===p.SEARCHING&&(null===(i=t.masterFields)||void 0===i?void 0:i.length)>0&&(m={expression:t.expression,params:t.masterFields.map((t=>{const i=e.getField(t),s=(null==i?void 0:i.dataType)||g.TEXT,n=e.getFieldValue(t);if(null==n)throw this.alert("Erro ao pesquisar",`É necessario informar o campo ${i.label} para executar a pesquisa.`),new Error(`É necessario informar o campo ${i.label} para executar a pesquisa.`);return{name:t,value:n,dataType:s}}))})})),this.executePreparedSearch(i,r,{entity:a,entityDescription:l,isHierarchyEntity:u,criteria:m,searchOptions:w,allowsNonAnalytic:null==s?void 0:s.allowsNonAnalytic})}}filterInvalidFields(t,i,e){return t.fieldsMetadata.filter((s=>{let n=!a.isEmpty(i[s.fieldName])&&!1!==s.visible&&"B"!==s.type&&t.pkField!==s.fieldName&&t.descriptionField!==s.fieldName&&(s.isPrimaryKey||!s.isLinkField)&&!("S"===s.type&&"H"===s.presentationType);return n&&(e[s.fieldName]=s),("string"!=typeof i[s.fieldName]||!(i[s.fieldName].indexOf("<img")>-1||i[s.fieldName].indexOf("<svg")>-1))&&n}))}filterMathFields(t,i,e,s){return t&&Array.isArray(t)&&t.forEach((t=>{let e=m.removeReference(i,s[t]);e&&i.unshift(e)})),i=i.slice(0,e)}builOptionItem(t,i,e,s,n){var r;return{value:a.highlightValue(t,i.__matchFields,null===(r=i[n])||void 0===r?void 0:r.toString(),e,!0),label:s?a.highlightValue(t,i.__matchFields,i[s],e,!0):"",details:w.buildDetails(t,e,i)}}async executePreparedSearch(t,i,e){const s={},{entity:n,entityDescription:r,criteria:a,searchOptions:c,isHierarchyEntity:h,allowsNonAnalytic:l}=e;return new Promise("ADVANCED"===t?(t,e)=>{const s=document.createElement("snk-pesquisa");s[y.DATA_ELEMENT_ID_ATTRIBUTE_NAME]=`entity_${n}`,s.entityName=n,s.argument=i,s.searchLoader=t=>this.pesquisaFetcher.loadAdvancedSearch(n,t,a,c),s.isHierarchyEntity=h,h&&(s.treeLoader=t=>this.pesquisaFetcher.loadTree(n,t,a,c),s.allowsNonAnalytic=l),s.selectItem=i=>{t(i),this.clearPopUpTitle(),this.closePopUp()},this.setPopUpTitle(r),this.showPopUp(s,void 0,void 0,e)}:(t,e)=>{this.pesquisaFetcher.loadAdvancedSearch(n,i,a,c).then((e=>{let n=(e=o.stringToObject(e.json.$)).descriptionField,r=e.pkField;const a=[];e.data.forEach((t=>{let o=this.filterInvalidFields(e,t,s),c=this.filterMathFields(t.__matchFields,o,6,s);a.push(this.builOptionItem(i,t,c,n,r))})),t(a)})).catch((t=>{e(t)}))})}async isDebugMode(){return new Promise((t=>{t(window.isDebugMode)}))}async getAppLabel(){return G.getAppLabel(this.applicationResourceID)}addSearchListener(t,i,e){return new Promise((s=>{s(this.pesquisaFetcher.addSearchListener(t,i.dataUnitId,e))}))}importScript(t){return new Promise((i=>{this.getApplicationPath().then((e=>{let s=[];Array.isArray(t)||(s=[t]),s.forEach((t=>{const i=document.createElement("script");i.src=`${e}/${t}`,i.async=!0,document.body.appendChild(i)})),i()}))}))}async getApplicationPath(){return new Promise((t=>{"dev"===window.applicationenv?t(""):t(`/${this.getModuleName()}/labsApps/${window.APPLICATION_NAME}/build`)}))}getModuleName(){return window.MGE_MODULE_NAME||"mgefin-bff"}executeSelectDistinct(t,i,e){return this.dataUnitFetcher.loadSelectDistinct(t,i,e)}getDataFetcher(){return Promise.resolve(b.get())}async whenApplicationReady(){return f.getContextValue("__SNK__APPLICATION__LOADING__")?Promise.resolve(this):new Promise((t=>{this._waitingAppReady.push((()=>t(this)))}))}async setSearchFilterContext(t,i){f.setContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${t})__`,i)}clearContent(t){t&&Array.from(t.children).forEach((i=>{t.removeChild(i)}))}clearPopUpTitle(){this._popUp.ezTitle=""}setPopUpTitle(t){this._popUp.ezTitle=t}async pkChangeListener(){const t=top.window.location.hash.split("/")[2];if(this._currentPkParameter===t)return;const i=this.getResourceIdFromToken(),e=T.getPkObjectFromUrlToken(top.window.location.hash),s=window.redirectFrom;if(void 0===e)return;if((!s||-1===s.split("_")[0].indexOf(i.split("_")[0]))&&i!==this.applicationResourceID)return;const n={pk:e};if(this._isLoadedByPk=!0,this.loadByPK)return this.loadByPK(n,s),void(this._currentPkParameter=t);this._loadPkParameter={pk:n,redirect:s},this.defaultLoadByPK(n,t)}getResourceIdFromToken(){return top.window.location.pathname.indexOf("tabContent.jsp")>-1?T.getResourceIdFromUrlToken(window.location.generateHash(window.location.hash)):T.getResourceIdFromUrlToken(top.window.location.hash)}defaultLoadByPK(t,i){if(!(null==t?void 0:t.pk))return;const e=this.getFirstDataUnitFromDOM(),s=e.dataUnit;if(!s)return console.warn("Dataunit não inicializado"),void e.addEventListener("dataUnitReady",(e=>{this.loadDataWithPKFilter(t,e.detail),this._currentPkParameter=i}));this.loadDataWithPKFilter(t,s),this._currentPkParameter=i}loadDataWithPKFilter(t,i){const e={term:"",filter:{name:"LOAD_BY_PK_FILTER",expression:this.buildFilterExpressionByPkObject(t),params:this.getFilterParamsFromPkObject(t,i)}};i.loadData(e)}getFirstDataUnitFromDOM(){let t=this._element.querySelector("snk-data-unit[data-load-by-pk]");if(t||(t=this._element.querySelector("snk-data-unit")),t)return t}getFilterParamsFromPkObject(t,i){var e;const s=[];for(const n in t.pk)t.pk.hasOwnProperty(n)&&!Array.isArray(t.pk[n])&&s.push({name:n,dataType:(null===(e=i.getField(n))||void 0===e?void 0:e.dataType)||this.getDefaultDataTypeLoadByPK(t.pk[n]),value:t.pk[n]});return s}getDefaultDataTypeLoadByPK(t){return"number"==typeof t||t instanceof Number?g.NUMBER:"boolean"==typeof t||t instanceof Boolean?g.BOOLEAN:t instanceof Date?g.DATE:g.TEXT}buildFilterExpressionByPkObject(t){let i="";for(const e in t.pk)a.isEmpty(i)||(i+=" AND "),Array.isArray(t.pk[e])?i+=`${e} IN (${t.pk[e].toString()})`:i+=`${e} = :${e}`;return i}async showNewVersionPopup(){const t=document.createElement("ez-modal-container"),i=await this.getAppLabel();t.modalTitle=this.getMessage("snkApplication.newVersionPopup.title",{screenName:i}),t.okButtonLabel=this.getMessage("snkApplication.newVersionPopup.okButton"),t.cancelButtonLabel=this.getMessage("snkApplication.newVersionPopup.cancelButton");const e=document.createElement("p");e.innerText=this.getMessage("snkApplication.newVersionPopup.info"),e.className="ez-text",t.appendChild(e),t.addEventListener("ezModalAction",this.newVersionPopupEventListener.bind(this));const s=await I.showPopup({content:t});this._removeVersionLayoutPopup=async()=>{await s(),await this.processPendingActions(this.NEW_VERSION_POPUP_LOCKER)}}async newVersionPopupEventListener(t){"LOAD"!==t.detail&&("OK"===t.detail&&G.setScreenToUseV3Layout(),"CANCEL"===t.detail&&G.setScreenToUseOldLayout(),this._popUp.opened=!1,this._removeVersionLayoutPopup&&await this._removeVersionLayoutPopup())}async handleShowNewVersionPopup(){this.hasToShowNewVersionPopup()&&await this.showNewVersionPopup()}hasToShowNewVersionPopup(){const t=new URLSearchParams(window.location.search).get("firstLoadConv");return t&&"S"===t}registerPkChangeListener(){window.hasOwnProperty("onhashchange")?window.onhashchange=this.pkChangeListener.bind(this):setInterval(this.pkChangeListener.bind(this),100)}componentWillLoad(){f.setContextValue("__SNK__APPLICATION__LOADING__",!0),this._errorHandler=new W(this),this.messagesBuilder=new O,f.setContextValue("__EZUI__UPLOAD__ADD__URL__",`${T.getUrlBase()}/mge/upload/file`),f.setContextValue("__EZUI__SEARCH__OPTION__LOADER__",((t,i,e,s)=>this.executeSearch(t,i,e,s))),f.setContextValue("__EZUI__GRID_LICENSE__",K),this.registerPkChangeListener(),v.init(),k.preload(this.applicationResourceID,this.configName,{gridLegacyConfig:this.gridLegacyConfigName,formLegacyConfig:this.formLegacyConfigName}),document.addEventListener("click",(()=>G.applicationClick())),this._waitingAppReady.forEach((t=>t()))}connectedCallback(){this._isBrowserTypeElectron=P.isElectron(),f.setContextValue("__SNK__APPLICATION__",this),b.addRequestListener(this._requestListener)}disconnectedCallback(){null==b||b.removeRequestListener(this._requestListener),this.removeShortcuts(),this._lockManagerTimer&&clearTimeout(this._lockManagerTimer)}async componentDidLoad(){this.applicationLoading.emit(!0),window.requestAnimationFrame((()=>{f.setContextValue("__SNK__APPLICATION__LOADING__",!1),this.applicationLoaded.emit(!0),this.pkChangeListener()})),y.addIDInfo(this._element,`resource_${this.applicationResourceID}`),await this.handleShowNewVersionPopup(),this.initKeyboardManager(),this.enableLockManagerLoadingApp?(_.addLockManagerCtxId(this._element),this.resolveApplicationReady()):this._applicationReady=!0}async markToReload(){this.enableLockManagerLoadingApp&&(this._applicationReady=!1,await _.resetLocks(this._element,A.APP_LOADING),this.resolveApplicationReady())}async addLoadingLock(t=!1){if(this.enableLockManagerLoadingApp)return t&&(this._applicationReady=!1,await _.resetLocks(this._element,A.APP_LOADING)),this.resolveApplicationReady(),await _.lock(this._element,A.APP_LOADING)}async resolveApplicationReady(){if(!this._applicationReady)try{await this.checkTimeoutLimitLockManager(),await _.whenHasLock(this._element,A.APP_LOADING),await _.whenResolve(this._element,A.APP_LOADING,200),await _.resetLocks(this._element,A.APP_LOADING),this._applicationReady=!0}catch(t){console.warn(t),this._applicationReady=!0}}stopTimeoutLockManager(){this._lockManagerTimer&&clearTimeout(this._lockManagerTimer)}async checkTimeoutLimitLockManager(){this.stopTimeoutLockManager(),this._applicationReady||(this._lockManagerTimer=setTimeout((async()=>{this._applicationReady||(await _.resetLocks(this._element,A.APP_LOADING),this.stopTimeoutLockManager(),this._applicationReady=!0)}),this._maxTimeLockAppLoading))}initKeyboardManager(){this._keyboardManager.bind("ctrl + g",G.searchApp.bind(this),{description:"Pesquisar por telas"}).bind("ctrl + d",G.showDesktop.bind(this),{description:"Mostrar o desktop"}).bind("F1",G.openHelp.bind(this),{description:"Abrir ajuda"})}removeShortcuts(){this._keyboardManager.unbind("ctrl + g").unbind("ctrl + d").unbind("F1")}renderLoadingSkeleton(t){if(this.enableLockManagerLoadingApp)return this._isBrowserTypeElectron?this.getSpinnerLoadingDefault():this.getSkeletonTemplateApplication()}getLoadingVisibilityStyle(){return{visibility:this._applicationReady?"hidden":"initial",display:this._applicationReady?"none":"unset"}}getSkeletonTemplateApplication(){return e("div",{class:"loading-hidden",style:this.getLoadingVisibilityStyle()},e("div",{class:"ez-margin--medium ez-margin-top--extra-small"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"150px",animation:"progress"})),e("div",{class:"ez-flex ez-flex--align-items-stretch skeleton-content"},e("div",{class:"skeleton-content-left ez-margin--medium"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"calc(100% - 15px)",animation:"progress",marginBottom:"20px"})),e("div",{class:"ez-flex-item--auto skeleton-content-right ez-margin--medium"},e("ez-skeleton",{count:this.getCountSkeleton("skeleton-content-right",50,20),variant:"rect",width:"100%",height:"49px",animation:"progress",marginBottom:"20px"}))),e("div",{class:"skeleton-content-footer ez-margin--medium ez-margin-top--extra-small"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"100px",animation:"progress"})))}getSpinnerLoadingDefault(){return e("div",{class:"loading-hidden",style:this.getLoadingVisibilityStyle()},e("div",{class:"ez-flex ez-size-height--full ez-size-width--full ez-flex--justify-center ez-flex--align-items-center spinner"},e("ez-icon",{iconName:"sync",size:"x-large",class:"spin"}),e("span",{class:"ez-title ez-title--secondary ez-title--extra-large"},"Carregando...")))}render(){return e(s,{style:{visibility:!this.enableLockManagerLoadingApp||this._applicationReady?"unset":"hidden",overflow:!this.enableLockManagerLoadingApp||this._applicationReady?"unset":"hidden"}},e("div",null,e("ez-loading-bar",{ref:t=>this._requestListener.ezLoadingBar=t}),e("ez-popup",{opened:!1,ref:t=>this._popUp=t,onEzClosePopup:()=>this.closePopUp()}),e("ez-modal",{opened:!1,ref:t=>this._rightModal=t,"modal-size":"small",closeOutsideClick:!0,closeEsc:!0}),this.renderLoadingSkeleton()))}get _element(){return n(this)}static get watchers(){return{loadByPK:["watchPropHandler"]}}};class Q{constructor(t,i){this.resolve=t,this.reject=i}}var tt;!function(t){t[t.APPLICATION=1]="APPLICATION",t[t.GRID=2]="GRID"}(tt||(tt={})),Z.style=".sc-snk-application-h{display:flex;flex-direction:column;height:100%}.sc-snk-application-h>.loading-hidden.sc-snk-application{display:none;pointer-events:none}.skeleton-content-left.sc-snk-application{width:300px;padding-right:5px}.skeleton-content.sc-snk-application{height:calc(100vh - 310px)}.spinner.sc-snk-application{height:100vh;gap:10px}.spinner.sc-snk-application>.spin.sc-snk-application{animation-name:spin;animation-duration:5000ms;animation-iteration-count:infinite;animation-timing-function:linear}@keyframes spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}";export{Z as snk_application}
11
+ }`)}fetchTotals(t,i,e=[]){const s=`${t}_${i}`,n=this.cancel.findIndex((t=>t[s]));return n>=0&&(this.cancel[n][s](),this.cancel.splice(n,1)),Promise.race([new Promise((t=>this.cancel.push({[s]:t}))),this.getTotals(t,i,e)]).then((t=>{let i=new Map;if(t){i=t;const e=this.cancel.findIndex((t=>t[s]));e>=0&&this.cancel.splice(e,1)}return i}))}getTotals(t,i,e=[]){return new Promise(((s,n)=>{T.get().callGraphQL({query:this.templateByQuery.get("fetchTotals"),values:{name:`totals://${t}/${i}`,filters:e}}).then((t=>{if(t.length>0){const i=new Map;return t.forEach((t=>i.set(t.name,parseFloat(t.value)))),s(i)}return n("Não foi possível recuperar os totalizadores")})).catch(n)}))}}function q(){const t=["2909523kXwted","CompanyName=Sankhya Jiva Tecnologia e Inovao Ltda,LicensedApplication=Sankhya Gestao,LicenseType=SingleApplication,LicensedConcurrentDeveloperCount=2,LicensedProductionInstancesCount=0,AssetReference=AG-019460,ExpiryDate=9_November_2022_[v2]_MTY2Nzk1MjAwMDAwMA==10487151e296ee4360f80961ca960869","1131048CARoeW","502909mLEPmu","447255iQEXuN","428UHbJwW","270AFTxAV","194369jhGqTI","1540nWuTrj","2044062GicUQI","30CkXPWg"];return(q=function(){return t})()}const B=H;function H(t,i){const e=q();return(H=function(t){return e[t-=392]})(t,i)}!function(){const t=H,i=q();for(;;)try{if(951926==-parseInt(t(398))/1+-parseInt(t(393))/2+parseInt(t(395))/3+-parseInt(t(400))/4*(parseInt(t(392))/5)+-parseInt(t(401))/6*(-parseInt(t(402))/7)+parseInt(t(397))/8+-parseInt(t(399))/9*(-parseInt(t(394))/10))break;i.push(i.shift())}catch(t){i.push(i.shift())}}();const K=B(396);var V;class G{static openAppActivity(t,i){var e;null===(e=window.workspace)||void 0===e||e.openAppActivity(t,i)}static getAppLabel(t){if(null!=(null===window||void 0===window?void 0:window.workspace))return null==window.workspace.getAppLabel&&(window.workspace.getAppLabel=t=>(t||"").split(".").pop()),window.workspace.getAppLabel(t)}static setScreenToUseV3Layout(){var t;null===(t=window.workspace)||void 0===t||t.setScreenToUseV3Layout()}static setScreenToUseOldLayout(){var t;null===(t=window.workspace)||void 0===t||t.setScreenToUseOldLayout()}static showDesktop(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.showDesktop)||void 0===i||i.call(t)}static searchApp(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.searchApp)||void 0===i||i.call(t)}static openHelp(){var t,i;null===(i=null===(t=window.workspace)||void 0===t?void 0:t.openHelp)||void 0===i||i.call(t)}static applicationClick(){var t,i;(null===(t=window.workspace)||void 0===t?void 0:t.applicationClick)&&(null===(i=window.workspace)||void 0===i||i.applicationClick())}}G.resourceID=null===(V=window.workspace)||void 0===V?void 0:V.resourceID;class W{constructor(t){this._app=t,window.addEventListener("error",(t=>this.errorHandler(t))),window.addEventListener("unhandledrejection",(t=>this.rejectionHandler(t)))}rejectionHandler(t){const i=t.reason;i instanceof c||(i?this.processException(i):this._app.isDebugMode().then((t=>{t&&this._app.error("Promise rejeitada","Erro interno: Uma promise foi rejeitada sem razão determinada.")})))}errorHandler(t){this.processException(t.error)}buildErrorCodeHTML(t){return'<br><a href="#" onclick="try{window.workspace.openHelp(\'_tbcode:'+t+"')} catch(e){alert('Não é possível abrir a ajuda fora do workspace Sankhya');}\">Código: "+t+"</a>"}processException(t){t.errorCode&&(t.message+=this.buildErrorCodeHTML(t.errorCode)),t instanceof c||t instanceof h?this._app.alert(t.title,t.message):t instanceof l?this._app.error(t.title,t.message):this._app.isDebugMode().then((i=>{if(i)if(t instanceof Error)this._app.error(t.name,t.message);else{const i=(null==t?void 0:t.title)||"Erro detectado",e="string"==typeof t?t:t.message||`Erro interno "${o.objectToString(t)}"`;this._app.error(i,e)}}))}}class J{constructor(){this._debounceTime=1500,this.requests=new Map,this.requestsLoadingBar=[]}onRequestStart(t){if(t.url.includes("quietMode=true"))return;this.requestsLoadingBar.push(t.requestId);const i=setTimeout((()=>{this.ezLoadingBar.show()}),this._debounceTime);this.requests.set(t.requestId,i)}onRequestEnd(t){var i,e,s;const n=this.requests.get(t.requestId);clearTimeout(n),(null===(i=this.requestsLoadingBar)||void 0===i?void 0:i.includes(t.requestId))&&(this.requestsLoadingBar=null===(e=this.requestsLoadingBar)||void 0===e?void 0:e.filter((i=>i!==t.requestId)),!this.requestsLoadingBar.length&&(null===(s=this.ezLoadingBar)||void 0===s||s.hide()))}}class Y{constructor(){this._debounceTime=1e3,this._ignoredNameTypes=["totals"],this._countRequest=0}onRequestStart(t){this.isIgnoreLoadingOnRequest(t)||(this._countRequest++,this.ezLoadingBar.show(),this._timerLoading&&clearTimeout(this._timerLoading))}onRequestEnd(t){this.isIgnoreLoadingOnRequest(t)||(this._countRequest--,this._timerLoading=setTimeout((()=>{this._countRequest<=0&&this.ezLoadingBar.hide()}),this._debounceTime))}isIgnoreLoadingOnRequest(t){if(null==t)return!1;if(t.url.includes("quietMode=true"))return!0;if(null==t.requestBody)return!1;if(1==t.requestBody.length){const{name:i}=t.requestBody[0].variables;if(i){const t=i.split(":");return this._ignoredNameTypes.indexOf(t[0])>=0}}return!1}}class X{static create({strategy:t}){switch(t){case"request_name":return new Y;case"request_time":return new J;default:throw new Error("Strategy not found")}}}const Z=class{constructor(e){t(this,e),this.applicationLoaded=i(this,"applicationLoaded",7),this.applicationLoading=i(this,"applicationLoading",7),this.NEW_VERSION_POPUP_LOCKER="NEW_VERSION_POPUP_LOCKER",this._authPromises=[],this._keyboardManager=new u,this._waitingAppReady=new Array,this._duCache=new Map,this._duPromises=new Map,this._requestListener=X.create({strategy:"request_time"}),this._maxTimeLockAppLoading=1e4,this._isBrowserTypeElectron=!1,this._pendingActions=new Map,this._loadPkParameter=null,this._isLoadedByPk=!1,this._applicationReady=!1,this.enableLockManagerLoadingApp=void 0,this.messagesBuilder=void 0,this.configName=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.loadByPK=void 0}async processPendingActions(t){const i=this._pendingActions.get(t);i&&i.length&&(i.forEach((t=>t())),this._pendingActions.set(t,[]))}get parameters(){return this._parameters||(this._parameters=new F),this._parameters}async getAuth(t){return null==t?this.getApplicationAuth():new Promise(((i,e)=>{this.authFetcher.getData(t).then((t=>{i(t)})).catch((t=>{e(t)}))}))}async getApplicationAuth(){return this._auth?Promise.resolve(this._auth):new Promise(((t,i)=>{const e=this._authPromises.length>0;this._authPromises.push(new Q(t,i)),e||this.authFetcher.getData(this.applicationResourceID).then((t=>{for(this._auth=t;this._authPromises.length>0;)this._authPromises.pop().resolve(this._auth)})).catch((t=>{for(;this._authPromises.length>0;)this._authPromises.pop().reject(t)}))}))}watchPropHandler(t,i){t&&this._loadPkParameter&&(this.loadByPK(this._loadPkParameter.pk,this._loadPkParameter.redirect),this._loadPkParameter=null)}async getKeyboardManager(){return Promise.resolve(this._keyboardManager)}async isUserSup(){return new Promise(((t,i)=>{this.getAuth().then((e=>{this.getAuthList(e).then((i=>{t(i.isSup)})).catch((t=>i(t)))}))}))}async addPendingAction(t,i){var e;const s=null!==(e=this._pendingActions.get(t))&&void 0!==e?e:[];this._pendingActions.set(t,[...s,i])}async callServiceBroker(t,i,e){return T.get().callServiceBroker(t,i,e)}async initOnboarding(t){this.hasToShowNewVersionPopup()?await this.addPendingAction(this.NEW_VERSION_POPUP_LOCKER,(()=>this.doInitOnboarding(t))):this.doInitOnboarding(t)}doInitOnboarding(t){d.getInstance().init(t,window.envContext)}async hasAccess(t,i){return new Promise(((e,s)=>{this.getAuth(i).then((i=>{this.getAuthList(i).then((i=>{e(i.isSup||i.actions[t])})).catch((t=>s(t)))}))}))}async getAllAccess(t){return new Promise(((i,e)=>{this.getAuth(t).then((t=>{this.getAuthList(t).then((t=>{const e={};e.isSup=t.isSup,Object.entries(b).forEach((i=>{e[i[0]]=t.actions[i[1]]||!1})),i(e)})).catch((t=>e(t)))}))}))}async getStringParam(t){return this.parameters.asString(t)}async getIntParam(t){return this.parameters.asInteger(t)}async getFloatParam(t){return this.parameters.asFloat(t)}async getBooleanParam(t){return this.parameters.asBoolean(t)}async getDateParam(t){return this.parameters.asDate(t)}async showPopUp(t,i="full",e=!0,s){this.clearContent(this._popUp),this._popUp.addEventListener("ezClosePopup",(()=>{s()}),{once:!0}),this._popUp.appendChild(t),this._popUp.opened=!0,this._popUp.heightMode=i,this._popUp.useHeader=e,"EZ-MODAL-CONTAINER"===t.tagName&&(this._popUp.useHeader=!1)}async showModal(t){this.clearContent(this._rightModal),this._rightModal.appendChild(t),this._rightModal.opened=!0}showAlerts(t){return I.showAlerts({alerts:t})}async closeModal(){this.clearContent(this._rightModal),this._rightModal.opened=!1}async closePopUp(){this.clearContent(this._popUp),this._popUp.opened=!1,this._popUp.useHeader=!0,this._popUp.heightMode="full"}async temOpcional(t){const i=t.split(",");return new Promise(((t,e)=>{this.getAttributeFromHTMLWrapper("opc0009").then((s=>{"1"===s?t(!0):Promise.all(i.map((t=>this.getAttributeFromHTMLWrapper("opc"+t)))).then((i=>{t(i.includes("1"))})).catch((t=>{e(t)}))})).catch((t=>{e(t)}))}))}async getConfig(t){let i={serviceName:"SystemUtilsSP.getConf",requestBody:{config:{chave:t,tipo:"T"}}};return new Promise(((t,e)=>{T.get().callServiceBroker("SystemUtilsSP.getConf",JSON.stringify(i)).then((i=>{var e;return t(null===(e=i.config)||void 0===e?void 0:e.data)})).catch((t=>e(t)))}))}async saveConfig(t,i){let e={serviceName:"SystemUtilsSP.saveConf",requestBody:{config:{chave:t,tipo:"T",data:i}}};return new Promise(((t,i)=>{T.get().callServiceBroker("SystemUtilsSP.saveConf",JSON.stringify(e)).then((i=>t(i))).catch((t=>i(t)))}))}async getAttributeFromHTMLWrapper(t){return Promise.resolve(window[t])}async openApp(t,i){G.openAppActivity(t,i)}async webConnection(t,i,e){this.getStringParam(t).then((t=>{z.webConnectionCaller(t,i,e)}))}getDuPromissesStack(t){let i;return t&&(i=this._duPromises.get(t),i||(i=[],this._duPromises.set(t,i))),i||[]}async createDataunit(t,i,e,s,n){return null==n&&(n=this.applicationResourceID),new Promise(((r,a)=>{const o=this.getDuPromissesStack(i),c=o.length>0;if(o.push(new Q(r,a)),!c){const r=this.dataUnitFetcher.getDataUnit(t,n,e,s);r.loadMetadata().then((()=>{this.processResolveDataUnit(r,i,o)})).catch((t=>{for(;o.length>0;)o.pop().reject(t)}))}}))}processResolveDataUnit(t,i,e){for(i&&this.updateDataunitCache(void 0,i,t);e.length>0;)e.pop().resolve(t)}async updateDataunitCache(t,i,e){t&&this._duCache.delete(t),this._duCache.set(i,e)}async getDataUnit(t,i,e,s,n){return new Promise(((r,a)=>{const o=this._duCache.get(i);o?r(o):this.createDataunit(t,i,e,s,n).then((t=>{r(t)})).catch((t=>a(t)))}))}async addClientEvent(t,i){return new Promise((e=>{T.addClientEvent(t,i),e()}))}async removeClientEvent(t){return new Promise((i=>{T.removeClientEvent(t),i()}))}async hasClientEvent(t){return new Promise((i=>{i(T.hasClientEvent(t))}))}get applicationResourceID(){return this._applicationResourceID||(this._applicationResourceID=this.urlParams.get("workspaceResourceID")||this.urlParams.get("resourceID")||G.resourceID||"unknown.resource.id"),this._applicationResourceID}async getResourceID(){return Promise.resolve(this.applicationResourceID)}async getUserID(){return Promise.resolve(window.UID)}async alert(t,i,e,s){return I.alert(t,i,e,s)}async error(t,i,e,s){return I.error(t,i,e,s)}async success(t,i,e,s){return I.success(t,i,e,s)}async message(t,i,e,s){return I.message(t,i,e,s)}async confirm(t,i,e,s,n){return I.confirm(t,i,e,s,n)}async info(t,i){return I.info(t,i)}async loadTotals(t,i,e){return this.totalsFetcher.fetchTotals(t,i,e)}async isLoadedByPk(){return Promise.resolve(this._isLoadedByPk)}async preloadMangerRemoveRecord(t,i){const e=i.map((t=>({__record__id__:t})));N.removeRecords(t,e)}getCountSkeleton(t,i,e){let s=window.innerHeight-350;return e=e||20,Math.floor(s/(i+e))||1}async getAuthList(t){return await(new U).parseFromJSON(t)}get urlParams(){return this._urlParams||(this._urlParams=L.getQueryParams(location.search)),this._urlParams}getMessage(t,i){var e;return null===(e=this.messagesBuilder)||void 0===e?void 0:e.getMessage(t,i)}get dataUnitFetcher(){return this._dataUnitFetcher||(this._dataUnitFetcher=new E),this._dataUnitFetcher}get totalsFetcher(){return this._totalsFetcher||(this._totalsFetcher=new $),this._totalsFetcher}get pesquisaFetcher(){return this._pesquisaFetcher||(this._pesquisaFetcher=new D),this._pesquisaFetcher}get authFetcher(){return this._authFetcher||(this._authFetcher=new C),this._authFetcher}async executeSearch(t,i,e,s){const n=null==e?void 0:e.getField(i);if(n){const{mode:i,argument:r}=t,{ENTITYNAME:a,CODEFIELD:o,DESCRIPTIONFIELD:c,ROOTENTITY:h,DESCRIPTIONENTITY:l,ISHIERARCHYENTITY:u}=n.properties,d=n.dependencies;let m;const w={rootEntity:h,descriptionFieldName:c,codeFieldName:o,showInactives:!1,dataUnitId:e.dataUnitId};return null==d||d.filter((t=>t.masterFields)).forEach((t=>{var i;t.type===p.SEARCHING&&(null===(i=t.masterFields)||void 0===i?void 0:i.length)>0&&(m={expression:t.expression,params:t.masterFields.map((t=>{const i=e.getField(t),s=(null==i?void 0:i.dataType)||g.TEXT,n=e.getFieldValue(t);if(null==n)throw this.alert("Erro ao pesquisar",`É necessario informar o campo ${i.label} para executar a pesquisa.`),new Error(`É necessario informar o campo ${i.label} para executar a pesquisa.`);return{name:t,value:n,dataType:s}}))})})),this.executePreparedSearch(i,r,{entity:a,entityDescription:l,isHierarchyEntity:u,criteria:m,searchOptions:w,allowsNonAnalytic:null==s?void 0:s.allowsNonAnalytic})}}filterInvalidFields(t,i,e){return t.fieldsMetadata.filter((s=>{let n=!a.isEmpty(i[s.fieldName])&&!1!==s.visible&&"B"!==s.type&&t.pkField!==s.fieldName&&t.descriptionField!==s.fieldName&&(s.isPrimaryKey||!s.isLinkField)&&!("S"===s.type&&"H"===s.presentationType);return n&&(e[s.fieldName]=s),("string"!=typeof i[s.fieldName]||!(i[s.fieldName].indexOf("<img")>-1||i[s.fieldName].indexOf("<svg")>-1))&&n}))}filterMathFields(t,i,e,s){return t&&Array.isArray(t)&&t.forEach((t=>{let e=m.removeReference(i,s[t]);e&&i.unshift(e)})),i=i.slice(0,e)}builOptionItem(t,i,e,s,n){var r;return{value:a.highlightValue(t,i.__matchFields,null===(r=i[n])||void 0===r?void 0:r.toString(),e,!0),label:s?a.highlightValue(t,i.__matchFields,i[s],e,!0):"",details:w.buildDetails(t,e,i)}}async executePreparedSearch(t,i,e){const s={},{entity:n,entityDescription:r,criteria:a,searchOptions:c,isHierarchyEntity:h,allowsNonAnalytic:l}=e;return new Promise("ADVANCED"===t?(t,e)=>{const s=document.createElement("snk-pesquisa");s[y.DATA_ELEMENT_ID_ATTRIBUTE_NAME]=`entity_${n}`,s.entityName=n,s.argument=i,s.searchLoader=t=>this.pesquisaFetcher.loadAdvancedSearch(n,t,a,c),s.isHierarchyEntity=h,h&&(s.treeLoader=t=>this.pesquisaFetcher.loadTree(n,t,a,c),s.allowsNonAnalytic=l),s.selectItem=i=>{t(i),this.clearPopUpTitle(),this.closePopUp()},this.setPopUpTitle(r),this.showPopUp(s,void 0,void 0,e)}:(t,e)=>{this.pesquisaFetcher.loadAdvancedSearch(n,i,a,c).then((e=>{let n=(e=o.stringToObject(e.json.$)).descriptionField,r=e.pkField;const a=[];e.data.forEach((t=>{let o=this.filterInvalidFields(e,t,s),c=this.filterMathFields(t.__matchFields,o,6,s);a.push(this.builOptionItem(i,t,c,n,r))})),t(a)})).catch((t=>{e(t)}))})}async isDebugMode(){return new Promise((t=>{t(window.isDebugMode)}))}async getAppLabel(){return G.getAppLabel(this.applicationResourceID)}addSearchListener(t,i,e){return new Promise((s=>{s(this.pesquisaFetcher.addSearchListener(t,i.dataUnitId,e))}))}importScript(t){return new Promise((i=>{this.getApplicationPath().then((e=>{let s=[];Array.isArray(t)||(s=[t]),s.forEach((t=>{const i=document.createElement("script");i.src=`${e}/${t}`,i.async=!0,document.body.appendChild(i)})),i()}))}))}async getApplicationPath(){return new Promise((t=>{"dev"===window.applicationenv?t(""):t(`/${this.getModuleName()}/labsApps/${window.APPLICATION_NAME}/build`)}))}getModuleName(){return window.MGE_MODULE_NAME||"mgefin-bff"}executeSelectDistinct(t,i,e){return this.dataUnitFetcher.loadSelectDistinct(t,i,e)}getDataFetcher(){return Promise.resolve(T.get())}async whenApplicationReady(){return f.getContextValue("__SNK__APPLICATION__LOADING__")?Promise.resolve(this):new Promise((t=>{this._waitingAppReady.push((()=>t(this)))}))}async setSearchFilterContext(t,i){f.setContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${t})__`,i)}clearContent(t){t&&Array.from(t.children).forEach((i=>{t.removeChild(i)}))}clearPopUpTitle(){this._popUp.ezTitle=""}setPopUpTitle(t){this._popUp.ezTitle=t}async pkChangeListener(){const t=top.window.location.hash.split("/")[2];if(this._currentPkParameter===t)return;const i=this.getResourceIdFromToken(),e=L.getPkObjectFromUrlToken(top.window.location.hash),s=window.redirectFrom;if(void 0===e)return;if((!s||-1===s.split("_")[0].indexOf(i.split("_")[0]))&&i!==this.applicationResourceID)return;const n={pk:e};if(this._isLoadedByPk=!0,this.loadByPK)return this.loadByPK(n,s),void(this._currentPkParameter=t);this._loadPkParameter={pk:n,redirect:s},this.defaultLoadByPK(n,t)}getResourceIdFromToken(){return top.window.location.pathname.indexOf("tabContent.jsp")>-1?L.getResourceIdFromUrlToken(window.location.generateHash(window.location.hash)):L.getResourceIdFromUrlToken(top.window.location.hash)}defaultLoadByPK(t,i){if(!(null==t?void 0:t.pk))return;const e=this.getFirstDataUnitFromDOM(),s=e.dataUnit;if(!s)return console.warn("Dataunit não inicializado"),void e.addEventListener("dataUnitReady",(e=>{this.loadDataWithPKFilter(t,e.detail),this._currentPkParameter=i}));this.loadDataWithPKFilter(t,s),this._currentPkParameter=i}loadDataWithPKFilter(t,i){const e={term:"",filter:{name:"LOAD_BY_PK_FILTER",expression:this.buildFilterExpressionByPkObject(t),params:this.getFilterParamsFromPkObject(t,i)}};i.loadData(e)}getFirstDataUnitFromDOM(){let t=this._element.querySelector("snk-data-unit[data-load-by-pk]");if(t||(t=this._element.querySelector("snk-data-unit")),t)return t}getFilterParamsFromPkObject(t,i){var e;const s=[];for(const n in t.pk)t.pk.hasOwnProperty(n)&&!Array.isArray(t.pk[n])&&s.push({name:n,dataType:(null===(e=i.getField(n))||void 0===e?void 0:e.dataType)||this.getDefaultDataTypeLoadByPK(t.pk[n]),value:t.pk[n]});return s}getDefaultDataTypeLoadByPK(t){return"number"==typeof t||t instanceof Number?g.NUMBER:"boolean"==typeof t||t instanceof Boolean?g.BOOLEAN:t instanceof Date?g.DATE:g.TEXT}buildFilterExpressionByPkObject(t){let i="";for(const e in t.pk)a.isEmpty(i)||(i+=" AND "),Array.isArray(t.pk[e])?i+=`${e} IN (${t.pk[e].toString()})`:i+=`${e} = :${e}`;return i}async showNewVersionPopup(){const t=document.createElement("ez-modal-container"),i=await this.getAppLabel();t.modalTitle=this.getMessage("snkApplication.newVersionPopup.title",{screenName:i}),t.okButtonLabel=this.getMessage("snkApplication.newVersionPopup.okButton"),t.cancelButtonLabel=this.getMessage("snkApplication.newVersionPopup.cancelButton");const e=document.createElement("p");e.innerText=this.getMessage("snkApplication.newVersionPopup.info"),e.className="ez-text",t.appendChild(e),t.addEventListener("ezModalAction",this.newVersionPopupEventListener.bind(this));const s=await I.showPopup({content:t});this._removeVersionLayoutPopup=async()=>{await s(),await this.processPendingActions(this.NEW_VERSION_POPUP_LOCKER)}}async newVersionPopupEventListener(t){"LOAD"!==t.detail&&("OK"===t.detail&&G.setScreenToUseV3Layout(),"CANCEL"===t.detail&&G.setScreenToUseOldLayout(),this._popUp.opened=!1,this._removeVersionLayoutPopup&&await this._removeVersionLayoutPopup())}async handleShowNewVersionPopup(){this.hasToShowNewVersionPopup()&&await this.showNewVersionPopup()}hasToShowNewVersionPopup(){const t=new URLSearchParams(window.location.search).get("firstLoadConv");return t&&"S"===t}registerPkChangeListener(){window.hasOwnProperty("onhashchange")?window.onhashchange=this.pkChangeListener.bind(this):setInterval(this.pkChangeListener.bind(this),100)}componentWillLoad(){f.setContextValue("__SNK__APPLICATION__LOADING__",!0),this._errorHandler=new W(this),this.messagesBuilder=new O,f.setContextValue("__EZUI__UPLOAD__ADD__URL__",`${L.getUrlBase()}/mge/upload/file`),f.setContextValue("__EZUI__SEARCH__OPTION__LOADER__",((t,i,e,s)=>this.executeSearch(t,i,e,s))),f.setContextValue("__EZUI__GRID_LICENSE__",K),this.registerPkChangeListener(),v.init(),k.preload(this.applicationResourceID,this.configName,{gridLegacyConfig:this.gridLegacyConfigName,formLegacyConfig:this.formLegacyConfigName}),document.addEventListener("click",(()=>G.applicationClick())),this._waitingAppReady.forEach((t=>t()))}connectedCallback(){this._isBrowserTypeElectron=P.isElectron(),f.setContextValue("__SNK__APPLICATION__",this),T.addRequestListener(this._requestListener)}disconnectedCallback(){null==T||T.removeRequestListener(this._requestListener),this.removeShortcuts(),this._lockManagerTimer&&clearTimeout(this._lockManagerTimer)}async componentDidLoad(){this.applicationLoading.emit(!0),window.requestAnimationFrame((()=>{f.setContextValue("__SNK__APPLICATION__LOADING__",!1),this.applicationLoaded.emit(!0),this.pkChangeListener()})),y.addIDInfo(this._element,`resource_${this.applicationResourceID}`),await this.handleShowNewVersionPopup(),this.initKeyboardManager(),this.enableLockManagerLoadingApp?(_.addLockManagerCtxId(this._element),this.resolveApplicationReady()):this._applicationReady=!0}async markToReload(){this.enableLockManagerLoadingApp&&(this._applicationReady=!1,await _.resetLocks(this._element,A.APP_LOADING),this.resolveApplicationReady())}async addLoadingLock(t=!1){if(this.enableLockManagerLoadingApp)return t&&(this._applicationReady=!1,await _.resetLocks(this._element,A.APP_LOADING)),this.resolveApplicationReady(),await _.lock(this._element,A.APP_LOADING)}async resolveApplicationReady(){if(!this._applicationReady)try{await this.checkTimeoutLimitLockManager(),await _.whenHasLock(this._element,A.APP_LOADING),await _.whenResolve(this._element,A.APP_LOADING,200),await _.resetLocks(this._element,A.APP_LOADING),this._applicationReady=!0}catch(t){console.warn(t),this._applicationReady=!0}}stopTimeoutLockManager(){this._lockManagerTimer&&clearTimeout(this._lockManagerTimer)}async checkTimeoutLimitLockManager(){this.stopTimeoutLockManager(),this._applicationReady||(this._lockManagerTimer=setTimeout((async()=>{this._applicationReady||(await _.resetLocks(this._element,A.APP_LOADING),this.stopTimeoutLockManager(),this._applicationReady=!0)}),this._maxTimeLockAppLoading))}initKeyboardManager(){this._keyboardManager.bind("ctrl + g",G.searchApp.bind(this),{description:"Pesquisar por telas"}).bind("ctrl + d",G.showDesktop.bind(this),{description:"Mostrar o desktop"}).bind("F1",G.openHelp.bind(this),{description:"Abrir ajuda"})}removeShortcuts(){this._keyboardManager.unbind("ctrl + g").unbind("ctrl + d").unbind("F1")}renderLoadingSkeleton(t){if(this.enableLockManagerLoadingApp)return this._isBrowserTypeElectron?this.getSpinnerLoadingDefault():this.getSkeletonTemplateApplication()}getLoadingVisibilityStyle(){return{visibility:this._applicationReady?"hidden":"initial",display:this._applicationReady?"none":"unset"}}getSkeletonTemplateApplication(){return e("div",{class:"loading-hidden",style:this.getLoadingVisibilityStyle()},e("div",{class:"ez-margin--medium ez-margin-top--extra-small"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"150px",animation:"progress"})),e("div",{class:"ez-flex ez-flex--align-items-stretch skeleton-content"},e("div",{class:"skeleton-content-left ez-margin--medium"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"calc(100% - 15px)",animation:"progress",marginBottom:"20px"})),e("div",{class:"ez-flex-item--auto skeleton-content-right ez-margin--medium"},e("ez-skeleton",{count:this.getCountSkeleton("skeleton-content-right",50,20),variant:"rect",width:"100%",height:"49px",animation:"progress",marginBottom:"20px"}))),e("div",{class:"skeleton-content-footer ez-margin--medium ez-margin-top--extra-small"},e("ez-skeleton",{count:1,variant:"rect",width:"100%",height:"100px",animation:"progress"})))}getSpinnerLoadingDefault(){return e("div",{class:"loading-hidden",style:this.getLoadingVisibilityStyle()},e("div",{class:"ez-flex ez-size-height--full ez-size-width--full ez-flex--justify-center ez-flex--align-items-center spinner"},e("ez-icon",{iconName:"sync",size:"x-large",class:"spin"}),e("span",{class:"ez-title ez-title--secondary ez-title--extra-large"},"Carregando...")))}render(){return e(s,{style:{visibility:!this.enableLockManagerLoadingApp||this._applicationReady?"unset":"hidden",overflow:!this.enableLockManagerLoadingApp||this._applicationReady?"unset":"hidden"}},e("div",null,e("ez-loading-bar",{ref:t=>this._requestListener.ezLoadingBar=t}),e("ez-popup",{opened:!1,ref:t=>this._popUp=t,onEzClosePopup:()=>this.closePopUp()}),e("ez-modal",{opened:!1,ref:t=>this._rightModal=t,"modal-size":"small",closeOutsideClick:!0,closeEsc:!0}),this.renderLoadingSkeleton()))}get _element(){return n(this)}static get watchers(){return{loadByPK:["watchPropHandler"]}}};class Q{constructor(t,i){this.resolve=t,this.reject=i}}var tt;!function(t){t[t.APPLICATION=1]="APPLICATION",t[t.GRID=2]="GRID"}(tt||(tt={})),Z.style=".sc-snk-application-h{display:flex;flex-direction:column;height:100%}.sc-snk-application-h>.loading-hidden.sc-snk-application{display:none;pointer-events:none}.skeleton-content-left.sc-snk-application{width:300px;padding-right:5px}.skeleton-content.sc-snk-application{height:calc(100vh - 310px)}.spinner.sc-snk-application{height:100vh;gap:10px}.spinner.sc-snk-application>.spin.sc-snk-application{animation-name:spin;animation-duration:5000ms;animation-iteration-count:infinite;animation-timing-function:linear}@keyframes spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}";export{Z as snk_application}
@@ -1 +1 @@
1
- import{r as s,h as i,H as e,g as t}from"./p-d2d301a6.js";import{ObjectUtils as r,StringUtils as a,ElementIDUtils as o}from"@sankhyalabs/core";import{P as n,b as l,a as c}from"./p-4fe8bb73.js";import"./p-d62228fb.js";import"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ddefbbc7.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const u=class{constructor(i){s(this,i),this._mdByName={},this._startHighlightTag="<span class='card-item__highlight'>",this._endHighlightTag="</span>",this._specialCharsRegex=/[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gim,this._charsWithAccentuation="ÁÉÍÓÚ_ÃÕ_ÂÊÎÔÛ_ÀÈÌÒÙ_Ü_Ç_áéíóú_ãõ_âêîôû_àèìòù_ü_ç",this._charsWithoutAccentuation="AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c",this._changeDeboucingTimeout=null,this._limitCharsToSearch=3,this._deboucingTime=450,this._gridDataSource=[],this.pesquisaFetcher=new n,this._itemList=void 0,this._startLoading=!1,this._presentationMode="list",this._currentView=void 0,this.searchLoader=void 0,this.treeLoader=void 0,this.selectItem=void 0,this.entityName=void 0,this.argument=void 0,this.isHierarchyEntity=!1,this.allowsNonAnalytic=!1}observeArgument(){this._textInput&&(this._textInput.value=this.argument)}clearSearch(){this.argument="",this._itemList=void 0}buildDetails(s,i){let e={};for(let t=0;t<s.length;t++){const r=s[t],a=i[r.fieldName];e[r.description]=this.highlightValue(i.__matchFields,r.options&&r.options[a]||a,s,!0)}return e}buildFirstFields(s,i,e=6){return s&&Array.isArray(s)&&s.forEach((s=>{let e=this.removeReference(i,this._mdByName[s]);e&&i.unshift(e)})),i=i.slice(0,e)}doSearch(s){this.searchLoader&&"function"==typeof this.searchLoader&&(this._startLoading=!0,this.searchLoader(s).then((s=>{s&&this.processSearchResponse(s)})).finally((()=>{this._startLoading=!1})))}processSearchResponse(s){let i=(s=r.stringToObject(s.json.$)).descriptionField,e=s.pkField;e&&(this._gridMetadata=l(s),this._gridDataSource=[...s.data],this._pkField=e,this._descriptionField=i,this._itemList=this.buildCardItemList(s,e,i))}buildCardItemList(s,i,e){var t;return null===(t=s.data)||void 0===t?void 0:t.map((t=>{var r;let a=this.filterFieldsMetadata(s,t),o=this.buildFirstFields(t.__matchFields,a);return{key:this.highlightValue(t.__matchFields,null===(r=t[i])||void 0===r?void 0:r.toString(),o,!0),title:e?this.highlightValue(t.__matchFields,t[e],o,!0):"",details:this.buildDetails(o,t)}}))}filterFieldsMetadata(s,i){return s.fieldsMetadata.filter((e=>{let t=!a.isEmpty(i[e.fieldName])&&!1!==e.visible&&"B"!==e.type&&s.pkField!==e.fieldName&&s.descriptionField!==e.fieldName&&(e.isPrimaryKey||!e.isLinkField)&&!("S"===e.type&&"H"===e.presentationType);return t&&(this._mdByName[e.fieldName]=e),("string"!=typeof i[e.fieldName]||!(i[e.fieldName].indexOf("<img")>-1||i[e.fieldName].indexOf("<svg")>-1))&&t}))}removeAtIndex(s,i){if(i>=0&&i<s.length)return s.splice(i,1)[0]}removeReference(s,i){let e=this.indexOf(s,i);return this.removeAtIndex(s,e)}indexOf(s,i){let e=-1;return Array.isArray(s)&&this.find(s,((s,t)=>(e=t,this.equals(i,s)))),e}equals(s,i){return r.objectToString(s)===r.objectToString(i)}find(s,i){if(s)for(let e=0,t=s.length;e<t;e++)if(i(s[e],e,s))return s[e]}highlightValue(s,i,e,t){let r=this.replaceHtmlEntities(i);if(this.argument&&(t||this.isIn(s,e.fieldName))){const s=this.getArgumentNumber();let i=(isNaN(s)?this.argument:s.toString()).split(/%|,|\s+/),t=0,a=this.replaceAccentuatedChars(r);i.forEach((s=>{if(s){s=this.replaceAccentuatedChars(s);let i=this.getSpecialCharacters(s);null!=i&&i.length>0&&(s=this.removeSpecialCharacters(s)),(e.mask||"CGC_CPF"===e.uiType||"Phone"===e.uiType)&&(s=s.split("").join("\\.?\\-?\\/?\\(?\\)?"));let o=new RegExp(s,"ig");o.lastIndex=t;let n=o.exec(a);if(n&&n.length>0){t=n.index;let s=n[0].length,i=r.substring(t,t+s),e=(null==i?void 0:i.trim())?this._startHighlightTag+i+this._endHighlightTag:"",o=r.substring(0,t),l=r.substring(t+s);r=o+e+l,t+=e.length,a=this.replaceAccentuatedChars(r)}}}))}return r}replaceHtmlEntities(s){return null==s?s:String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}replaceAccentuatedChars(s){return null==s?s:this.replaceToSpace(s,["&amp;","&lt;","&gt;","&quot;"]).replace(/[^\w ]/g,(s=>{let i=this._charsWithAccentuation.indexOf(s);return i>-1&&(s=this._charsWithoutAccentuation.charAt(i)),s||""}))}replaceToSpace(s,i=[]){return null==s||i.forEach((i=>{const e=new RegExp(i,"g");let t="";for(let s=0;s<i.length;s++)t+=" ";s=String(s).replace(e,t)})),s}isIn(s,i){return this.indexOf(s,i)>-1}getSpecialCharacters(s){let i,e=[];for(;i=this._specialCharsRegex.exec(s);)e.push(s[i.index]);return e}removeSpecialCharacters(s){return this.getSpecialCharacters(s).forEach((i=>{s=this.replaceAll(s,i,"")})),s}replaceAll(s,i,e){let t=(null!=s?s:"").indexOf(i);for(;t>-1;)t=(s=s.replace(i,e)).indexOf(i);return s}getArgumentNumber(){return Number(this.argument||void 0)}createOption(s){let{key:i,title:e}=s;const t=new RegExp(this._startHighlightTag,"g"),r=new RegExp(this._endHighlightTag,"g");e=a.decodeHtmlEntities(e);const o={value:null==i?void 0:i.replace(t,"").replace(r,""),label:null==e?void 0:e.replace(t,"").replace(r,"")};this.selectItem(o)}onChangeValue(s){var i;if(this.clearDeboucingTimeout(),this._startLoading)return void(this._changeDeboucingTimeout=setTimeout((()=>{this.onChangeValue(s)}),this._deboucingTime));if(this.argument=(s.detail||"").trim(),this.isHierarchyEntity&&"list"===this._presentationMode)return void(null===(i=this._pesquisaTree)||void 0===i||i.applyFilter());const e=this.getArgumentNumber();this.argument&&(!isNaN(e)||this.argument.length>=this._limitCharsToSearch)?this._changeDeboucingTimeout=setTimeout((()=>{this.doSearch(isNaN(e)?this.argument:e.toString())}),this._deboucingTime):this._itemList=void 0}clearDeboucingTimeout(){this._changeDeboucingTimeout&&(clearTimeout(this._changeDeboucingTimeout),this._changeDeboucingTimeout=void 0)}onClickSearch(){this.doSearch((this.argument||"").trim())}getMessageView(){return this._startLoading?"Aguarde, buscando registros...":this._itemList?this._itemList.length>=1?`${this._itemList.length} ${this._itemList.length>1?"registros encontrados":"registro encontrado"}`:"Nenhum registro encontrado":"Os resultados de sua pesquisa aparecerão aqui..."}async componentWillLoad(){const s=await this.pesquisaFetcher.loadPresentationConfig(this.entityName);this._presentationMode="list"===s?"list":"table"}async componentDidLoad(){o.addIDInfo(this._element),await this.chooseViewMode()}async handleChangeViewMode(){this._presentationMode="list"===this._presentationMode?"table":"list",await this.chooseViewMode(),await this.pesquisaFetcher.savePresentationConfig(this.entityName,this._presentationMode)}async chooseViewMode(){var s,i;if("list"!==this._presentationMode)return await(null===(s=this._viewStack)||void 0===s?void 0:s.show(c.GRID)),void(this._currentView=c.GRID);const e=this.isHierarchyEntity?c.TREE:c.CARDS;await(null===(i=this._viewStack)||void 0===i?void 0:i.show(e)),this._currentView=e}hideLimitMessage(){return!this._itemList||this._itemList.length<100}hideRecordsMessage(){return"list"===this._presentationMode&&this.isHierarchyEntity}getButtonModeInfo(){return"list"===this._presentationMode?{iconName:"table",title:"Modo grade"}:this.isHierarchyEntity?{iconName:"hierarchical-tree",title:"Modo árvore hierárquica"}:{iconName:"list",title:"Modo lista"}}render(){var s,t;return i(e,null,i("div",{class:"snk-pesquisa"},i("div",{class:"snk-pesquisa__input"},i("ez-text-input",{label:"Buscar",class:"ez-margin-right--medium",canShowError:!1,ref:s=>this._textInput=s,onEzChange:s=>this.onChangeValue(s),value:this.argument,"data-element-id":"searchInput"},i("ez-icon",{slot:"leftIcon",iconName:"search"}),this.argument&&(null===(s=this._textInput)||void 0===s?void 0:s.value)?i("button",{slot:"rightIcon",class:"snk-pesquisa__btn",onClick:()=>this.clearSearch()},i("ez-icon",{iconName:"close"})):void 0),i("ez-button",{class:"ez-button--primary",label:"Pesquisar",onClick:()=>this.onClickSearch()}),i("ez-button",{class:"ez-margin-left--medium",mode:"icon",iconName:this.getButtonModeInfo().iconName,title:this.getButtonModeInfo().title,onClick:async()=>await this.handleChangeViewMode()})),i("div",{class:"snk-pesquisa__records-label "+(this._currentView===c.TREE?"hidden":"")},i("label",{class:"snk-pesquisa__records "+(this.hideRecordsMessage()?"hidden":"")},this.getMessageView()),i("label",{class:"snk-pesquisa__records-limit "+(this.hideLimitMessage()?"hidden":"")},"Essa pesquisa foi limitada, existem mais resultados.")),i("div",{class:"snk-pesquisa__content"},i("ez-view-stack",{ref:s=>this._viewStack=s,"data-element-id":"simple-crud"},i("stack-item",null,i("pesquisa-grid",{metadata:this._gridMetadata,dataSource:this._gridDataSource,pkField:this._pkField,descriptionField:this._descriptionField,entityName:this.entityName,shouldLoadConfig:this._currentView===c.GRID,onPesquisaGridSelectItem:({detail:s})=>this.selectItem(s)})),i("stack-item",null,i("div",{class:"snk-pesquisa__cards-container"},null===(t=this._itemList)||void 0===t?void 0:t.map((s=>i("ez-card-item",{onEzClick:s=>this.createOption(s.detail),item:s}))))),i("stack-item",null,i("pesquisa-tree",{ref:s=>this._pesquisaTree=s,argument:this.argument,treeLoader:this.treeLoader,allowsNonAnalytic:this.allowsNonAnalytic,shouldLoadTree:this._currentView===c.TREE,onPesquisaTreeSelectItem:({detail:s})=>this.selectItem(s)}))))))}get _element(){return t(this)}static get watchers(){return{argument:["observeArgument"]}}};u.style=".sc-snk-pesquisa-h{--snk-pesquisa--font-size:var(--text--medium, 14px);--snk-pesquisa--font-family:var(--font-pattern, Arial);--snk-pesquisa--font-weight:var(--text-weight--medium, 400);--snk-pesquisa__records--color:var(--text--primary, #626e82);--snk-pesquisa__records--color-secondary:var(--text--secondary, #626e82);--snk-pesquisa__records--padding-vertical:var(--space--medium, 12px);--snk-pesquisa__content--padding-right:var(--space--small, 6px);--snk-pesquisa__btn--color:var(--title--primary, #2B3A54);--snk-pesquisa__btn-disabled--color:var(--text--disable, #AFB6C0);--snk-pesquisa__btn-hover--color:var(--color--primary, #4e4e4e);--snk-pesquisa__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-pesquisa__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-pesquisa__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-pesquisa__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-pesquisa__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-pesquisa__scrollbar--width:var(--space--medium, 12px);height:100%;display:flex;flex-direction:column;overflow-y:auto}.snk-pesquisa.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%}.snk-pesquisa__input.sc-snk-pesquisa{display:flex;width:100%;box-sizing:border-box;padding-top:4px;padding-right:4px}.snk-pesquisa__input.sc-snk-pesquisa ez-icon.sc-snk-pesquisa{--ez-icon--color:inherit;font-weight:var(--text-weight--large, 600)}.snk-pesquisa__content.sc-snk-pesquisa{display:flex;flex-direction:column;overflow-y:hidden;scrollbar-width:thin;scrollbar-color:var(--snk-pesquisa__scrollbar--color-clicked) var(--snk-pesquisa__scrollbar--color-background);padding-right:var(--snk-pesquisa__content--padding-right);height:100vh}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar{background-color:var(--snk-pesquisa__scrollbar--color-background);width:var(--snk-pesquisa__scrollbar--width);max-width:var(--snk-pesquisa__scrollbar--width);min-width:var(--snk-pesquisa__scrollbar--width)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-track{background-color:var(--snk-pesquisa__scrollbar--color-background);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb{background-color:var(--snk-pesquisa__scrollbar--color-default);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:hover,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-pesquisa__scrollbar--color-hover)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:active,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-pesquisa__scrollbar--color-clicked)}.snk-pesquisa__records-label.sc-snk-pesquisa{display:flex;flex-direction:row;justify-content:space-between;font-family:var(--snk-pesquisa--font-family);font-weight:var(--snk-pesquisa--font-weight);font-size:var(--snk-pesquisa--font-size);padding-bottom:var(--snk-pesquisa__records--padding-vertical);padding-top:var(--snk-pesquisa__records--padding-vertical)}.snk-pesquisa__records-label.hidden.sc-snk-pesquisa{display:none}.snk-pesquisa__records.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color)}.snk-pesquisa__records-limit.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color-secondary)}.snk-pesquisa__records-limit.hidden.sc-snk-pesquisa,.snk-pesquisa__records.hidden.sc-snk-pesquisa{visibility:hidden}.snk-pesquisa__btn.sc-snk-pesquisa{outline:none;border:none;background:none;cursor:pointer;color:var(--snk-pesquisa__btn--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled:hover{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:hover{color:var(--snk-pesquisa__btn-hover--color)}.snk-pesquisa__cards-container.sc-snk-pesquisa{height:100%;overflow-y:auto}";export{u as snk_pesquisa}
1
+ import{r as s,h as i,H as t,g as e}from"./p-d2d301a6.js";import{ObjectUtils as r,StringUtils as a,ElementIDUtils as o}from"@sankhyalabs/core";import{P as n,b as l,a as c}from"./p-c9f22653.js";import"./p-d62228fb.js";import"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-78d49c74.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const u=class{constructor(i){s(this,i),this._mdByName={},this._startHighlightTag="<span class='card-item__highlight'>",this._endHighlightTag="</span>",this._specialCharsRegex=/[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gim,this._charsWithAccentuation="ÁÉÍÓÚ_ÃÕ_ÂÊÎÔÛ_ÀÈÌÒÙ_Ü_Ç_áéíóú_ãõ_âêîôû_àèìòù_ü_ç",this._charsWithoutAccentuation="AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c",this._changeDeboucingTimeout=null,this._limitCharsToSearch=3,this._deboucingTime=450,this._gridDataSource=[],this.pesquisaFetcher=new n,this._itemList=void 0,this._startLoading=!1,this._presentationMode="list",this._currentView=void 0,this.searchLoader=void 0,this.treeLoader=void 0,this.selectItem=void 0,this.entityName=void 0,this.argument=void 0,this.isHierarchyEntity=!1,this.allowsNonAnalytic=!1}observeArgument(){this._textInput&&(this._textInput.value=this.argument)}clearSearch(){this.argument="",this._itemList=void 0}buildDetails(s,i){let t={};for(let e=0;e<s.length;e++){const r=s[e],a=i[r.fieldName];t[r.description]=this.highlightValue(i.__matchFields,r.options&&r.options[a]||a,s,!0)}return t}buildFirstFields(s,i,t=6){return s&&Array.isArray(s)&&s.forEach((s=>{let t=this.removeReference(i,this._mdByName[s]);t&&i.unshift(t)})),i=i.slice(0,t)}doSearch(s){this.searchLoader&&"function"==typeof this.searchLoader&&(this._startLoading=!0,this.searchLoader(s).then((s=>{s&&this.processSearchResponse(s)})).finally((()=>{this._startLoading=!1})))}processSearchResponse(s){let i=(s=r.stringToObject(s.json.$)).descriptionField,t=s.pkField;t&&(this._gridMetadata=l(s),this._gridDataSource=[...s.data],this._pkField=t,this._descriptionField=i,this._itemList=this.buildCardItemList(s,t,i))}buildCardItemList(s,i,t){var e;return null===(e=s.data)||void 0===e?void 0:e.map((e=>{var r;let a=this.filterFieldsMetadata(s,e),o=this.buildFirstFields(e.__matchFields,a);return{key:this.highlightValue(e.__matchFields,null===(r=e[i])||void 0===r?void 0:r.toString(),o,!0),title:t?this.highlightValue(e.__matchFields,e[t],o,!0):"",details:this.buildDetails(o,e)}}))}filterFieldsMetadata(s,i){return s.fieldsMetadata.filter((t=>{let e=!a.isEmpty(i[t.fieldName])&&!1!==t.visible&&"B"!==t.type&&s.pkField!==t.fieldName&&s.descriptionField!==t.fieldName&&(t.isPrimaryKey||!t.isLinkField)&&!("S"===t.type&&"H"===t.presentationType);return e&&(this._mdByName[t.fieldName]=t),("string"!=typeof i[t.fieldName]||!(i[t.fieldName].indexOf("<img")>-1||i[t.fieldName].indexOf("<svg")>-1))&&e}))}removeAtIndex(s,i){if(i>=0&&i<s.length)return s.splice(i,1)[0]}removeReference(s,i){let t=this.indexOf(s,i);return this.removeAtIndex(s,t)}indexOf(s,i){let t=-1;return Array.isArray(s)&&this.find(s,((s,e)=>(t=e,this.equals(i,s)))),t}equals(s,i){return r.objectToString(s)===r.objectToString(i)}find(s,i){if(s)for(let t=0,e=s.length;t<e;t++)if(i(s[t],t,s))return s[t]}highlightValue(s,i,t,e){let r=this.replaceHtmlEntities(i);if(this.argument&&(e||this.isIn(s,t.fieldName))){const s=this.getArgumentNumber();let i=(isNaN(s)?this.argument:s.toString()).split(/%|,|\s+/),e=0,a=this.replaceAccentuatedChars(r);i.forEach((s=>{if(s){s=this.replaceAccentuatedChars(s);let i=this.getSpecialCharacters(s);null!=i&&i.length>0&&(s=this.removeSpecialCharacters(s)),(t.mask||"CGC_CPF"===t.uiType||"Phone"===t.uiType)&&(s=s.split("").join("\\.?\\-?\\/?\\(?\\)?"));let o=new RegExp(s,"ig");o.lastIndex=e;let n=o.exec(a);if(n&&n.length>0){e=n.index;let s=n[0].length,i=r.substring(e,e+s),t=(null==i?void 0:i.trim())?this._startHighlightTag+i+this._endHighlightTag:"",o=r.substring(0,e),l=r.substring(e+s);r=o+t+l,e+=t.length,a=this.replaceAccentuatedChars(r)}}}))}return r}replaceHtmlEntities(s){return null==s?s:String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}replaceAccentuatedChars(s){return null==s?s:this.replaceToSpace(s,["&amp;","&lt;","&gt;","&quot;"]).replace(/[^\w ]/g,(s=>{let i=this._charsWithAccentuation.indexOf(s);return i>-1&&(s=this._charsWithoutAccentuation.charAt(i)),s||""}))}replaceToSpace(s,i=[]){return null==s||i.forEach((i=>{const t=new RegExp(i,"g");let e="";for(let s=0;s<i.length;s++)e+=" ";s=String(s).replace(t,e)})),s}isIn(s,i){return this.indexOf(s,i)>-1}getSpecialCharacters(s){let i,t=[];for(;i=this._specialCharsRegex.exec(s);)t.push(s[i.index]);return t}removeSpecialCharacters(s){return this.getSpecialCharacters(s).forEach((i=>{s=this.replaceAll(s,i,"")})),s}replaceAll(s,i,t){let e=(null!=s?s:"").indexOf(i);for(;e>-1;)e=(s=s.replace(i,t)).indexOf(i);return s}getArgumentNumber(){return Number(this.argument||void 0)}createOption(s){let{key:i,title:t}=s;const e=new RegExp(this._startHighlightTag,"g"),r=new RegExp(this._endHighlightTag,"g");t=a.decodeHtmlEntities(t);const o={value:null==i?void 0:i.replace(e,"").replace(r,""),label:null==t?void 0:t.replace(e,"").replace(r,"")};this.selectItem(o)}onChangeValue(s){var i;if(this.clearDeboucingTimeout(),this._startLoading)return void(this._changeDeboucingTimeout=setTimeout((()=>{this.onChangeValue(s)}),this._deboucingTime));if(this.argument=(s.detail||"").trim(),this.isHierarchyEntity&&"list"===this._presentationMode)return void(null===(i=this._pesquisaTree)||void 0===i||i.applyFilter());const t=this.getArgumentNumber();this.argument&&(!isNaN(t)||this.argument.length>=this._limitCharsToSearch)?this._changeDeboucingTimeout=setTimeout((()=>{this.doSearch(isNaN(t)?this.argument:t.toString())}),this._deboucingTime):this._itemList=void 0}clearDeboucingTimeout(){this._changeDeboucingTimeout&&(clearTimeout(this._changeDeboucingTimeout),this._changeDeboucingTimeout=void 0)}onClickSearch(){this.doSearch((this.argument||"").trim())}getMessageView(){return this._startLoading?"Aguarde, buscando registros...":this._itemList?this._itemList.length>=1?`${this._itemList.length} ${this._itemList.length>1?"registros encontrados":"registro encontrado"}`:"Nenhum registro encontrado":"Os resultados de sua pesquisa aparecerão aqui..."}async componentWillLoad(){const s=await this.pesquisaFetcher.loadPresentationConfig(this.entityName);this._presentationMode="list"===s?"list":"table"}async componentDidLoad(){o.addIDInfo(this._element),await this.chooseViewMode()}async handleChangeViewMode(){this._presentationMode="list"===this._presentationMode?"table":"list",await this.chooseViewMode(),await this.pesquisaFetcher.savePresentationConfig(this.entityName,this._presentationMode)}async chooseViewMode(){var s,i;if("list"!==this._presentationMode)return await(null===(s=this._viewStack)||void 0===s?void 0:s.show(c.GRID)),void(this._currentView=c.GRID);const t=this.isHierarchyEntity?c.TREE:c.CARDS;await(null===(i=this._viewStack)||void 0===i?void 0:i.show(t)),this._currentView=t}hideLimitMessage(){return!this._itemList||this._itemList.length<100}hideRecordsMessage(){return"list"===this._presentationMode&&this.isHierarchyEntity}getButtonModeInfo(){return"list"===this._presentationMode?{iconName:"table",title:"Modo grade"}:this.isHierarchyEntity?{iconName:"hierarchical-tree",title:"Modo árvore hierárquica"}:{iconName:"list",title:"Modo lista"}}render(){var s,e;return i(t,null,i("div",{class:"snk-pesquisa"},i("div",{class:"snk-pesquisa__input"},i("ez-text-input",{label:"Buscar",class:"ez-margin-right--medium",canShowError:!1,ref:s=>this._textInput=s,onEzChange:s=>this.onChangeValue(s),value:this.argument,"data-element-id":"searchInput"},i("ez-icon",{slot:"leftIcon",iconName:"search"}),this.argument&&(null===(s=this._textInput)||void 0===s?void 0:s.value)?i("button",{slot:"rightIcon",class:"snk-pesquisa__btn",onClick:()=>this.clearSearch()},i("ez-icon",{iconName:"close"})):void 0),i("ez-button",{class:"ez-button--primary",label:"Pesquisar",onClick:()=>this.onClickSearch()}),i("ez-button",{class:"ez-margin-left--medium",mode:"icon",iconName:this.getButtonModeInfo().iconName,title:this.getButtonModeInfo().title,onClick:async()=>await this.handleChangeViewMode()})),i("div",{class:"snk-pesquisa__records-label "+(this._currentView===c.TREE?"hidden":"")},i("label",{class:"snk-pesquisa__records "+(this.hideRecordsMessage()?"hidden":"")},this.getMessageView()),i("label",{class:"snk-pesquisa__records-limit "+(this.hideLimitMessage()?"hidden":"")},"Essa pesquisa foi limitada, existem mais resultados.")),i("div",{class:"snk-pesquisa__content"},i("ez-view-stack",{ref:s=>this._viewStack=s,"data-element-id":"simple-crud"},i("stack-item",null,i("pesquisa-grid",{metadata:this._gridMetadata,dataSource:this._gridDataSource,pkField:this._pkField,descriptionField:this._descriptionField,entityName:this.entityName,shouldLoadConfig:this._currentView===c.GRID,onPesquisaGridSelectItem:({detail:s})=>this.selectItem(s)})),i("stack-item",null,i("div",{class:"snk-pesquisa__cards-container"},null===(e=this._itemList)||void 0===e?void 0:e.map((s=>i("ez-card-item",{onEzClick:s=>this.createOption(s.detail),item:s}))))),i("stack-item",null,i("pesquisa-tree",{ref:s=>this._pesquisaTree=s,argument:this.argument,treeLoader:this.treeLoader,allowsNonAnalytic:this.allowsNonAnalytic,shouldLoadTree:this._currentView===c.TREE,onPesquisaTreeSelectItem:({detail:s})=>this.selectItem(s)}))))))}get _element(){return e(this)}static get watchers(){return{argument:["observeArgument"]}}};u.style=".sc-snk-pesquisa-h{--snk-pesquisa--font-size:var(--text--medium, 14px);--snk-pesquisa--font-family:var(--font-pattern, Arial);--snk-pesquisa--font-weight:var(--text-weight--medium, 400);--snk-pesquisa__records--color:var(--text--primary, #626e82);--snk-pesquisa__records--color-secondary:var(--text--secondary, #626e82);--snk-pesquisa__records--padding-vertical:var(--space--medium, 12px);--snk-pesquisa__content--padding-right:var(--space--small, 6px);--snk-pesquisa__btn--color:var(--title--primary, #2B3A54);--snk-pesquisa__btn-disabled--color:var(--text--disable, #AFB6C0);--snk-pesquisa__btn-hover--color:var(--color--primary, #4e4e4e);--snk-pesquisa__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-pesquisa__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-pesquisa__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-pesquisa__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-pesquisa__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-pesquisa__scrollbar--width:var(--space--medium, 12px);height:100%;display:flex;flex-direction:column;overflow-y:auto}.snk-pesquisa.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%}.snk-pesquisa__input.sc-snk-pesquisa{display:flex;width:100%;box-sizing:border-box;padding-top:4px;padding-right:4px}.snk-pesquisa__input.sc-snk-pesquisa ez-icon.sc-snk-pesquisa{--ez-icon--color:inherit;font-weight:var(--text-weight--large, 600)}.snk-pesquisa__content.sc-snk-pesquisa{display:flex;flex-direction:column;overflow-y:hidden;scrollbar-width:thin;scrollbar-color:var(--snk-pesquisa__scrollbar--color-clicked) var(--snk-pesquisa__scrollbar--color-background);padding-right:var(--snk-pesquisa__content--padding-right);height:100vh}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar{background-color:var(--snk-pesquisa__scrollbar--color-background);width:var(--snk-pesquisa__scrollbar--width);max-width:var(--snk-pesquisa__scrollbar--width);min-width:var(--snk-pesquisa__scrollbar--width)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-track{background-color:var(--snk-pesquisa__scrollbar--color-background);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb{background-color:var(--snk-pesquisa__scrollbar--color-default);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:hover,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-pesquisa__scrollbar--color-hover)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:active,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-pesquisa__scrollbar--color-clicked)}.snk-pesquisa__records-label.sc-snk-pesquisa{display:flex;flex-direction:row;justify-content:space-between;font-family:var(--snk-pesquisa--font-family);font-weight:var(--snk-pesquisa--font-weight);font-size:var(--snk-pesquisa--font-size);padding-bottom:var(--snk-pesquisa__records--padding-vertical);padding-top:var(--snk-pesquisa__records--padding-vertical)}.snk-pesquisa__records-label.hidden.sc-snk-pesquisa{display:none}.snk-pesquisa__records.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color)}.snk-pesquisa__records-limit.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color-secondary)}.snk-pesquisa__records-limit.hidden.sc-snk-pesquisa,.snk-pesquisa__records.hidden.sc-snk-pesquisa{visibility:hidden}.snk-pesquisa__btn.sc-snk-pesquisa{outline:none;border:none;background:none;cursor:pointer;color:var(--snk-pesquisa__btn--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled:hover{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:hover{color:var(--snk-pesquisa__btn-hover--color)}.snk-pesquisa__cards-container.sc-snk-pesquisa{height:100%;overflow-y:auto}";export{u as snk_pesquisa}
@@ -1 +1 @@
1
- import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as n,StringUtils as o,ApplicationContext as h,ObjectUtils as a,DataType as r,JSUtils as d,FloatingManager as l,KeyboardManager as u,ElementIDUtils as c}from"@sankhyalabs/core";import{CSSVarsUtils as m}from"@sankhyalabs/ezui/dist/collection/utils";import{V as v,S as p}from"./p-95ce311a.js";import{T as g}from"./p-7e7a7473.js";import"./p-d62228fb.js";import"./p-4fe8bb73.js";import{C as f,S as C,R as b,b as k,a as S}from"./p-ee759111.js";import{D as y,P as w}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as E}from"./p-ddefbbc7.js";import"./p-ff1990ad.js";import{F as _}from"./p-1435701f.js";import{T as I,b as T,o as F}from"./p-23736d75.js";import{C as R}from"./p-19dc71e9.js";import{S as D}from"./p-aaef93e8.js";import{g as z}from"./p-7dd49d15.js";import{s as M}from"./p-6dc031de.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const O=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],L=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class N extends f{getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return z(this.dataUnit)}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[y.EXPORT_BY_EMAIL,y.EXPORT_PDF_TO_EMAIL,y.EXPORT_XLS_TO_EMAIL,y.EXPORT_PAGE_TO_PDF,y.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,o=i[e||s];if(null==o)return"";if(null!=e)return o.label;if(this.dataUnit.getField(s).userInterface===n.SEARCH)return o.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(o,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,o)}}const P=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new C,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new _,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new I({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[g.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[g.DATA_EXPORTER,g.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[g.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[g.DATA_EXPORTER,g.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":this.getFinishEditionButtonsCallback.bind(this)}),this._showPopUpGridConfig=!1,this._currentViewMode=v.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${o.generateUUID()}`,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=p.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this._enableContinuousInsert=!0,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0,this.outlineMode=!1}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){o.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},n),{[t]:s})),this._fieldsProps=e}getFinishEditionButtonsCallback(){const i=["CANCEL","SAVE"];return this.enableGridInsert&&this._currentViewMode!==v.ATTACHMENT&&i.push(this._currentViewMode===v.GRID?g.FORM_MODE:g.GRID_MODE),i}getButtons(i,t,s){let e=i?L:O;return s&&(e=e.filter((i=>i!==g.REFRESH))),this.addConfigButton(this.resolveInMemoryBtns(e).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(g.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===p.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===g.CONFIGURATOR?this._snkConfigurator.open():t===g.GRID_MODE?this.goToView(v.GRID):t===g.FORM_MODE&&this.goToView(v.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==p.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){a.objectToString(t)!=a.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===v.GRID?this.openGridConfig():i===v.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){(this.formLegacyConfigName||this.configName)&&await this._snkSimpleFormConfig.show()}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&R.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{R.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1,t=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let s=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=s)return this._formConfigManager.setConfig(s),void this.setFormConfig(s,t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new b,this._continuousInsertUtils=new k(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidLoad(){m.applyVarsGrid(this._element,this._grid),this.initKeyboardManager()}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===v.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===v.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new E(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:r[i.getAttribute("dataType")]||r.TEXT,userInterface:n[i.getAttribute("userInterface")]||n.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!n.includes(i.name)&&n.push(i.name)})),n.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,n,o;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(g.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(g.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(g.FORM_MODE),(null===(o=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===o?void 0:o.length)>1&&h.push(g.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(v.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=T(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){a.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getActionsList(){var i,t;const s=[{value:o.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===v.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(this.enableGridInsert&&s.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return s;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return this.actionsList?s.concat(this.actionsList):s}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${w.PRIMARY}`:`snkGridTopTaskbar.regular${w.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===v.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await F(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){i.stopPropagation(),this.configName&&R.saveGridConfig(i.detail,this.configName,this.resolveResourceID())}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new N(this.dataUnit,this._grid);M.set("exporterProviders",Object.assign(Object.assign({},M.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,S.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}getPageSize(){return this.mode===p.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}resolveResourceID(){return o.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){let i=this.formConfig;null==this.formLegacyConfigName&&(i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields})),this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(v.FORM)}async initKeyboardManager(){var i;const t=new u,s=this.dataUnit||await(null===(i=this._snkDataUnit)||void 0===i?void 0:i.getDataUnit());null!=s&&t.bind("F7",(()=>s.saveData()),{description:"Salva os dados.",element:this._element}).bind("F8",s.addRecord.bind(s),{description:"Adiciona um novo registro.",element:this._element}).bind("F9",s.removeSelectedRecords.bind(s),{description:"Remove o registro selecionado.",element:this._element}).bind("Escape",(()=>{s.isDirty()&&s.cancelEdition()}),{debounceTime:1e3,description:"Cancela uma ação.",element:this._element})}async handleFormConfigSaved(){await this.loadFormConfig(!0,!0)}renderTaskbarContent(){var i;return s("snk-taskbar",{class:this._currentViewMode===v.FORM&&`ez-box ${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(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:w.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}))}render(){var i;if(null!=this.dataUnit)return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===v.GRID,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:`ez-box ${this.outlineMode?"ez-box--outline":"ez-box--shadow"} simple-crud__container-section`},s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(v.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(E.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},this.renderTaskbarContent(),s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,this.renderTaskbarContent(),s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large",dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),s("snk-simple-form-config",{ref:i=>this._snkSimpleFormConfig=i,dataUnit:this.dataUnit,onSnkConfigSaved:this.handleFormConfigSaved.bind(this),configName:null!==(i=this.formLegacyConfigName)&&void 0!==i?i:this.configName})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(c.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};P.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{P as snk_simple_crud}
1
+ import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as n,StringUtils as o,ApplicationContext as h,ObjectUtils as a,DataType as r,JSUtils as d,FloatingManager as l,KeyboardManager as u,ElementIDUtils as c}from"@sankhyalabs/core";import{CSSVarsUtils as m}from"@sankhyalabs/ezui/dist/collection/utils";import{V as v,S as p}from"./p-95ce311a.js";import{T as g}from"./p-7e7a7473.js";import"./p-d62228fb.js";import"./p-c9f22653.js";import{C as f,S as C,R as b,b as k,a as S}from"./p-dd37be7e.js";import{D as y,P as w}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as E}from"./p-78d49c74.js";import"./p-ff1990ad.js";import{F as _}from"./p-1435701f.js";import{T as I,b as T,o as F}from"./p-23736d75.js";import{C as R}from"./p-19dc71e9.js";import{S as D}from"./p-aaef93e8.js";import{g as z}from"./p-7dd49d15.js";import{s as M}from"./p-6dc031de.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const O=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],L=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class N extends f{getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return z(this.dataUnit)}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[y.EXPORT_BY_EMAIL,y.EXPORT_PDF_TO_EMAIL,y.EXPORT_XLS_TO_EMAIL,y.EXPORT_PAGE_TO_PDF,y.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,o=i[e||s];if(null==o)return"";if(null!=e)return o.label;if(this.dataUnit.getField(s).userInterface===n.SEARCH)return o.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(o,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,o)}}const P=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new C,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new _,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new I({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[g.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[g.DATA_EXPORTER,g.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[g.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[g.DATA_EXPORTER,g.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":this.getFinishEditionButtonsCallback.bind(this)}),this._showPopUpGridConfig=!1,this._currentViewMode=v.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${o.generateUUID()}`,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=p.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this._enableContinuousInsert=!0,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0,this.outlineMode=!1}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){o.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},n),{[t]:s})),this._fieldsProps=e}getFinishEditionButtonsCallback(){const i=["CANCEL","SAVE"];return this.enableGridInsert&&this._currentViewMode!==v.ATTACHMENT&&i.push(this._currentViewMode===v.GRID?g.FORM_MODE:g.GRID_MODE),i}getButtons(i,t,s){let e=i?L:O;return s&&(e=e.filter((i=>i!==g.REFRESH))),this.addConfigButton(this.resolveInMemoryBtns(e).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(g.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===p.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===g.CONFIGURATOR?this._snkConfigurator.open():t===g.GRID_MODE?this.goToView(v.GRID):t===g.FORM_MODE&&this.goToView(v.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==p.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){a.objectToString(t)!=a.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===v.GRID?this.openGridConfig():i===v.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){(this.formLegacyConfigName||this.configName)&&await this._snkSimpleFormConfig.show()}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&R.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{R.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1,t=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let s=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=s)return this._formConfigManager.setConfig(s),void this.setFormConfig(s,t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new b,this._continuousInsertUtils=new k(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidLoad(){m.applyVarsGrid(this._element,this._grid),this.initKeyboardManager()}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===v.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===v.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new E(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:r[i.getAttribute("dataType")]||r.TEXT,userInterface:n[i.getAttribute("userInterface")]||n.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!n.includes(i.name)&&n.push(i.name)})),n.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,n,o;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(g.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(g.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(g.FORM_MODE),(null===(o=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===o?void 0:o.length)>1&&h.push(g.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(v.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=T(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){a.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getActionsList(){var i,t;const s=[{value:o.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===v.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(this.enableGridInsert&&s.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return s;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return this.actionsList?s.concat(this.actionsList):s}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${w.PRIMARY}`:`snkGridTopTaskbar.regular${w.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===v.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await F(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){i.stopPropagation(),this.configName&&R.saveGridConfig(i.detail,this.configName,this.resolveResourceID())}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new N(this.dataUnit,this._grid);M.set("exporterProviders",Object.assign(Object.assign({},M.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,S.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}getPageSize(){return this.mode===p.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}resolveResourceID(){return o.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){let i=this.formConfig;null==this.formLegacyConfigName&&(i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields})),this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new D(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(v.FORM)}async initKeyboardManager(){var i;const t=new u,s=this.dataUnit||await(null===(i=this._snkDataUnit)||void 0===i?void 0:i.getDataUnit());null!=s&&t.bind("F7",(()=>s.saveData()),{description:"Salva os dados.",element:this._element}).bind("F8",s.addRecord.bind(s),{description:"Adiciona um novo registro.",element:this._element}).bind("F9",s.removeSelectedRecords.bind(s),{description:"Remove o registro selecionado.",element:this._element}).bind("Escape",(()=>{s.isDirty()&&s.cancelEdition()}),{debounceTime:1e3,description:"Cancela uma ação.",element:this._element})}async handleFormConfigSaved(){await this.loadFormConfig(!0,!0)}renderTaskbarContent(){var i;return s("snk-taskbar",{class:this._currentViewMode===v.FORM&&`ez-box ${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(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:w.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}))}render(){var i;if(null!=this.dataUnit)return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===v.GRID,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:`ez-box ${this.outlineMode?"ez-box--outline":"ez-box--shadow"} simple-crud__container-section`},s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(v.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(E.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},this.renderTaskbarContent(),s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,this.renderTaskbarContent(),s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large",dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),s("snk-simple-form-config",{ref:i=>this._snkSimpleFormConfig=i,dataUnit:this.dataUnit,onSnkConfigSaved:this.handleFormConfigSaved.bind(this),configName:null!==(i=this.formLegacyConfigName)&&void 0!==i?i:this.configName})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(c.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};P.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{P as snk_simple_crud}
@@ -1 +1 @@
1
- import{r as i,c as e,h as t,F as s}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as a}from"@sankhyalabs/core";import{S as n}from"./p-aaef93e8.js";import{buildFormMetadata as d,FormMetadata as o}from"@sankhyalabs/ezui/dist/collection/utils/form";import{o as h,T as l,b as u}from"./p-23736d75.js";import{T as c}from"./p-7e7a7473.js";import{V as v}from"./p-95ce311a.js";import"./p-d62228fb.js";import"./p-4fe8bb73.js";import{P as g}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ddefbbc7.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import{SelectionMode as m}from"@sankhyalabs/core/dist/dataunit/DataUnit";const k="__FORM:",f=class{constructor(t){i(this,t),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={}}observeDataUnit(){this.loadGuides(!0)}observeDataState(i,e){const t=null==i?void 0:i.selectedRecord,s=null==e?void 0:e.selectedRecord;(null==t?void 0:t.__record__id__)!==(null==s?void 0:s.__record__id__)&&this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected())}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async findField(){await h(this._moreOptions,this._fieldSearch)}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,t){const s={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:t})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),s)}async setFocus(){this._container.focus()}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===c.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){f.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=d(this.masterFormConfig,this.dataUnit,!0);const e=this._masterFormMetadata.getAllSheets(),t=this.dataUnit.getSelectedRecord(),s=!t||this.dataUnit.isNewRecord(t.__record__id__),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&s&&(e.tooltip="Para alterar detalhes é necessário estar com um registro selecionado.",e.disabled=!0),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}isDetail(i){return null!=o.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}getTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkGuideViewer.finish_edition":"snkGuideViewer.regular"}loadTaskbarProcessor(){var i;const e=this.getTaskBarId(),t=[];this.dataState&&this.dataState.hasPrevious||t.push("PREVIOUS"),this.dataState&&this.dataState.hasNext||t.push("NEXT"),(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&(this.dataState.selectionInfo.length>1&&t.push("CLONE"),this.dataState.selectionInfo.isAllRecords()&&t.push("REMOVE"));const s=["PREVIOUS","NEXT","DIVIDER","ATTACH","CLONE","REMOVE","MORE_OPTIONS","ACTIONS_BUTTON","DIVIDER","GRID_MODE","CONFIGURATOR"];this.presentationMode==g.SECONDARY?s.unshift("INSERT"):s.push("INSERT");const r=this.getInvisibleButtons();this._taskbarProcessor=new l({"snkGuideViewer.regular":s,"snkGuideViewer.finish_edition":["CANCEL","SAVE",this.handleAddGridMode()]}),this._taskbarProcessor.process(e,this.taskbarManager,this.dataState,t,r)}handleAddGridMode(){return this.enableGridInsert?c.GRID_MODE:""}getInvisibleButtons(){const i=[];return this.dataState&&this.dataState.selectionInfo.mode===m.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}static updateContentCard(i,e,t,s){return s.saveCardState(i,e,t)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return t(s,null,Array.from(r.entries()).filter((([e,t])=>(null==t?void 0:t.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,s])=>{var r,a;const n=i.formMetadata.getSheet(e);if(null!=n)return t("snk-form-view",{levelPath:i.levelPath,label:n.label,name:e,fields:n.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==s?void 0:s.presentation),fixed:null==s?void 0:s.fixed,summaryFields:null===(a=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps})})))}wrapDetail(i,e){if(0===i.length)return e;const s=i.pop(),r=o.getDetailName(s);return r?this.wrapDetail(i,t("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const t=i.map((i=>o.getDetailName(i)));return`${this.entityPath}/${t.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){var i,e,s,r,a;if(!this.selectedGuide)return;const n=this.selectedGuide.id;let d;const h=n.split("::"),l=h.pop(),u=o.getDetailName(l);let c=n;if(u||h.length>0){let e,s;if(n.includes(k)){[c,e]=n.split(k);const t=(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)||0;s=t>1?this._breadcrumbItems[t-2]:this.selectedGuide}else s=this.selectedGuide;d=this.wrapDetail(h,t("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(h,u),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:u,selectedForm:e,branchGuide:s,guideItemPath:this._breadcrumbItems,key:`detail${c}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders}))}else{const i=this.selectedGuide.id,o=this._masterFormMetadata.getSheet(i);if(o){const h=null===(s=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===s?void 0:s.get(i);d=t("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==h?void 0:h.fixed,summaryFields:null===(a=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(i),name:i,label:o.label,fields:o.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:n,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps},this.presentationMode==g.SECONDARY&&this.buildTaskBar())}}return d}onBreadcrumbClickHandler(i){null!=(null==i?void 0:i.id)&&this._guideNavigator.selectGuide(i.id)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))]}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error("Erro interno: resourceID não informado");this._configManager=new n(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(this._currentDetail?this._currentDetail.showUp():this._mainForm&&this._mainForm.showUp(),this._guideHasChanged=!1)}getFieldsSearch(i,e){return(null==this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._moreOptions=i,i.addEventListener("taskbarActionsButtonDisconnected",(()=>this._hasToCreateFieldSearch=!0)),this._fieldSearch=u(e,(({argument:i})=>this.fieldsOptionLoader(i)),(e=>this.onSelectField(e,i)))),this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}onSelectField(i,e){if(null==i)return;this._fieldToGetFocus=i.value;const t=this.getGuideName(i.value);t!==this.selectedGuide.id&&this.changeGuideHandler(t),e.hideActions()}getActionsList(){return[{value:"",label:this.getMessage("snkCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,e)=>this.getFieldsSearch(i,e)}].concat(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions?this.taskbarManager.getMoreOptions(this.getTaskBarId(),this.configName,this.dataState,this.actionsList):this.actionsList)}buildTaskBar(){var i;return t("div",{class:"snk-guides-viewer__header-taskbar "+(this.presentationMode!=g.SECONDARY?"ez-align--right":"ez-padding-bottom--medium")},t("snk-taskbar",{key:"guideViewerTaskbar","data-element-id":"guideViewer",configName:this.configName,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,actionsList:this.getActionsList(),messagesBuilder:this.messagesBuilder,presentationMode:this.presentationMode,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-taskbar-owner":"master",dataUnit:this.dataUnit,resourceID:this.resourceID,customSlotId:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS",alignRigth:!0},t("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"})))}async dataUnitActionHandler(i){var e;if(i.type===r.FIELD_INVALIDATED){const t=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(t),await this.openGuideNavigator(t)}i.type===r.METADATA_LOADED&&this.loadGuides(this.noGuideSelected())}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var t;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(t=i.badge)&&void 0!==t?t:null}getGuideName(i){var e;for(const t of this._masterFormMetadata.getAllSheets()){const s=null===(e=t[1])||void 0===e?void 0:e.fields;for(const e of s)if(e.name===i)return t[0]}return""}getTitle(){var i,e;return null!==(e=null===(i=this.getCustomTitle)||void 0===i?void 0:i.call(this))&&void 0!==e?e:this.getMessage("snkCrud.title")}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}render(){var i,e;if(null!=this._formEditorConfigManager)return t("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,ignoreReadOnlyFormFields:this.ignoreReadOnlyFormFields});if(!this.dataUnit||!this._configManager.isLoaded)return;this.loadTaskbarProcessor();const s=this._guides&&this._guides.length>1;return t("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabindex:-1},t("div",{class:"ez-row snk-guides-viewer__header"},t("div",{class:"snk-guides-viewer__header-breadcrumb ez-flex--align-items-center ez-flex-item--align-center ez-padding-left--large",key:"header"},t("ez-button",{onClick:()=>this.exitViewer(),title:this.getMessage("snkCrud.goBackTitle"),mode:"icon",iconName:"arrow_back",class:"ez-padding-right--medium",size:"small"}),t("div",{class:"ez-flex ez-flex--column ez-flex-item--auto"},t("h1",{class:"ez-title ez-title--primary ez-title--xlarge"},this.getTitle()),(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)>1&&t("div",{class:"ez-margin-top--extra-small"},t("ez-breadcrumb",Object.assign({items:this._breadcrumbItems,onSelectedItem:i=>this.onBreadcrumbClickHandler(null==i?void 0:i.detail)},{[a.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${a.getInternalIDInfo("breadcrumb")}`}))))),this.presentationMode!=g.SECONDARY&&this.buildTaskBar()),t("div",{class:"snk-guides-viewer__container"},s?t("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):t("div",null),t("div",{class:"snk-guides-viewer__detail-container"},f.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps}),this.getContent())),t("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID}))}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};f.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:68px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;display:block}snk-form-view.sc-snk-guides-viewer{width:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding-left:0px;padding-top:0px;padding-right:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:calc(var(--snk-guides-viewer__header--min-height) + var(--snk-guides-viewer--space-small));height:calc(100vh - var(--snk-guides-viewer__header--min-height) - var(--snk-guides-viewer--space-large) - var(--snk-guides-viewer--space-small))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{f as S}
1
+ import{r as i,c as e,h as t,F as s}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as a}from"@sankhyalabs/core";import{S as n}from"./p-aaef93e8.js";import{buildFormMetadata as d,FormMetadata as o}from"@sankhyalabs/ezui/dist/collection/utils/form";import{o as h,T as l,b as u}from"./p-23736d75.js";import{T as c}from"./p-7e7a7473.js";import{V as v}from"./p-95ce311a.js";import"./p-d62228fb.js";import"./p-c9f22653.js";import{P as g}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-78d49c74.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import{SelectionMode as m}from"@sankhyalabs/core/dist/dataunit/DataUnit";const k="__FORM:",f=class{constructor(t){i(this,t),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={}}observeDataUnit(){this.loadGuides(!0)}observeDataState(i,e){const t=null==i?void 0:i.selectedRecord,s=null==e?void 0:e.selectedRecord;(null==t?void 0:t.__record__id__)!==(null==s?void 0:s.__record__id__)&&this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected())}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async findField(){await h(this._moreOptions,this._fieldSearch)}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,t){const s={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:t})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),s)}async setFocus(){this._container.focus()}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===c.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){f.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=d(this.masterFormConfig,this.dataUnit,!0);const e=this._masterFormMetadata.getAllSheets(),t=this.dataUnit.getSelectedRecord(),s=!t||this.dataUnit.isNewRecord(t.__record__id__),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&s&&(e.tooltip="Para alterar detalhes é necessário estar com um registro selecionado.",e.disabled=!0),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}isDetail(i){return null!=o.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}getTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkGuideViewer.finish_edition":"snkGuideViewer.regular"}loadTaskbarProcessor(){var i;const e=this.getTaskBarId(),t=[];this.dataState&&this.dataState.hasPrevious||t.push("PREVIOUS"),this.dataState&&this.dataState.hasNext||t.push("NEXT"),(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&(this.dataState.selectionInfo.length>1&&t.push("CLONE"),this.dataState.selectionInfo.isAllRecords()&&t.push("REMOVE"));const s=["PREVIOUS","NEXT","DIVIDER","ATTACH","CLONE","REMOVE","MORE_OPTIONS","ACTIONS_BUTTON","DIVIDER","GRID_MODE","CONFIGURATOR"];this.presentationMode==g.SECONDARY?s.unshift("INSERT"):s.push("INSERT");const r=this.getInvisibleButtons();this._taskbarProcessor=new l({"snkGuideViewer.regular":s,"snkGuideViewer.finish_edition":["CANCEL","SAVE",this.handleAddGridMode()]}),this._taskbarProcessor.process(e,this.taskbarManager,this.dataState,t,r)}handleAddGridMode(){return this.enableGridInsert?c.GRID_MODE:""}getInvisibleButtons(){const i=[];return this.dataState&&this.dataState.selectionInfo.mode===m.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}static updateContentCard(i,e,t,s){return s.saveCardState(i,e,t)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return t(s,null,Array.from(r.entries()).filter((([e,t])=>(null==t?void 0:t.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,s])=>{var r,a;const n=i.formMetadata.getSheet(e);if(null!=n)return t("snk-form-view",{levelPath:i.levelPath,label:n.label,name:e,fields:n.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==s?void 0:s.presentation),fixed:null==s?void 0:s.fixed,summaryFields:null===(a=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps})})))}wrapDetail(i,e){if(0===i.length)return e;const s=i.pop(),r=o.getDetailName(s);return r?this.wrapDetail(i,t("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const t=i.map((i=>o.getDetailName(i)));return`${this.entityPath}/${t.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){var i,e,s,r,a;if(!this.selectedGuide)return;const n=this.selectedGuide.id;let d;const h=n.split("::"),l=h.pop(),u=o.getDetailName(l);let c=n;if(u||h.length>0){let e,s;if(n.includes(k)){[c,e]=n.split(k);const t=(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)||0;s=t>1?this._breadcrumbItems[t-2]:this.selectedGuide}else s=this.selectedGuide;d=this.wrapDetail(h,t("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(h,u),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:u,selectedForm:e,branchGuide:s,guideItemPath:this._breadcrumbItems,key:`detail${c}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders}))}else{const i=this.selectedGuide.id,o=this._masterFormMetadata.getSheet(i);if(o){const h=null===(s=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===s?void 0:s.get(i);d=t("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==h?void 0:h.fixed,summaryFields:null===(a=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===a?void 0:a.get(i),name:i,label:o.label,fields:o.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:n,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps},this.presentationMode==g.SECONDARY&&this.buildTaskBar())}}return d}onBreadcrumbClickHandler(i){null!=(null==i?void 0:i.id)&&this._guideNavigator.selectGuide(i.id)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))]}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error("Erro interno: resourceID não informado");this._configManager=new n(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(this._currentDetail?this._currentDetail.showUp():this._mainForm&&this._mainForm.showUp(),this._guideHasChanged=!1)}getFieldsSearch(i,e){return(null==this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._moreOptions=i,i.addEventListener("taskbarActionsButtonDisconnected",(()=>this._hasToCreateFieldSearch=!0)),this._fieldSearch=u(e,(({argument:i})=>this.fieldsOptionLoader(i)),(e=>this.onSelectField(e,i)))),this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}onSelectField(i,e){if(null==i)return;this._fieldToGetFocus=i.value;const t=this.getGuideName(i.value);t!==this.selectedGuide.id&&this.changeGuideHandler(t),e.hideActions()}getActionsList(){return[{value:"",label:this.getMessage("snkCrud.findColumn"),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,e)=>this.getFieldsSearch(i,e)}].concat(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions?this.taskbarManager.getMoreOptions(this.getTaskBarId(),this.configName,this.dataState,this.actionsList):this.actionsList)}buildTaskBar(){var i;return t("div",{class:"snk-guides-viewer__header-taskbar "+(this.presentationMode!=g.SECONDARY?"ez-align--right":"ez-padding-bottom--medium")},t("snk-taskbar",{key:"guideViewerTaskbar","data-element-id":"guideViewer",configName:this.configName,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,actionsList:this.getActionsList(),messagesBuilder:this.messagesBuilder,presentationMode:this.presentationMode,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-taskbar-owner":"master",dataUnit:this.dataUnit,resourceID:this.resourceID,customSlotId:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS",alignRigth:!0},t("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"})))}async dataUnitActionHandler(i){var e;if(i.type===r.FIELD_INVALIDATED){const t=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(t),await this.openGuideNavigator(t)}i.type===r.METADATA_LOADED&&this.loadGuides(this.noGuideSelected())}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var t;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(t=i.badge)&&void 0!==t?t:null}getGuideName(i){var e;for(const t of this._masterFormMetadata.getAllSheets()){const s=null===(e=t[1])||void 0===e?void 0:e.fields;for(const e of s)if(e.name===i)return t[0]}return""}getTitle(){var i,e;return null!==(e=null===(i=this.getCustomTitle)||void 0===i?void 0:i.call(this))&&void 0!==e?e:this.getMessage("snkCrud.title")}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this))}render(){var i,e;if(null!=this._formEditorConfigManager)return t("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,ignoreReadOnlyFormFields:this.ignoreReadOnlyFormFields});if(!this.dataUnit||!this._configManager.isLoaded)return;this.loadTaskbarProcessor();const s=this._guides&&this._guides.length>1;return t("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabindex:-1},t("div",{class:"ez-row snk-guides-viewer__header"},t("div",{class:"snk-guides-viewer__header-breadcrumb ez-flex--align-items-center ez-flex-item--align-center ez-padding-left--large",key:"header"},t("ez-button",{onClick:()=>this.exitViewer(),title:this.getMessage("snkCrud.goBackTitle"),mode:"icon",iconName:"arrow_back",class:"ez-padding-right--medium",size:"small"}),t("div",{class:"ez-flex ez-flex--column ez-flex-item--auto"},t("h1",{class:"ez-title ez-title--primary ez-title--xlarge"},this.getTitle()),(null===(i=this._breadcrumbItems)||void 0===i?void 0:i.length)>1&&t("div",{class:"ez-margin-top--extra-small"},t("ez-breadcrumb",Object.assign({items:this._breadcrumbItems,onSelectedItem:i=>this.onBreadcrumbClickHandler(null==i?void 0:i.detail)},{[a.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:`${a.getInternalIDInfo("breadcrumb")}`}))))),this.presentationMode!=g.SECONDARY&&this.buildTaskBar()),t("div",{class:"snk-guides-viewer__container"},s?t("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):t("div",null),t("div",{class:"snk-guides-viewer__detail-container"},f.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps}),this.getContent())),t("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID}))}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};f.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:68px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;display:block}snk-form-view.sc-snk-guides-viewer{width:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding-left:0px;padding-top:0px;padding-right:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-large)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:calc(var(--snk-guides-viewer__header--min-height) + var(--snk-guides-viewer--space-small));height:calc(100vh - var(--snk-guides-viewer__header--min-height) - var(--snk-guides-viewer--space-large) - var(--snk-guides-viewer--space-small))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{f as S}
@@ -1 +1 @@
1
- import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-19dc71e9.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-23736d75.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as v,a as f,R as E,b as p}from"./p-ee759111.js";import{SelectionMode as b}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-d62228fb.js";import"./p-4fe8bb73.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ddefbbc7.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import{g as R}from"./p-7dd49d15.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class O extends k{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return R(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const C=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new v,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1,this.outlineMode=!1}reloadConfig(){this.loadConfig()}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async findColumn(){await g(this._moreOptions,this._columnSearch)}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){var t;if(this.hasToBlockEvent(i)){if(i.preventDefault(),i.stopPropagation(),!await this._dataUnit.cancelEdition())return;const s=new i.constructor(i.type,i);null===(t=i.target)||void 0===t||t.dispatchEvent(s)}this._grid&&!this._grid.contains(i.target)&&this._grid.stopEdit()}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?h.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,f.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new O(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),f.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new E,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new p(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(h.CLONE,"ATTACH",h.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===b.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?h.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};C.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding)}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}";export{C as snk_grid}
1
+ import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-19dc71e9.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-23736d75.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as v,a as E,R as f,b as p}from"./p-dd37be7e.js";import{SelectionMode as b}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-d62228fb.js";import"./p-c9f22653.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-78d49c74.js";import"./p-ff1990ad.js";import"./p-1435701f.js";import{g as R}from"./p-7dd49d15.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class O extends k{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return R(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const C=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new v,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1,this.outlineMode=!1}reloadConfig(){this.loadConfig()}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async findColumn(){await g(this._moreOptions,this._columnSearch)}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){var t;if(this.hasToBlockEvent(i)){if(i.preventDefault(),i.stopPropagation(),!await this._dataUnit.cancelEdition())return;const s=new i.constructor(i.type,i);null===(t=i.target)||void 0===t||t.dispatchEvent(s)}this._grid&&!this._grid.contains(i.target)&&this._grid.stopEdit()}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?h.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,E.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new O(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),E.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new f,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new p(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(h.CLONE,"ATTACH",h.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===b.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?h.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};C.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding)}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}";export{C as snk_grid}