import { r as registerInstance, h } from './index-04f73a26.js';
import './DataFetcher-5ed0a377.js';
import './ISave-5b46d691.js';
import { ApplicationContext } from '@sankhyalabs/core';
import './index-b40568ff.js';
import '@sankhyalabs/ezui/dist/collection/utils/constants';
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
import './dataunit-fetcher-3b1ca96e.js';
import './filter-item-type.enum-d45e026f.js';
import { F as FormConfigFetcher } from './form-config-fetcher-1c81efc4.js';
import './constants-7b422de0.js';
import { FormLayout } from '@sankhyalabs/ezui/dist/collection/utils';
import './PrintUtils-3e4ff0f5.js';
import '@sankhyalabs/ezui/dist/collection/components/ez-grid/utils';
import '@sankhyalabs/core/dist/utils/SortingUtils';
import './ResourceIDUtils-a114189a.js';

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

const FORM_COL_CONFIG_PREFIX = 'formColCfg.';
const SnkLayoutFormConfig = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    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", { class: "ez-margin-bottom--small" }, h("ez-check", { label: this.getMessage('snkLayoutFormConfig.classicCascadeLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(FormLayout.CLASSIC_CASCADE), value: this.layoutType === FormLayout.CLASSIC_CASCADE }), h("snk-view-representation", { mode: FormLayout.CLASSIC_CASCADE }), h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.classicCascadeLayout.description'))), h("div", { class: "ez-margin-bottom--small" }, 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'))), h("div", null, h("ez-check", { label: this.getMessage('snkLayoutFormConfig.classicSideBySideLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(FormLayout.CLASSIC_SIDE_BY_SIDE), value: this.layoutType === FormLayout.CLASSIC_SIDE_BY_SIDE }), h("snk-view-representation", { mode: FormLayout.CLASSIC_SIDE_BY_SIDE }), h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.classicSideBySideLayout.description')))));
  }
};
SnkLayoutFormConfig.style = snkLayoutFormConfigCss;

export { SnkLayoutFormConfig as snk_layout_form_config };
