import { h, Host } from '@stencil/core';
import { ApplicationContext, ElementIDUtils, StringUtils, KeyboardManager } from '@sankhyalabs/core';
import { TaskbarElement } from '../snk-taskbar/elements/taskbar-elements';
import { PresentationMode } from '../../lib';
import { VIEW_MODE } from '../../lib/utils/constants';
import { AutorizationType } from '../../lib/http/data-fetcher/fetchers/auth-fetcher';
import { ExporterStrategy } from '../../lib/@types';
/**
 * É possível customizar as mensagens dos blocos de construção através de um pequeno modulo na estrutura da aplicação:
 * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
 * Para conhecer os detalhes do módulo, vide os arquivos neste projeto "/src/lib/message/resources/*.msg.ts"
 */
export class SnkCrud {
  constructor() {
    this._viewHistory = [];
    this._customEditors = new Map();
    this._customRenders = new Map();
    this._dataUnit = undefined;
    this._dataState = undefined;
    this.attachmentRegisterKey = undefined;
    this._currentViewMode = VIEW_MODE.GRID;
    this._canEdit = undefined;
    this._resourceID = undefined;
    this.enableLockManagerLoadingComp = false;
    this.enableLockManagerTaskbarClick = false;
    this.configName = undefined;
    this.filterBarTitle = undefined;
    this.selectionToastConfig = undefined;
    this.showActionButtons = false;
    this.actionsList = undefined;
    this.taskbarManager = undefined;
    this.recordsValidator = undefined;
    this.statusResolver = undefined;
    this.multipleSelection = true;
    this.presentationMode = PresentationMode.PRIMARY;
    this.messagesBuilder = undefined;
    this.useEnterLikeTab = false;
    this.gridLegacyConfigName = undefined;
    this.filterBarLegacyConfigName = undefined;
    this.formLegacyConfigName = undefined;
    this.disablePersonalizedFilter = undefined;
    this.autoLoad = undefined;
    this.autoFocus = true;
    this.enableGridInsert = false;
    this.domainMessagesBuilder = undefined;
    this.ignoreReadOnlyFormFields = undefined;
    this.setCustomFormTitle = undefined;
    this.strategyExporter = ExporterStrategy.SERVER_SIDE;
    this.layoutFormConfig = true;
    this.multipleEditionEnabled = true;
    this.paginationCounterMode = 'auto';
    this.customContainerId = `SNK-CRUD-CUSTOM-CONTAINER-${StringUtils.generateUUID()}`;
  }
  /**
   * Usado para alternar a visão entre GRID e FORM externamente.
   */
  async goToView(mode) {
    this.executeAction(mode);
  }
  /**
   * Usado para abrir o configurator do CRUD
   */
  async openConfigurator() {
    var _a;
    (_a = this._snkConfigurator) === null || _a === void 0 ? void 0 : _a.open();
  }
  /**
   * Usado para fechar o configurator do CRUD
   */
  async closeConfigurator() {
    var _a;
    (_a = this._snkConfigurator) === null || _a === void 0 ? void 0 : _a.close();
  }
  /**
   * Faz o recarregamento da filter-bar do crud, buscando o state no servidor.
   */
  async reloadFilterBar() {
    var _a;
    (_a = this._snkGrid) === null || _a === void 0 ? void 0 : _a.reloadFilterBar();
  }
  /**
   * Retorna o elemento da filter-bar da grade.
   */
  async getFilterBar() {
    return await this._snkGrid.getFilterBar();
  }
  /**
   * Registra um editor customizado para campos da grade e formulário.
   */
  async addCustomEditor(fieldName, customEditor) {
    if (this._guidesViewer && this._snkGrid) {
      this._guidesViewer.addCustomEditor(fieldName, customEditor);
      this._snkGrid.addCustomEditor(fieldName, customEditor);
      return;
    }
    const newCustomEditors = new Map(this._customEditors);
    newCustomEditors.set(fieldName, customEditor);
    this._customEditors = newCustomEditors;
  }
  /**
   * Registra um render customizado para colunas da grid.
   */
  async addGridCustomRender(fieldName, customRender) {
    if (this._snkGrid) {
      this._snkGrid.addGridCustomRender(fieldName, customRender);
      return;
    }
    const newCustomRenders = new Map(this._customRenders);
    newCustomRenders.set(fieldName, customRender);
    this._customRenders = newCustomRenders;
  }
  /**
   * Registra um formatador de valores para uma coluna da grid.
   */
  async addCustomValueFormatter(columnName, customFormatter) {
    this._snkGrid.addCustomValueFormatter(columnName, customFormatter);
  }
  /**
   * Remove o formatador de valores de uma coluna da grid.
   */
  async removeCustomValueFormatter(columnName) {
    this._snkGrid.removeCustomValueFormatter(columnName);
  }
  /**
   * Altera/adiciona uma propriedade nos metadados do campo.
   */
  async setFieldProp(fieldName, propName, value) {
    await this._guidesViewer.setFieldProp(fieldName, propName, value);
  }
  currentViewModeWatcher(currentView) {
    this._viewHistory = [...this._viewHistory.slice(-1), currentView];
  }
  async gridToForm(keepFormMode = false) {
    this._backToGrid = !keepFormMode && await this._viewStack.getSelectedIndex() === VIEW_MODE.GRID;
    this.setViewMode(VIEW_MODE.FORM);
  }
  async executeAction(act) {
    switch (act) {
      case TaskbarElement.GRID_MODE:
        return this.setViewMode(VIEW_MODE.GRID);
      case TaskbarElement.FORM_MODE:
      case TaskbarElement.UPDATE:
        return this.gridToForm(act !== TaskbarElement.UPDATE);
      case TaskbarElement.UPDATE_MULTIPLE:
        this._dataUnit.isMultipleEdition = true;
        return this.setViewMode(VIEW_MODE.FORM);
      case TaskbarElement.CONFIGURATOR:
        return this._snkConfigurator.open();
      case TaskbarElement.ATTACH:
        return this.setViewMode(VIEW_MODE.ATTACHMENT);
    }
  }
  backView() {
    const lastView = this._viewHistory.at(-2) || VIEW_MODE.GRID;
    this.setViewMode(lastView);
  }
  setViewMode(viewMode) {
    this._viewStack.show(viewMode);
    this._currentViewMode = viewMode;
    if (viewMode === VIEW_MODE.GRID) {
      this._dataUnit.isMultipleEdition = false;
      this._snkGrid.setFocus();
    }
    else if (viewMode === VIEW_MODE.FORM) {
      this._guidesViewer.setFocus();
    }
    this.viewModeChanged.emit(viewMode);
  }
  openConfig(viewMode) {
    this._snkConfigurator.close();
    if (viewMode === VIEW_MODE.GRID) {
      this._snkGrid.showConfig();
    }
    else if (viewMode === VIEW_MODE.FORM) {
      this._guidesViewer.showFormConfig();
    }
  }
  addDataElementID() {
    const dataInfo = { dataUnit: this._dataUnit };
    ElementIDUtils.addIDInfo(this._element, null, dataInfo);
  }
  insertionModeHandler() {
    if (this.enableGridInsert)
      return;
    this.gridToForm();
  }
  cancelHandler() {
    if (this._backToGrid) {
      this.setViewMode(VIEW_MODE.GRID);
    }
  }
  async getAttachmentRegisterKey() {
    if (!this._snkDataUnit)
      return;
    const recordCriteria = await this._snkDataUnit.getSelectedRecordsIDsInfo();
    const joinedPrimaryKeys = recordCriteria.map(({ value }) => value).join('_');
    return joinedPrimaryKeys;
  }
  setCustomRenders() {
    if (!this._snkGrid) {
      return;
    }
    for (const [fieldName, customRender] of this._customRenders) {
      this._snkGrid.addGridCustomRender(fieldName, customRender);
      this._customRenders.delete(fieldName);
    }
  }
  setCustomEditors() {
    if (!this._snkGrid || !this._guidesViewer) {
      return;
    }
    for (const [fieldName, customEditor] of this._customEditors) {
      this._guidesViewer.addCustomEditor(fieldName, customEditor);
      this._snkGrid.addCustomEditor(fieldName, customEditor);
      this._customEditors.delete(fieldName);
    }
  }
  componentDidRender() {
    this.setCustomRenders();
    this.setCustomEditors();
  }
  componentWillLoad() {
    this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
    let parent = this._element.parentElement;
    this._application
      .hasAccess(AutorizationType.UPDATE, this._resourceID)
      .then(canEdit => this._canEdit = canEdit);
    while (parent) {
      if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
        this._snkDataUnit = parent;
        this._snkDataUnit.addEventListener("insertionMode", () => this.insertionModeHandler());
        this._snkDataUnit.addEventListener("cancelEdition", () => this.cancelHandler());
        this._snkDataUnit.domainMessagesBuilder = this.domainMessagesBuilder;
        this._dataUnit = this._snkDataUnit.dataUnit;
        this._dataState = this._snkDataUnit.dataState;
        if (!this._dataUnit) {
          this._snkDataUnit.addEventListener("dataUnitReady", (evt) => {
            this._dataUnit = evt.detail;
            this.initDataUnit();
          });
        }
        else {
          this.initDataUnit();
        }
        this._snkDataUnit.addEventListener("dataStateChange", this.handleDataStateChange.bind(this));
        break;
      }
      parent = parent.parentElement;
    }
    if (!this.configName) {
      this.configName = this._application.configName;
    }
  }
  componentDidLoad() {
    this.initKeyboardManager();
  }
  disconnectedCallback() {
    this.removeShortcuts();
  }
  async handleDataStateChange(evt) {
    var _a;
    this._dataState = evt.detail;
    if (this._dataState.selectedRecord !== undefined) {
      this.attachmentRegisterKey = await this.getAttachmentRegisterKey();
    }
    const fieldsWithRmPrecision = await this._snkDataUnit.getFieldsWithRmPrecision();
    for (const field of fieldsWithRmPrecision || []) {
      if (!field) {
        continue;
      }
      const rmPrecision = (_a = this._dataState.rowMetadata) === null || _a === void 0 ? void 0 : _a.getProp('rm_precision', field);
      if (!rmPrecision && rmPrecision !== 0) {
        continue;
      }
      await this.setFieldProp(field, 'precision', rmPrecision);
      await this.setFieldProp(field, 'prettyPrecision', rmPrecision);
    }
    ;
  }
  async initKeyboardManager() {
    this._keyboardManager = new KeyboardManager({ propagate: false, element: this._element });
    const dataUnit = this._dataUnit || await this._snkDataUnit.getDataUnit();
    async function saveDataUnitHandlingFocus() {
      const element = document.activeElement;
      const isDocumentBody = (element == document.body);
      if (!isDocumentBody)
        element.blur();
      await dataUnit.saveData();
      if (!isDocumentBody && element.setFocus != undefined) {
        element.setFocus();
        return;
      }
      if (!isDocumentBody)
        element.focus();
    }
    async function handleAddRecord() {
      if (!dataUnit.hasNewRecord()) {
        dataUnit.addRecord();
      }
    }
    if (this._keyboardManager) {
      this._keyboardManager
        .bind("F6", this.toggleView.bind(this), { description: this.getMessage("snkCrud.shortcuts.toggleView"), element: this._element })
        .bind("F7", saveDataUnitHandlingFocus.bind(this), { description: this.getMessage("snkCrud.shortcuts.saveData"), element: this._element })
        .bind("ctrl + \\", saveDataUnitHandlingFocus.bind(this), { description: this.getMessage("snkCrud.shortcuts.addRecord"), element: this._element })
        .bind("F8", handleAddRecord.bind(this), { description: this.getMessage("snkCrud.shortcuts.addRecord"), element: this._element })
        .bind("F9", dataUnit.removeSelectedRecords.bind(dataUnit), { description: this.getMessage("snkCrud.shortcuts.removeRecord"), element: this._element })
        .bind("ctrl + F9", dataUnit.removeSelectedRecords.bind(dataUnit), { description: this.getMessage("snkCrud.shortcuts.removeRecord"), element: this._element })
        .bind("F5", async () => {
        const currentView = await this._viewStack.getSelectedIndex();
        if (VIEW_MODE.GRID === currentView) {
          dataUnit.loadData();
        }
      }, { description: this.getMessage("snkCrud.shortcuts.refreshData"), element: this._element })
        .bind("Escape", () => {
        if (dataUnit.isDirty()) {
          dataUnit.cancelEdition();
        }
      }, {
        debounceTime: 1000,
        description: this.getMessage("snkCrud.shortcuts.cancelAction"), element: this._element
      });
    }
  }
  getMessage(key, params) {
    if (this.messagesBuilder)
      return this.messagesBuilder.getMessage(key, params);
  }
  async removeShortcuts() {
    var _a;
    (_a = this._keyboardManager) === null || _a === void 0 ? void 0 : _a.unbindAllShortcutKeys();
  }
  async toggleView() {
    const currentView = await this._viewStack.getSelectedIndex();
    this.setViewMode(VIEW_MODE.GRID === currentView ? VIEW_MODE.FORM : VIEW_MODE.GRID);
  }
  async initDataUnit() {
    this.addDataElementID();
    if (!this.messagesBuilder) {
      this.messagesBuilder = this._snkDataUnit.messagesBuilder;
    }
    if (this._resourceID == undefined) {
      //Tenta pegar o resourceID do snkDataUnit;
      this._resourceID = this._snkDataUnit.resourceID;
      if (this._resourceID == undefined) {
        this._resourceID = await this._application.getResourceID();
      }
    }
  }
  handleConfiguratorEvent(evt, type) {
    evt.stopImmediatePropagation();
    if (type === 'SAVE') {
      this.configuratorSave.emit();
      return;
    }
    this.configuratorCancel.emit();
  }
  render() {
    if (this._resourceID == undefined) {
      return;
    }
    this._snkDataUnit.ignoreSaveMessage = (this._currentViewMode === VIEW_MODE.GRID && !this.enableGridInsert);
    return (h(Host, null, h("ez-view-stack", { ref: (ref) => this._viewStack = ref, "data-element-id": "crud" }, h("stack-item", { class: 'ez-flex ez-flex--column ez-size-height--full ez-size-width--full ez-padding--medium' }, h("snk-grid", { ref: (ref) => this._snkGrid = ref, class: 'ez-flex ez-flex--column ez-size-height--full ez-size-width--full', filterBarTitle: this.filterBarTitle, "data-element-id": "crud_grid", configName: this.configName, onGridDoubleClick: () => this.gridToForm(true), taskbarManager: this.taskbarManager, onActionClick: evt => this.executeAction(evt.detail), messagesBuilder: this.messagesBuilder, actionsList: this.actionsList, statusResolver: this.statusResolver, multipleSelection: this.multipleSelection, presentationMode: this.presentationMode, recordsValidator: this.recordsValidator, selectionToastConfig: this.selectionToastConfig, useEnterLikeTab: this.useEnterLikeTab, canEdit: this._canEdit, resourceID: this._resourceID, disablePersonalizedFilter: this.disablePersonalizedFilter, gridLegacyConfigName: this.gridLegacyConfigName, filterBarLegacyConfigName: this.filterBarLegacyConfigName, autoLoad: this.autoLoad, autoFocus: this.autoFocus, enableGridInsert: this.enableGridInsert, enableLockManagerTaskbarClick: this.enableLockManagerTaskbarClick, enableLockManagerLoadingComp: this.enableLockManagerLoadingComp, strategyExporter: this.strategyExporter, multipleEditionEnabled: this.multipleEditionEnabled, paginationCounterMode: this.paginationCounterMode }, h("slot", { name: "GRID_TASKBAR_CUSTOM_ELEMENTS" }), h("slot", { name: "GRID_HEADER_CUSTOM_ELEMENTS" }), h("slot", { name: "SnkGridHeader" }), h("slot", { name: "SnkGridFooter" }), h("slot", { name: "SnkGridTaskBar" }))), h("stack-item", null, h("snk-guides-viewer", { ref: ref => this._guidesViewer = ref, entityPath: this._snkDataUnit.entityName, messagesBuilder: this.messagesBuilder, onExit: () => this.setViewMode(VIEW_MODE.GRID), dataState: this._dataState, dataUnit: this._dataUnit, actionsList: this.actionsList, taskbarManager: this.taskbarManager, configName: this.configName, onActionClick: evt => this.executeAction(evt.detail), presentationMode: this.presentationMode, "data-element-id": "crud_form", canEdit: this._canEdit, recordsValidator: this.recordsValidator, resourceID: this._resourceID, detailTaskbarCustomContainerId: this.customContainerId, formLegacyConfigName: this.formLegacyConfigName, enableGridInsert: this.enableGridInsert, getCustomTitle: this.setCustomFormTitle, ignoreReadOnlyFormFields: this.ignoreReadOnlyFormFields }, h("slot", { name: "GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS" }), h("slot", { name: "SnkFormTaskBar" }))), h("stack-item", { tabIndex: "0" }, h("snk-attach", { registerKey: this.attachmentRegisterKey, messagesBuilder: this.messagesBuilder, entityName: this._snkDataUnit.entityName, onBack: this.backView.bind(this) })), h("snk-configurator", { ref: (ref) => this._snkConfigurator = ref, viewMode: this._currentViewMode, messagesBuilder: this.messagesBuilder, onConfigSelected: (evt) => this.setViewMode(evt.detail), onOpenConfig: (evt) => this.openConfig(evt.detail), showActionButtons: this.showActionButtons, onSave: evt => this.handleConfiguratorEvent(evt, 'SAVE'), onCancel: evt => this.handleConfiguratorEvent(evt, 'CANCEL'), resourceID: this._resourceID, customContainerId: this.customContainerId, layoutFormConfig: this.layoutFormConfig })), h("div", { id: `${this.customContainerId}` }, h("slot", { name: "SnkConfigContainerSlot" }), h("slot", { name: "DETAIL_GRID_HEADER_CUSTOM_ELEMENTS" }), h("slot", { name: "DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS" }), h("slot", { name: "DETAIL_TASKBAR_CUSTOM_ELEMENTS" }))));
  }
  static get is() { return "snk-crud"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() {
    return {
      "$": ["snk-crud.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["snk-crud.css"]
    };
  }
  static get properties() {
    return {
      "enableLockManagerLoadingComp": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Define se o componente deve usar o LockManager para controle de carregamento da aplica\u00E7\u00E3o"
        },
        "attribute": "enable-lock-manager-loading-comp",
        "reflect": false,
        "defaultValue": "false"
      },
      "enableLockManagerTaskbarClick": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Ativa o gerenciamento de locks na grade pela Taskbar."
        },
        "attribute": "enable-lock-manager-taskbar-click",
        "reflect": false,
        "defaultValue": "false"
      },
      "configName": {
        "type": "string",
        "mutable": true,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Usado para salvar as configura\u00E7\u00F5es dos blocos de constru\u00E7\u00E3o."
        },
        "attribute": "config-name",
        "reflect": false
      },
      "filterBarTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "T\u00EDtulo que ser\u00E1 apresentado na barra de filtros"
        },
        "attribute": "filter-bar-title",
        "reflect": false
      },
      "selectionToastConfig": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "ISelectionToastConfig",
          "resolved": "ISelectionToastConfig",
          "references": {
            "ISelectionToastConfig": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/interfaces"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Configura\u00E7\u00E3o da sele\u00E7\u00E3o de grade no toast."
        }
      },
      "showActionButtons": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Usado para exibir os bot\u00F5es de a\u00E7\u00E3o do snk-configurator"
        },
        "attribute": "show-action-buttons",
        "reflect": false,
        "defaultValue": "false"
      },
      "actionsList": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "Array<Action>",
          "resolved": "Action[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "Action": {
              "location": "import",
              "path": "../snk-taskbar/snk-taskbar"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "A\u00E7\u00F5es a serem colocadas no bot\u00E3o \"Mais op\u00E7\u00F5es\" do componente snk-taskbar."
        }
      },
      "taskbarManager": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "TaskbarManager",
          "resolved": "TaskbarManager",
          "references": {
            "TaskbarManager": {
              "location": "import",
              "path": "../snk-taskbar/snk-taskbar"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Gerenciador das barras de tarefas. \u00C9 poss\u00EDvel determinar bot\u00F5es espec\u00EDficos\nou mesmo gerenciar o estado dos bot\u00F5es."
        }
      },
      "recordsValidator": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "IRecordValidator",
          "resolved": "IRecordValidator",
          "references": {
            "IRecordValidator": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/utils/form/interfaces"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Validador respons\u00E1vel por checar a integridade das informa\u00E7\u00F5es do registro."
        }
      },
      "statusResolver": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "IStatusResolver | StatusResolverFunction",
          "resolved": "((data: object) => string) | IStatusResolver",
          "references": {
            "IStatusResolver": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/controller/EzGridController"
            },
            "StatusResolverFunction": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/controller/EzGridController"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Configura\u00E7\u00E3o do valor da coluna de status.\nExemplo: { \"RECDESP\": { \"-1\" : \"#BD0025\", \"1\" : \"#157A00\" } }"
        }
      },
      "multipleSelection": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Determina se pode haver mais de uma linha selecionada na grade."
        },
        "attribute": "multiple-selection",
        "reflect": false,
        "defaultValue": "true"
      },
      "presentationMode": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "PresentationMode",
          "resolved": "PresentationMode.PRIMARY | PresentationMode.SECONDARY | PresentationMode.SINGLE_TASKBAR",
          "references": {
            "PresentationMode": {
              "location": "import",
              "path": "../../lib"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Altera o modo de apresenta\u00E7\u00E3o dos bot\u00F5es do snk-taskbar."
        },
        "attribute": "presentation-mode",
        "reflect": false,
        "defaultValue": "PresentationMode.PRIMARY"
      },
      "messagesBuilder": {
        "type": "unknown",
        "mutable": true,
        "complexType": {
          "original": "SnkMessageBuilder",
          "resolved": "SnkMessageBuilder",
          "references": {
            "SnkMessageBuilder": {
              "location": "import",
              "path": "../../lib/message/SnkMessageBuilder"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Respons\u00E1vel por flexibilizar e padronizar o uso de mensagens nos blocos de constru\u00E7\u00E3o."
        }
      },
      "useEnterLikeTab": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Quando verdadeiro, o ENTER far\u00E1 a navega\u00E7\u00E3o como se fosse a tecla TAB na grade."
        },
        "attribute": "use-enter-like-tab",
        "reflect": false,
        "defaultValue": "false"
      },
      "gridLegacyConfigName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Chave da configura\u00E7\u00E3o legado da grade."
        },
        "attribute": "grid-legacy-config-name",
        "reflect": false
      },
      "filterBarLegacyConfigName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Chave da configura\u00E7\u00E3o legado da barra de filtros."
        },
        "attribute": "filter-bar-legacy-config-name",
        "reflect": false
      },
      "formLegacyConfigName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Chave da configura\u00E7\u00E3o legado do formul\u00E1rio."
        },
        "attribute": "form-legacy-config-name",
        "reflect": false
      },
      "disablePersonalizedFilter": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Desabilita a apresenta\u00E7\u00E3o da op\u00E7\u00E3o de filtros personalizados na filter bar (chip de filtros)\ne no modal lateral de filtros (container de filtros personalizados)."
        },
        "attribute": "disable-personalized-filter",
        "reflect": false
      },
      "autoLoad": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Define se a carga dos dados ser\u00E1 feita assim que o componente for carregado."
        },
        "attribute": "auto-load",
        "reflect": false
      },
      "autoFocus": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Define se a grid ser\u00E1 focada ao ser carregada."
        },
        "attribute": "auto-focus",
        "reflect": false,
        "defaultValue": "true"
      },
      "enableGridInsert": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Ativa inser\u00E7\u00E3o de registros no modo grade."
        },
        "attribute": "enable-grid-insert",
        "reflect": false,
        "defaultValue": "false"
      },
      "domainMessagesBuilder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define a chave customizada para sobrescrever as mensagens (N\u00E3o pegando pela entidade)"
        },
        "attribute": "domain-messages-builder",
        "reflect": false
      },
      "ignoreReadOnlyFormFields": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Ignora os campos \"somente leitura\" no modo de inser\u00E7\u00E3o."
        },
        "attribute": "ignore-read-only-form-fields",
        "reflect": false
      },
      "setCustomFormTitle": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "() => string",
          "resolved": "() => string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define uma fun\u00E7\u00E3o para configurar um t\u00EDtulo cusotmizado no modo formul\u00E1rio."
        }
      },
      "strategyExporter": {
        "type": "string",
        "mutable": true,
        "complexType": {
          "original": "IExporterStrategyMode",
          "resolved": "\"ClientSideExporterStrategy\" | \"ServerSideExporterStrategy\"",
          "references": {
            "IExporterStrategyMode": {
              "location": "import",
              "path": "../snk-data-exporter/interfaces/IRecordID"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Modo de exporta\u00E7\u00E3o dos dados."
        },
        "attribute": "strategy-exporter",
        "reflect": false,
        "defaultValue": "ExporterStrategy.SERVER_SIDE"
      },
      "layoutFormConfig": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define se o LayoutFormConfig ser\u00E1 exibido no configurador."
        },
        "attribute": "layout-form-config",
        "reflect": false,
        "defaultValue": "true"
      },
      "multipleEditionEnabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Habilita a edi\u00E7\u00E3o de m\u00FAltiplos registros simult\u00E2neos."
        },
        "attribute": "multiple-edition-enabled",
        "reflect": false,
        "defaultValue": "true"
      },
      "paginationCounterMode": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "'show' | 'hidden' | 'auto'",
          "resolved": "\"auto\" | \"hidden\" | \"show\"",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Define se a grid ser\u00E1 focada ao ser carregada."
        },
        "attribute": "pagination-counter-mode",
        "reflect": false,
        "defaultValue": "'auto'"
      }
    };
  }
  static get states() {
    return {
      "_dataUnit": {},
      "_dataState": {},
      "attachmentRegisterKey": {},
      "_currentViewMode": {},
      "_canEdit": {},
      "_resourceID": {},
      "customContainerId": {}
    };
  }
  static get events() {
    return [{
        "method": "actionClick",
        "name": "actionClick",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitido pela taskbar sempre que houver click de bot\u00E3o ou a\u00E7\u00E3o."
        },
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        }
      }, {
        "method": "configuratorSave",
        "name": "configuratorSave",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitido quando salva a configura\u00E7\u00E3o no configurator do CRUD."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "configuratorCancel",
        "name": "configuratorCancel",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitido quando cancela o salvamento da configura\u00E7\u00E3o no configurator do CRUD."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "formItemsReady",
        "name": "formItemsReady",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Respons\u00E1vel por notificar quando ocorrer a renderiza\u00E7\u00E3o de itens do formul\u00E1rio."
        },
        "complexType": {
          "original": "Array<HTMLElement>",
          "resolved": "HTMLElement[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "HTMLElement": {
              "location": "global"
            }
          }
        }
      }, {
        "method": "viewModeChanged",
        "name": "viewModeChanged",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "VIEW_MODE",
          "resolved": "VIEW_MODE.ATTACHMENT | VIEW_MODE.FORM | VIEW_MODE.GRID",
          "references": {
            "VIEW_MODE": {
              "location": "import",
              "path": "../../lib/utils/constants"
            }
          }
        }
      }];
  }
  static get methods() {
    return {
      "goToView": {
        "complexType": {
          "signature": "(mode: string) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Usado para alternar a vis\u00E3o entre GRID e FORM externamente.",
          "tags": []
        }
      },
      "openConfigurator": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Usado para abrir o configurator do CRUD",
          "tags": []
        }
      },
      "closeConfigurator": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Usado para fechar o configurator do CRUD",
          "tags": []
        }
      },
      "reloadFilterBar": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Faz o recarregamento da filter-bar do crud, buscando o state no servidor.",
          "tags": []
        }
      },
      "getFilterBar": {
        "complexType": {
          "signature": "() => Promise<HTMLSnkFilterBarElement>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            },
            "HTMLSnkFilterBarElement": {
              "location": "global"
            }
          },
          "return": "Promise<HTMLSnkFilterBarElement>"
        },
        "docs": {
          "text": "Retorna o elemento da filter-bar da grade.",
          "tags": []
        }
      },
      "addCustomEditor": {
        "complexType": {
          "signature": "(fieldName: string, customEditor: ICustomEditor) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }, {
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "ICustomEditor": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/utils"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Registra um editor customizado para campos da grade e formul\u00E1rio.",
          "tags": []
        }
      },
      "addGridCustomRender": {
        "complexType": {
          "signature": "(fieldName: string, customRender: ICustomRender) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }, {
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "ICustomRender": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/utils"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Registra um render customizado para colunas da grid.",
          "tags": []
        }
      },
      "addCustomValueFormatter": {
        "complexType": {
          "signature": "(columnName: string, customFormatter: ICustomFormatter) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }, {
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "ICustomFormatter": {
              "location": "import",
              "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/interfaces"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Registra um formatador de valores para uma coluna da grid.",
          "tags": []
        }
      },
      "removeCustomValueFormatter": {
        "complexType": {
          "signature": "(columnName: string) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Remove o formatador de valores de uma coluna da grid.",
          "tags": []
        }
      },
      "setFieldProp": {
        "complexType": {
          "signature": "(fieldName: string, propName: string, value: any) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }, {
              "tags": [],
              "text": ""
            }, {
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Altera/adiciona uma propriedade nos metadados do campo.",
          "tags": []
        }
      }
    };
  }
  static get elementRef() { return "_element"; }
  static get watchers() {
    return [{
        "propName": "_currentViewMode",
        "methodName": "currentViewModeWatcher"
      }];
  }
}
