'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1894343a.js');
require('./DataFetcher-b3a8075d.js');
require('./ISave-4674c283.js');
const core = require('@sankhyalabs/core');
require('./index-e3e39724.js');
require('@sankhyalabs/ezui/dist/collection/utils/constants');
require('@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata');
require('./dataunit-fetcher-bcbc38c0.js');
require('./filter-item-type.enum-a7ffdaa6.js');
const formConfigFetcher = require('./form-config-fetcher-858d6407.js');
require('./constants-6d82e405.js');
const utils = require('@sankhyalabs/ezui/dist/collection/utils');
require('./PrintUtils-bcaeb82f.js');
require('@sankhyalabs/ezui/dist/collection/components/ez-grid/utils');
require('@sankhyalabs/core/dist/utils/SortingUtils');
require('./ResourceIDUtils-5ff86aa7.js');

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

const FORM_COL_CONFIG_PREFIX = 'formColCfg.';
const SnkLayoutFormConfig = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this._formConfigFetcher = new formConfigFetcher.FormConfigFetcher();
    this.messagesBuilder = undefined;
    this.layoutType = utils.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 = core.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 = utils.FormLayout.SIDE_BY_SIDE;
      return;
    }
    const configAsNumber = Number(config);
    this.layoutType = Object.values(utils.FormLayout).includes(configAsNumber)
      ? configAsNumber
      : utils.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 (index.h("div", { class: "ez-flex ez-flex--column" }, index.h("div", { class: "ez-margin-bottom--small" }, index.h("ez-check", { label: this.getMessage('snkLayoutFormConfig.cascadeLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(utils.FormLayout.CASCADE), value: this.layoutType === utils.FormLayout.CASCADE }), index.h("snk-view-representation", { mode: utils.FormLayout.CASCADE }), index.h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.cascadeLayout.description'))), index.h("div", { class: "ez-margin-bottom--small" }, index.h("ez-check", { label: this.getMessage('snkLayoutFormConfig.classicCascadeLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(utils.FormLayout.CLASSIC_CASCADE), value: this.layoutType === utils.FormLayout.CLASSIC_CASCADE }), index.h("snk-view-representation", { mode: utils.FormLayout.CLASSIC_CASCADE }), index.h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.classicCascadeLayout.description'))), index.h("div", { class: "ez-margin-bottom--small" }, index.h("ez-check", { label: this.getMessage('snkLayoutFormConfig.sideBySideLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(utils.FormLayout.SIDE_BY_SIDE), value: this.layoutType === utils.FormLayout.SIDE_BY_SIDE }), index.h("snk-view-representation", { mode: utils.FormLayout.SIDE_BY_SIDE }), index.h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.sideBySideLayout.description'))), index.h("div", null, index.h("ez-check", { label: this.getMessage('snkLayoutFormConfig.classicSideBySideLayout.label'), class: "ez-margin-bottom--small", onEzChange: () => this.toggleLayout(utils.FormLayout.CLASSIC_SIDE_BY_SIDE), value: this.layoutType === utils.FormLayout.CLASSIC_SIDE_BY_SIDE }), index.h("snk-view-representation", { mode: utils.FormLayout.CLASSIC_SIDE_BY_SIDE }), index.h("label", { class: "ez-label ez-margin--small ez-flex ez-text--medium" }, this.getMessage('snkLayoutFormConfig.classicSideBySideLayout.description')))));
  }
};
SnkLayoutFormConfig.style = snkLayoutFormConfigCss;

exports.snk_layout_form_config = SnkLayoutFormConfig;
