import { r as registerInstance, e as createEvent, h, f as Host } from './index-e9c7ceaa.js';
import { ObjectUtils } from '@sankhyalabs/core';
import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';

const configsButtonCss = ".dropdown-container.sc-configs-button{font-family:'Roboto';font-size:12px;font-weight:400;display:flex;flex-direction:column;color:#2b3a54;width:200px}.main-item.sc-configs-button{padding:12px;font-size:14px;cursor:pointer;transition:all .2s ease-in-out;display:flex;flex-direction:row;gap:8px;align-items:center;justify-content:start}.main-item.sc-configs-button ez-icon.sc-configs-button{--ez-icon--color:#008561}.main-item.sc-configs-button:nth-of-type(1){padding-bottom:6px}.main-item.sc-configs-button:nth-of-type(2){padding-top:6px}.main-item.sc-configs-button:hover{background-color:#FAFCFF}.item-label.sc-configs-button{display:flex}";

const ConfigsButton = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.formConfigOptionSelected = createEvent(this, "formConfigOptionSelected", 7);
    this.configOptions = [];
    this.selectedConfig = undefined;
    this.hasChanges = false;
    this.messagesBuilder = undefined;
  }
  getMessage(key, params) {
    return this.messagesBuilder.getMessage(key, params);
  }
  async showShareConfigOptions() {
    if (this._refOptionsPopover && this._refShareConfigBtn) {
      await this._refOptionsPopover.showUnder(this._refShareConfigBtn);
    }
  }
  async handleSelectOption(option) {
    if (ObjectUtils.equals(option, this.selectedConfig))
      return;
    if (this.hasChanges) {
      const title = this.getMessage('snkFormConfig.confirm.title');
      const msg = this.getMessage('snkFormConfig.confirm.cancel');
      const confirm = await ApplicationUtils.confirm(title, msg);
      if (!confirm)
        return;
    }
    this.selectedConfig = option;
    this.formConfigOptionSelected.emit(option);
    await this._refOptionsPopover.hide();
  }
  getButtonLabel() {
    var _a, _b;
    return (_b = (_a = this.selectedConfig) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : this.getMessage('snkFormConfig.configs.buttonLabel');
  }
  renderConfigOptions() {
    return this.configOptions.map((option) => {
      return (h("div", { class: `main-item`, onClick: async () => await this.handleSelectOption(option) }, h("span", { class: 'item-label' }, " ", option.name), this.renderCheckIcon(option)));
    });
  }
  renderCheckIcon(option) {
    if (this.selectedConfig && this.selectedConfig.origin === option.origin)
      return h("ez-icon", { iconName: "check" });
  }
  render() {
    return (h(Host, null, h("ez-button", { ref: ref => this._refShareConfigBtn = ref, label: this.getButtonLabel(), onClick: async () => await this.showShareConfigOptions() }, h("ez-icon", { slot: "rightIcon", iconName: "chevron-down" })), h("ez-popover-plus", { ref: ref => this._refOptionsPopover = ref, autoClose: true, overlayType: "none" }, h("div", { class: 'dropdown-container' }, this.renderConfigOptions()))));
  }
};
ConfigsButton.style = configsButtonCss;

export { ConfigsButton as configs_button };
