/*!
 * KoliBri - The accessible HTML-Standard
 */
'use strict';

var index = require('./index-DBbl8tEq.js');
var tslib_es6 = require('./tslib.es6-Cm0ytgPY.js');
var common = require('./common-DAAt5YQ7.js');
var component$1 = require('./component-4yrnT9ww.js');
var accessAndShortKey = require('./access-and-short-key-B_Jn8UfN.js');
var ariaExpanded = require('./aria-expanded-DVEjetkn.js');
var customClass = require('./custom-class-C8GDf7By.js');
var disabled = require('./disabled-D8jGjcwY.js');
var hideLabel = require('./hide-label-CO4GBDgf.js');
var icons = require('./icons-D80xUBDS.js');
var inline = require('./inline-1X3ssV6v.js');
var label = require('./label-VzToxIES.js');
var tooltipAlign = require('./tooltip-align-C2v_joNk.js');
var variantClassName = require('./variant-class-name-DsZdGPeK.js');
var variantQuote = require('./variant-quote-DUWZtljE.js');
var component = require('./component-CYZTV5r0.js');
var controller = require('./controller-DHsc-8t1.js');
var clsx = require('./clsx-Bm_HQUnh.js');
var elementInteraction = require('./element-interaction-CmOQWzhR.js');
var events = require('./events-DN9qldnr.js');
var controller$1 = require('./controller-DNlov9_q.js');
var associated_controller = require('./associated.controller-CUvZCmFF.js');
require('./bem-registry-D9uDM1GJ.js');
require('./component-C1vBQDN-.js');
require('./isArray-BOIOdEQh.js');
require('./align-e4FQ7dUp.js');
require('./normalizers-R90MJyQR.js');
require('./_Uint8Array-BAQUGozM.js');
require('./align-floating-elements-DfUaAAqe.js');
require('./tooltip-open-tracking-Ba0udJRU.js');
require('./label-CrUhy8f0.js');
require('./base-controller-DAzsTqX9.js');
require('./element-focus-B4BhAkh_.js');
require('./component-names-5KS_pYRF.js');
require('./bootstrap-De2npoa_.js');
require('./i18n-CgUN6lev.js');

const validateAriaSelected = (component, value) => {
    common.watchBoolean(component, '_ariaSelected', value);
};

const validateButtonCallbacks = (component, value) => {
    common.watchValidator(component, `_on`, (value) => typeof value === 'object' && value !== null, new Set(['ButtonCallbacksPropType {Events.onClick, Events.onMouseDown, Events.onFocus, Events.onBlur}']), value);
};

const buttonTypePropTypeOptions = ['button', 'reset', 'submit'];
const validateButtonType = (component, value) => {
    common.watchValidator(component, `_type`, (value) => typeof value === 'string' && buttonTypePropTypeOptions.includes(value), new Set([`KoliBriButtonType {${buttonTypePropTypeOptions.join(', ')}`]), value);
};

