/**
 * Copyright Aquera Inc 2023
 *
 * This source code is licensed under the BSD-3-Clause license found in the
 * LICENSE file in the root directory of this source tree.
 */
import { __decorate } from "tslib";
import { html } from 'lit';
import { customElement, state, property } from 'lit/decorators.js';
import { styles } from './nile-link.css';
import { HasSlotController } from '../slot';
import { ifDefined } from 'lit/directives/if-defined.js';
import { classMap } from 'lit/directives/class-map.js';
import NileElement, { setupA11yMetadata } from '../internal/nile-element';
import { A11yProperty } from '../internal/accessibility/a11y.property.enum';
import { Role } from '../internal/accessibility/role.enum';
import { A11yCustomValue } from '../internal/accessibility/a11y.custom-value.enum';
import { A11yRole } from '../internal/accessibility/a11y.role.enum';
import { A11yState } from '../internal/accessibility/a11y.state.enum';
/**
 * Nile icon component.
 *
 * @tag nile-link
 *
 */
let NileLink = class NileLink extends NileElement {
    constructor() {
        super(...arguments);
        this.hasSlotController = new HasSlotController(this, '[default]', 'prefix', 'suffix');
        this.hasFocus = false;
        /** Disables the button. */
        this.disabled = false;
        this.button = false;
        /* #endregion */
    }
    /**
     * The styles for Link
     * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
     */
    static get styles() {
        return [styles];
    }
    connectedCallback() {
        super.connectedCallback();
        this.handleHostClick = this.handleHostClick.bind(this);
        this.addEventListener('click', this.handleHostClick);
        this.emit('nile-init');
        setupA11yMetadata(this, {
            [Role.Role]: A11yRole.Link,
            [A11yProperty.AriaLabel]: this.textContent?.trim() || A11yCustomValue.Link,
        });
    }
    updated(_changedProperties) {
        super.updated(_changedProperties);
        if (_changedProperties.has('disabled')) {
            setupA11yMetadata(this, {
                [A11yState.AriaDisabled]: this.disabled,
            });
        }
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('click', this.handleHostClick);
        this.emit('nile-destroy');
    }
    handleHostClick(event) {
        // Prevent the click event from being emitted when the button is disabled
        if (this.disabled) {
            event.preventDefault();
            event.stopImmediatePropagation();
            event.stopPropagation();
        }
    }
    handleBlur() {
        this.hasFocus = false;
        this.emit('nile-blur');
    }
    handleFocus() {
        this.hasFocus = true;
        this.emit('nile-focus');
    }
    handleClick(e) {
        if (this.disabled) {
            e.preventDefault();
            e.stopPropagation();
            return;
        }
    }
    /**
     * Render method
     * @slot This is a slot test
     */
    render() {
        return html `
      <a
        part="base"
        href="${ifDefined(this.href)}"
        class=${classMap({
            'link': true,
            'link--disabled': this.disabled,
            'link__button': this.button,
        })}
        .disabled=${this.disabled}
        title=${this
            .title /* An empty title prevents browser validation tooltips from appearing on hover */}
        aria-disabled=${this.disabled ? 'true' : 'false'}
        tabindex=${this.disabled ? '-1' : '0'}
        @blur=${this.handleBlur}
        @focus=${this.handleFocus}
        @click=${this.handleClick}
      >
        <slot name="prefix" part="prefix" class="link__prefix"></slot>
        <slot part="label" class="link__label"></slot>
        <slot name="suffix" part="suffix" class="link__suffix"></slot>
      </a>
    `;
    }
};
__decorate([
    state()
], NileLink.prototype, "hasFocus", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], NileLink.prototype, "disabled", void 0);
__decorate([
    property({ type: Boolean })
], NileLink.prototype, "button", void 0);
__decorate([
    property({ type: String })
], NileLink.prototype, "href", void 0);
NileLink = __decorate([
    customElement('nile-link')
], NileLink);
export { NileLink };
export default NileLink;
//# sourceMappingURL=nile-link.js.map