import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import './DataFetcher.js';
import './ISave.js';
import { ApplicationContext } from '@sankhyalabs/core';
import '@sankhyalabs/ezui/dist/collection/utils/constants';
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
import './dataunit-fetcher.js';
import './filter-item-type.enum.js';
import { F as FormConfigFetcher } from './form-config-fetcher.js';
import './constants.js';
import { FormLayout } from '@sankhyalabs/ezui/dist/collection/utils';
import { d as defineCustomElement$1 } from './snk-view-representation2.js';

const snkLayoutFormConfigCss = ".sc-snk-layout-form-config-h{display:block}";

const FORM_COL_CONFIG_PREFIX = 'formColCfg.';
const SnkLayoutFormConfig = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this._formConfigFetcher = new FormConfigFetcher();
    this.messagesBuilder = undefined;
    this.layoutType = FormLayout.SIDE_BY_SIDE;
  }
  /**
   * Salva o tipo de layout escolhido. Sem retorno.
   */
  async save() {
    this._LayoutFormConfigSingleton.setConfig(this.layoutType);
    this._formConfigFetcher.saveLayoutFormConfig(FORM_COL_CONFIG_PREFIX + this._resourceID, { config: this.layoutType, newConfig: true });
  }
  async componentWillLoad() {
    const _application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
    this._LayoutFormConfigSingleton = await (_application === null || _application === void 0 ? void 0 : _application.getLayoutFormConfig());
    this._resourceID = await (_application === null || _application === void 0 ? void 0 : _application.getResourceID());
    this.setLayoutInit();
  }
  setLayoutInit() {
    if (!this._LayoutFormConfigSingleton)
      return;
    const { config } = this._LayoutFormConfigSingleton;
    if (config == null) {
      this.layoutType = FormLayout.SIDE_BY_SIDE;
      return;
    }
    const configAsNumber = Number(config);
    this.layoutType = Object.values(FormLayout).includes(configAsNumber)
      ? configAsNumber
      : FormLayout.SIDE_BY_SIDE;
  }
  toggleLayout(key) {
    this.layoutType = key;
  }
  getMessage(key, params) {
    var _a;
    return (_a = this.messagesBuilder) === null || _a === void 0 ? void 0 : _a.getMessage(key, params);
  }
  render() {
    return (h("div", { class: "ez-flex ez-flex--column" }, h("div", { class: "ez-margin-bottom--small" }, h("ez-check", { label: this.getMessage('snkLayoutFormConfig.cascadeLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(FormLayout.CASCADE), value: this.layoutType === FormLayout.CASCADE }), h("snk-view-representation", { mode: FormLayout.CASCADE }), h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.cascadeLayout.description'))), h("div", null, h("ez-check", { label: this.getMessage('snkLayoutFormConfig.sideBySideLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(FormLayout.SIDE_BY_SIDE), value: this.layoutType === FormLayout.SIDE_BY_SIDE }), h("snk-view-representation", { mode: FormLayout.SIDE_BY_SIDE }), h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.sideBySideLayout.description')))));
  }
  static get style() { return snkLayoutFormConfigCss; }
}, [2, "snk-layout-form-config", {
    "messagesBuilder": [16],
    "layoutType": [32],
    "save": [64]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["snk-layout-form-config", "snk-view-representation"];
  components.forEach(tagName => { switch (tagName) {
    case "snk-layout-form-config":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, SnkLayoutFormConfig);
      }
      break;
    case "snk-view-representation":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}

export { SnkLayoutFormConfig as S, defineCustomElement as d };