const KolButtonWc = class {
    async focus(options) { }
    async click() { }
    render() {
        var _a;
        const hasExpertSlot = component$1.showExpertSlot(this.state._label);
        const ariaDescription = (_a = this.state._ariaDescription) === null || _a === void 0 ? void 0 : _a.trim();
        const badgeText = this.state._accessKey || this.state._shortKey;
        const isDisabled = this.state._disabled === true;
        const hideLabel = this.state._hideLabel === true;
        return (index.h(index.Host, { key: 'c1d7f928a7e82f9101c1da0929b2f17670c45bbf' }, index.h("button", { key: '2ffa65db67b8c7ba0c4aa5b3bd44cf2e9c3d6820', ref: this.ctaRef, accessKey: this.state._accessKey, "aria-controls": this.state._ariaControls, "aria-description": ariaDescription || undefined, "aria-expanded": common.mapBoolean2String(this.state._ariaExpanded), "aria-haspopup": this._ariaHasPopup, "aria-keyshortcuts": this.state._shortKey, "aria-label": hideLabel && typeof this.state._label === 'string' && this.state._label.length > 0 ? this.state._label : undefined, "aria-selected": common.mapStringOrBoolean2String(this.state._ariaSelected), class: clsx.clsx('kol-button', {
                'kol-button--disabled': isDisabled,
                [`kol-button--${this.state._variant}`]: this.state._variant !== 'custom',
                'kol-button--inline': this.state._inline === true,
                'kol-button--standalone': this.state._inline === false,
                'kol-button--hide-label': hideLabel,
                [this.state._customClass]: typeof this.state._customClass === 'string' && this.state._customClass.length > 0,
            }), disabled: isDisabled, id: this.state._id, name: this.state._name, onClick: this.onClick, onMouseDown: this.onMouseDown, onFocus: this.onFocus, onBlur: this.onBlur, role: this.state._role, tabIndex: this.state._tabIndex, type: this.state._type }, index.h(component$1.SpanFC, { key: '86eae862c2e73e86fc146974a90a4a693a04020f', class: "kol-button__text", badgeText: badgeText, icons: this.state._icons, hideLabel: hideLabel, label: hasExpertSlot ? '' : this.state._label }, index.h("slot", { key: '021615c5514837c984b8a89eef6c43cc03db13b6', name: "expert", slot: "expert" }))), hideLabel && typeof this.state._label === 'string' && this.state._label.length > 0 && (index.h("div", { key: '6a9c6f55dec04a4bc2f32f366617b36bfbb1254c', class: "kol-button__tooltip" }, index.h(component.TooltipFC, { key: 'bc1e41aec24688ba853a0e25c432764ca8b07e30', badgeText: badgeText || '', label: this.state._label, id: this.tooltipCtrl.getRenderProp('id'), refFloating: this.tooltipCtrl.setTooltipElementRef })))));
    }
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.ctaRef = elementInteraction.createCtaRef();
        this.tooltipCtrl = new controller.TooltipController(variantQuote.BaseWebComponent.stateLess);
        this.onClick = (event) => {
            var _a, _b;
            event.stopPropagation();
            this.tooltipCtrl.hideTooltip();
            if (this.state._type === 'submit') {
                controller$1.propagateSubmitEventToForm({
                    form: this.host});
            }
            else if (this.state._type === 'reset') {
                controller$1.propagateResetEventToForm({
                    form: this.host});
            }
            else {
                this.controller.setFormAssociatedValue(this.state._value);
                if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
                    common.setEventTarget(event, this.ctaRef.el);
                    (_b = this.state._on) === null || _b === void 0 ? void 0 : _b.onClick(event, this.state._value);
                }
            }
            if (this.host) {
                events.dispatchDomEvent(this.host, events.KolEvent.click, this.state._value);
            }
        };
        this.onMouseDown = (event) => {
            var _a, _b, _c;
            (_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onMouseDown) === null || _c === void 0 ? void 0 : _c.call(_b, event);
            if (this.host) {
                events.dispatchDomEvent(this.host, events.KolEvent.mousedown);
            }
        };
        this.onFocus = (event) => {
            var _a, _b, _c;
            (_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onFocus) === null || _c === void 0 ? void 0 : _c.call(_b, event);
            if (this.host) {
                events.dispatchDomEvent(this.host, events.KolEvent.focus);
            }
        };
        this.onBlur = (event) => {
            var _a, _b, _c;
            (_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onBlur) === null || _c === void 0 ? void 0 : _c.call(_b, event);
            if (this.host) {
                events.dispatchDomEvent(this.host, events.KolEvent.blur);
            }
        };
        this._disabled = false;
        this._hideLabel = false;
        this._inline = false;
        this._tooltipAlign = 'top';
        this._type = 'button';
        this.state = {
            _icons: {},
            _label: '',
            _on: {},
            _type: 'button',
            _variant: 'normal',
        };
        this.controller = new associated_controller.AssociatedInputController(this, 'button', this.host);
    }
    validateAccessKey(value) {
        accessAndShortKey.validateAccessKey(this, value);
        accessAndShortKey.validateAccessAndShortKey(value, this._shortKey);
    }
    validateAriaControls(value) {
        ariaExpanded.validateAriaControls(this, value);
    }
    validateAriaDescription(value) {
        ariaExpanded.validateAriaDescription(this, value);
    }
    validateAriaExpanded(value) {
        ariaExpanded.validateAriaExpanded(this, value);
    }
    validateAriaSelected(value) {
        validateAriaSelected(this, value);
    }
    validateCustomClass(value) {
        customClass.validateCustomClass(this, value);
    }
    validateDisabled(value) {
        disabled.validateDisabled(this, value);
    }
    validateHideLabel(value) {
        hideLabel.validateHideLabel(this, value);
    }
    validateIcons(value) {
        icons.validateIcons(this, value);
    }
    validateId(value) {
        common.watchString(this, '_id', value);
    }
    validateInline(value) {
        inline.validateInline(this, value, {
            defaultValue: false,
        });
    }
    validateLabel(value) {
        label.validateLabelWithExpertSlot(this, value, {
            required: true,
        });
        this.tooltipCtrl.watchLabel(typeof value === 'string' ? value : undefined);
    }
    validateName(value) {
        this.controller.validateName(value);
    }
    validateOn(value) {
        validateButtonCallbacks(this, value);
    }
    validateRole(value) {
        ariaExpanded.validateAlternativeButtonLinkRole(this, value);
    }
    validateShortKey(value) {
        accessAndShortKey.validateShortKey(this, value);
        accessAndShortKey.validateAccessAndShortKey(this._accessKey, value);
    }
    validateSyncValueBySelector(value) {
        this.controller.validateSyncValueBySelector(value);
    }
    validateTabIndex(value) {
        accessAndShortKey.validateTabIndex(this, value);
    }
    validateTooltipAlign(value) {
        tooltipAlign.validateTooltipAlign(this, value);
        this.tooltipCtrl.watchAlign(value);
    }
    validateType(value) {
        validateButtonType(this, value);
    }
    validateValue(value) {
        common.setState(this, '_value', value);
        this.controller.setFormAssociatedValue(this.state._value);
    }
    validateVariant(value) {
        variantClassName.validateVariantClassName(this, value);
    }
    componentWillLoad() {
        this.validateAccessKey(this._accessKey);
        this.validateAriaControls(this._ariaControls);
        this.validateAriaDescription(this._ariaDescription);
        this.validateAriaExpanded(this._ariaExpanded);
        this.validateAriaSelected(this._ariaSelected);
        this.validateCustomClass(this._customClass);
        this.validateDisabled(this._disabled);
        this.validateHideLabel(this._hideLabel);
        this.validateIcons(this._icons);
        this.validateId(this._id);
        this.validateInline(this._inline);
        this.validateLabel(this._label);
        this.validateName(this._name);
        this.validateOn(this._on);
        this.validateRole(this._role);
        this.validateShortKey(this._shortKey);
        this.validateSyncValueBySelector(this._syncValueBySelector);
        this.validateTabIndex(this._tabIndex);
        this.validateTooltipAlign(this._tooltipAlign);
        this.validateType(this._type);
        this.validateValue(this._value);
        this.validateVariant(this._variant);
        accessAndShortKey.validateAccessAndShortKey(this._accessKey, this._shortKey);
        this.tooltipCtrl.componentWillLoad({
            label: typeof this.state._label === 'string' ? this.state._label : '',
            align: this._tooltipAlign,
        });
    }
    componentDidRender() {
        if (this.ctaRef.el) {
            this.tooltipCtrl.syncListeners(undefined, this.ctaRef.el, true);
        }
    }
    disconnectedCallback() {
        this.tooltipCtrl.destroy();
    }
    get host() { return index.getElement(this); }
    static get watchers() { return {
        "_accessKey": ["validateAccessKey"],
        "_ariaControls": ["validateAriaControls"],
        "_ariaDescription": ["validateAriaDescription"],
        "_ariaExpanded": ["validateAriaExpanded"],
        "_ariaSelected": ["validateAriaSelected"],
        "_customClass": ["validateCustomClass"],
        "_disabled": ["validateDisabled"],
        "_hideLabel": ["validateHideLabel"],
        "_icons": ["validateIcons"],
        "_id": ["validateId"],
        "_inline": ["validateInline"],
        "_label": ["validateLabel"],
        "_name": ["validateName"],
        "_on": ["validateOn"],
        "_role": ["validateRole"],
        "_shortKey": ["validateShortKey"],
        "_syncValueBySelector": ["validateSyncValueBySelector"],
        "_tabIndex": ["validateTabIndex"],
        "_tooltipAlign": ["validateTooltipAlign"],
        "_type": ["validateType"],
        "_value": ["validateValue"],
        "_variant": ["validateVariant"]
    }; }
};
tslib_es6.__decorate([
    elementInteraction.directFocus('ctaRef')
], KolButtonWc.prototype, "focus", null);
tslib_es6.__decorate([
    elementInteraction.directClick('ctaRef')
], KolButtonWc.prototype, "click", null);

exports.kol_button_wc = KolButtonWc;
//# sourceMappingURL=kol-button-wc.entry.cjs.js.map
