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

var index = require('./index-DBbl8tEq.js');
var tslib_es6 = require('./tslib.es6-Cm0ytgPY.js');
var variantQuote = require('./variant-quote-DUWZtljE.js');
var component$2 = require('./component-C1vBQDN-.js');
var component = require('./component-CYZTV5r0.js');
var controller = require('./controller-DHsc-8t1.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 href = require('./href-DoBpb9Pl.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 elementInteraction = require('./element-interaction-CmOQWzhR.js');
var events = require('./events-DN9qldnr.js');
var ariaCurrentService = require('./ariaCurrentService-3051l6MI.js');
var i18n = require('./i18n-DL7vJXNn.js');
var clsx = require('./clsx-Bm_HQUnh.js');
require('./normalizers-R90MJyQR.js');
require('./_Uint8Array-BAQUGozM.js');
require('./isArray-BOIOdEQh.js');
require('./bem-registry-D9uDM1GJ.js');
require('./align-floating-elements-DfUaAAqe.js');
require('./tooltip-open-tracking-Ba0udJRU.js');
require('./align-e4FQ7dUp.js');
require('./label-CrUhy8f0.js');
require('./base-controller-DAzsTqX9.js');
require('./element-focus-B4BhAkh_.js');
require('./i18n-CgUN6lev.js');

const ariaCurrentValuePropTypeOptions = ['date', 'location', 'page', 'step', 'time', 'true', 'false'];
const validateAriaCurrentValue = (component, value) => {
    common.watchValidator(component, `_ariaCurrentValue`, (value) => typeof value === 'string' && ariaCurrentValuePropTypeOptions.includes(value), new Set([`AriaCurrentValue {${ariaCurrentValuePropTypeOptions.join(', ')}`]), value, {
        defaultValue: 'page',
    });
};

const validateAriaOwns = (component, value) => {
    common.watchString(component, '_ariaOwns', value, {
        defaultValue: undefined,
    });
};

const validateDownload = (component, value) => {
    common.watchString(component, '_download', value);
};

const validateLinkCallbacks = (component, value) => {
    if (typeof value === 'object' && typeof (value === null || value === void 0 ? void 0 : value.onClick) === 'function') {
        component.state = Object.assign(Object.assign({}, component.state), { _on: value });
    }
};

const validateLinkTarget = (component, value) => {
    common.watchString(component, '_target', value);
};

const KolLinkWc = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.ctaRef = elementInteraction.createCtaRef();
        this.tooltipCtrl = new controller.TooltipController(variantQuote.BaseWebComponent.stateLess);
        this.translateOpenLinkInTab = i18n.translate('kol-open-link-in-tab');
        this.onClick = (event) => {
            var _a, _b;
            this.tooltipCtrl.hideTooltip();
            if (this.state._disabled === true) {
                event.preventDefault();
            }
            else {
                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._href);
                }
                if (this.host) {
                    events.dispatchDomEvent(this.host, events.KolEvent.click, this.state._href);
                }
            }
        };
        this.getRenderValues = () => {
            const isExternal = typeof this.state._target === 'string' && this.state._target !== '_self';
            const tagAttrs = {
                href: typeof this.state._href === 'string' && this.state._href.length > 0 ? this.state._href : 'javascript:void(0);',
                target: typeof this.state._target === 'string' && this.state._target.length > 0 ? this.state._target : undefined,
                rel: isExternal ? 'noopener' : undefined,
                download: typeof this.state._download === 'string' ? this.state._download : undefined,
            };
            if (this.state._hideLabel === true && !this.state._label) {
                common.devHint(`[KolLink] An aria-label must be set when _hide-label is set.`);
            }
            return { isExternal, tagAttrs };
        };
        this._disabled = false;
        this._hideLabel = false;
        this._inline = true;
        this._tooltipAlign = 'right';
        this.state = {
            _ariaCurrentValue: 'page',
            _href: '',
            _icons: {},
        };
    }
    async focus(options) { }
    async click() { }
    render() {
        var _a;
        const { isExternal, tagAttrs } = this.getRenderValues();
        const hasExpertSlot = component$1.showExpertSlot(this.state._label);
        const ariaDescription = (_a = this.state._ariaDescription) === null || _a === void 0 ? void 0 : _a.trim();
        return (index.h(index.Host, { key: 'b2578fc0e2b3949a4d34bb6ff6acf185ba61fe7e' }, index.h("a", Object.assign({ key: '194ccd190fd5f7f40b3a71112fc4c4e429c0d040', ref: this.ctaRef }, tagAttrs, { accessKey: this.state._accessKey, "aria-current": this.state._ariaCurrent, "aria-controls": this.state._ariaControls, "aria-description": ariaDescription || undefined, "aria-disabled": this.state._disabled ? 'true' : undefined, "aria-expanded": typeof this.state._ariaExpanded === 'boolean' ? String(this.state._ariaExpanded) : undefined, "aria-owns": this.state._ariaOwns, "aria-label": this.state._hideLabel && typeof this.state._label === 'string'
                ? `${this.state._label}${isExternal ? ` (${this.translateOpenLinkInTab})` : ''}`
                : undefined, "aria-keyshortcuts": this.state._shortKey, class: clsx.clsx('kol-link', {
                'kol-link--disabled': this.state._disabled === true,
                'kol-link--external-link': isExternal,
                'kol-link--hide-label': this.state._hideLabel === true,
                [`kol-link--${this.state._variant}`]: this.state._variant !== undefined,
                'kol-link--inline': this.state._inline === true,
                'kol-link--standalone': this.state._inline === false,
                [this.state._customClass]: this.state._variant === 'custom' && typeof this.state._customClass === 'string' && this.state._customClass.length > 0,
            }) }, this.state._on, { onClick: this.onClick, onKeyPress: this.onClick, role: this.state._role, tabIndex: this.state._disabled ? -1 : this.state._tabIndex }), index.h(component$1.SpanFC, { key: '1c7125bbb54fa0d70e7fabf59c590d200d1ec4b1', class: "kol-link__text", badgeText: this.state._accessKey || this.state._shortKey, icons: this.state._icons, hideLabel: this.state._hideLabel, label: hasExpertSlot ? '' : this.state._label || this.state._href }, index.h("slot", { key: 'bd7222615ee15e0e27ae179f264b16ec619676bd', name: "expert", slot: "expert" })), isExternal && (index.h(component$2.IconFC, { key: '1dd5e08e968373d93df144510812c48e330c0fc3', class: "kol-link__icon", label: this.state._hideLabel ? '' : this.translateOpenLinkInTab, icons: 'kolicon-link-external', "aria-hidden": this.state._hideLabel }))), this.state._hideLabel === true && !hasExpertSlot && (index.h("div", { key: 'ba7014c6d4a1829765609ad7f363e86b345e9620', class: "kol-link__tooltip" }, index.h(component.TooltipFC, { key: '714d0a47ecd76d10b9fd0341aef2f6a6edd2394b', badgeText: this.state._accessKey || this.state._shortKey || '', label: typeof this.state._label === 'string' ? this.state._label : typeof this.state._href === 'string' ? this.state._href : '', id: this.tooltipCtrl.getRenderProp('id'), refFloating: this.tooltipCtrl.setTooltipElementRef })))));
    }
    validateAccessKey(value) {
        accessAndShortKey.validateAccessKey(this, value);
        accessAndShortKey.validateAccessAndShortKey(value, this._shortKey);
    }
    validateAriaCurrentValue(value) {
        validateAriaCurrentValue(this, value);
    }
    validateAriaControls(value) {
        ariaExpanded.validateAriaControls(this, value);
    }
    validateAriaDescription(value) {
        ariaExpanded.validateAriaDescription(this, value);
    }
    validateAriaExpanded(value) {
        ariaExpanded.validateAriaExpanded(this, value);
    }
    validateAriaOwns(value) {
        validateAriaOwns(this, value);
    }
    validateCustomClass(value) {
        customClass.validateCustomClass(this, value);
    }
    validateDisabled(value) {
        disabled.validateDisabled(this, value);
    }
    validateDownload(value) {
        validateDownload(this, value);
    }
    validateHideLabel(value) {
        hideLabel.validateHideLabel(this, value);
    }
    validateHref(value) {
        href.validateHref(this, value, {
            required: true,
        });
    }
    validateIcons(value) {
        icons.validateIcons(this, value);
    }
    validateInline(value) {
        inline.validateInline(this, value, {
            defaultValue: true,
        });
    }
    validateLabel(value) {
        label.validateLabelWithExpertSlot(this, value);
        this.tooltipCtrl.watchLabel(typeof value === 'string' ? value : undefined);
    }
    validateOn(value) {
        validateLinkCallbacks(this, value);
    }
    validateRole(value) {
        ariaExpanded.validateAlternativeButtonLinkRole(this, value);
    }
    validateShortKey(value) {
        accessAndShortKey.validateShortKey(this, value);
        accessAndShortKey.validateAccessAndShortKey(this._accessKey, value);
    }
    validateTabIndex(value) {
        accessAndShortKey.validateTabIndex(this, value);
    }
    validateTarget(value) {
        validateLinkTarget(this, value);
    }
    validateTooltipAlign(value) {
        tooltipAlign.validateTooltipAlign(this, value);
        this.tooltipCtrl.watchAlign(value);
    }
    validateVariantClassName(value) {
        variantClassName.validateVariantClassName(this, value);
    }
    componentWillLoad() {
        this.validateAccessKey(this._accessKey);
        this.validateAriaCurrentValue(this._ariaCurrentValue);
        this.validateAriaControls(this._ariaControls);
        this.validateAriaDescription(this._ariaDescription);
        this.validateAriaExpanded(this._ariaExpanded);
        this.validateAriaOwns(this._ariaOwns);
        this.validateCustomClass(this._customClass);
        this.validateDisabled(this._disabled);
        this.validateDownload(this._download);
        this.validateHideLabel(this._hideLabel);
        this.validateHref(this._href);
        this.validateIcons(this._icons);
        this.validateInline(this._inline);
        this.validateLabel(this._label);
        this.validateOn(this._on);
        this.validateRole(this._role);
        this.validateShortKey(this._shortKey);
        this.validateTabIndex(this._tabIndex);
        this.validateTarget(this._target);
        this.validateTooltipAlign(this._tooltipAlign);
        this.validateVariantClassName(this._variant);
        this.unsubscribeOnLocationChange = ariaCurrentService.onLocationChange((location) => {
            this.state._ariaCurrent = location === this.state._href ? this.state._ariaCurrentValue : undefined;
        });
        accessAndShortKey.validateAccessAndShortKey(this._accessKey, this._shortKey);
        this.tooltipCtrl.componentWillLoad({
            label: typeof this.state._label === 'string' ? this.state._label : typeof this.state._href === 'string' ? this.state._href : '',
            align: this._tooltipAlign,
        });
    }
    componentDidRender() {
        if (this.ctaRef.el) {
            this.tooltipCtrl.syncListeners(undefined, this.ctaRef.el, true);
        }
    }
    disconnectedCallback() {
        if (this.unsubscribeOnLocationChange) {
            this.unsubscribeOnLocationChange();
        }
        this.tooltipCtrl.destroy();
    }
    get host() { return index.getElement(this); }
    static get watchers() { return {
        "_accessKey": ["validateAccessKey"],
        "_ariaCurrentValue": ["validateAriaCurrentValue"],
        "_ariaControls": ["validateAriaControls"],
        "_ariaDescription": ["validateAriaDescription"],
        "_ariaExpanded": ["validateAriaExpanded"],
        "_ariaOwns": ["validateAriaOwns"],
        "_customClass": ["validateCustomClass"],
        "_disabled": ["validateDisabled"],
        "_download": ["validateDownload"],
        "_hideLabel": ["validateHideLabel"],
        "_href": ["validateHref"],
        "_icons": ["validateIcons"],
        "_inline": ["validateInline"],
        "_label": ["validateLabel"],
        "_on": ["validateOn"],
        "_role": ["validateRole"],
        "_shortKey": ["validateShortKey"],
        "_tabIndex": ["validateTabIndex"],
        "_target": ["validateTarget"],
        "_tooltipAlign": ["validateTooltipAlign"],
        "_variant": ["validateVariantClassName"]
    }; }
};
tslib_es6.__decorate([
    elementInteraction.directFocus('ctaRef')
], KolLinkWc.prototype, "focus", null);
tslib_es6.__decorate([
    elementInteraction.directClick('ctaRef')
], KolLinkWc.prototype, "click", null);

exports.kol_link_wc = KolLinkWc;
//# sourceMappingURL=kol-link-wc.entry.cjs.js.map
