'use strict';

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

const index = require('./index-17105557.js');
const utils = require('@sankhyalabs/ezui/dist/collection/utils');

const configHeaderCss = ".sc-config-header-h{display:flex;padding-top:12px;padding-left:12px;align-items:center;width:100%;justify-content:space-between}.left-group.sc-config-header{display:flex;gap:8px}.right-group.sc-config-header{padding-right:18px;display:flex}";

const ConfigHeader = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.configClose = index.createEvent(this, "configClose", 7);
    this.saveConfig = index.createEvent(this, "saveConfig", 7);
    this.isEditingGuide = false;
    this.isEditingGroup = false;
    this.configOptions = [];
    this.selectedConfig = undefined;
    this.messagesBuilder = undefined;
    this.hasChanges = false;
    this.optionConfigChanged = false;
  }
  handleIsEditingGuideName({ detail }) {
    this.isEditingGuide = detail;
  }
  handleIsEditingGroupName({ detail }) {
    this.isEditingGroup = detail;
  }
  saveFormConfig() {
    if (this.isEditingGuide || this.isEditingGroup) {
      const title = this.getMessage('snkFormConfig.confirm.title');
      const message = this.isEditingGuide
        ? this.getMessage('snkFormConfig.alert.titleGuideEditing')
        : this.getMessage('snkFormConfig.alert.titleGroupEditing');
      utils.ApplicationUtils.alert(title, message);
      return;
    }
    this.saveConfig.emit();
  }
  async closeFormConfig() {
    if (this.hasChanges) {
      const title = this.getMessage('snkFormConfig.confirm.title');
      const msg = this.getMessage('snkFormConfig.confirm.cancel');
      const confirm = await utils.ApplicationUtils.confirm(title, msg);
      if (!confirm)
        return;
    }
    this.configClose.emit();
  }
  getMessage(key, params) {
    return this.messagesBuilder.getMessage(key, params);
  }
  openConfirmDialog(msg = '', title = this.getMessage('snkFormConfig.confirm.title')) {
    return utils.ApplicationUtils.confirm(title, msg);
  }
  async applyOptionConfig() {
    var _a, _b;
    const name = (_b = (_a = this.selectedConfig) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : this.getMessage('snkFormConfig.configs.selectedConfig');
    const msg = this.getMessage('snkFormConfig.confirm.apply').replace('{0}', name);
    const confirm = await this.openConfirmDialog(msg);
    if (confirm) {
      this.saveConfig.emit();
    }
  }
  renderSaveActions() {
    if (!this.hasChanges && !this.optionConfigChanged)
      return;
    if (this.hasChanges) {
      return (index.h("div", { class: "right-group" }, index.h("ez-button", { title: this.getMessage('snkFormConfig.actions.cancel'), label: this.getMessage('snkFormConfig.actions.cancel'), onClick: this.closeFormConfig.bind(this), size: "medium" }), index.h("ez-button", { title: this.getMessage('snkFormConfig.actions.save'), label: this.getMessage('snkFormConfig.actions.save'), class: 'ez-button--primary ez-padding-left--medium', onClick: () => this.saveFormConfig(), size: "medium" })));
    }
    return (index.h("div", { class: "right-group" }, index.h("ez-button", { title: this.getMessage('snkFormConfig.actions.cancel'), label: this.getMessage('snkFormConfig.actions.cancel'), onClick: this.closeFormConfig.bind(this), size: "medium" }), index.h("ez-button", { title: this.getMessage('snkFormConfig.actions.save'), label: this.getMessage('snkFormConfig.applyConfig'), class: 'ez-button--primary ez-padding-left--medium', onClick: async () => await this.applyOptionConfig(), size: "medium" })));
  }
  render() {
    return (index.h(index.Host, null, index.h("div", { class: 'left-group' }, index.h("ez-button", { mode: "icon", title: this.getMessage('snkFormConfig.goBackTitle'), iconName: "arrow_back", class: "ez-padding--small", size: "small", onClick: this.closeFormConfig.bind(this), id: "formConfigToBack" }), index.h("h1", { class: "ez-title ez-title--primary ez-title--extra-large ez-padding--small" }, this.getMessage('snkFormConfig.title')), index.h("configs-button", { hasChanges: this.hasChanges, configOptions: this.configOptions, selectedConfig: this.selectedConfig, messagesBuilder: this.messagesBuilder })), this.renderSaveActions()));
  }
};
ConfigHeader.style = configHeaderCss;

exports.config_header = ConfigHeader;
