import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { s as sanitizeSvg } from './svg.js';
import { i as inheritAttributes } from './attributes.js';
import { B as BEM } from './bem.js';
import { n as rOnLoad, b as waitAfterFramePaint } from './helpers.js';
import { t as toKebabCase } from './string.js';

const CarouselItem = /*@__PURE__*/ proxyCustomElement(class CarouselItem extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.balNavigate = createEvent(this, "balNavigate", 7);
        this.balFocus = createEvent(this, "balFocus", 7);
        this.balBlur = createEvent(this, "balBlur", 7);
        this.imageInheritAttributes = {};
        this.isOnLoadEventDone = false;
        this.containerId = '';
        this.svgContent = '';
        /**
         * Label of the slide which will be used for pagination tabs
         */
        this.label = '';
        /**
         * Svg content.
         */
        this.svg = '';
        /**
         * @deprecated
         * Defines the role of the carousel.
         */
        this.htmlRole = 'listitem';
        /**
         * The type of button.
         */
        this.elementType = 'button';
        /**
         * The name of the button, which is submitted with the form data.
         */
        this.name = undefined;
        /**
         * The value of the button, which is submitted with the form data.
         */
        this.value = undefined;
        /**
         * Specifies where to display the linked URL.
         * Only applies when an `href` is provided.
         */
        this.target = '_self';
        this.generateSvgContent = () => {
            if (this.svg !== undefined && this.svg.length > 0) {
                this.svgContent = sanitizeSvg(this.svg);
            }
        };
        this.onClick = (ev) => {
            if (this.href !== undefined) {
                this.balNavigate.emit(ev);
            }
        };
        this.onFocus = () => {
            this.balFocus.emit();
        };
        this.onBlur = () => {
            this.balBlur.emit();
        };
    }
    svgChanged() {
        this.generateSvgContent();
    }
    /**
     * LIFECYCLE
     * ------------------------------------------------------
     */
    connectedCallback() {
        this.generateSvgContent();
    }
    componentDidLoad() {
        rOnLoad(() => {
            this.isOnLoadEventDone = true;
        });
    }
    componentWillLoad() {
        this.imageInheritAttributes = inheritAttributes(this.el, ['alt']);
        this.getContainerId();
    }
    async setFocus() {
        await waitAfterFramePaint();
        if (this.buttonEl) {
            this.buttonEl.focus();
        }
    }
    async getContainerId() {
        const parentEl = this.el.closest('bal-carousel');
        this.containerId = await parentEl.getContainerId();
    }
    render() {
        const block = BEM.block('carousel');
        const itemEl = block.element('item');
        const isProduct = !!this.color && !!this.label;
        const parentEl = this.el.closest('bal-carousel');
        const role = parentEl && parentEl.controls === 'tabs' ? 'tabpanel' : 'listitem';
        const id = `${this.containerId}-${toKebabCase(this.label)}`;
        if (!isProduct) {
            return (h(Host, { id: id, role: role, class: Object.assign({}, itemEl.class()), "aria-label": this.label }, this.isOnLoadEventDone && this.src !== undefined ? (h("img", Object.assign({ draggable: false, onDragStart: () => false, src: this.src }, this.imageInheritAttributes))) : (''), h("slot", null)));
        }
        const button = itemEl.element('button');
        const image = button.element('image');
        const label = button.element('label');
        const { elementType, download, href, rel, target, name, value } = this;
        const TagType = this.href === undefined ? 'button' : 'a';
        const attrs = TagType === 'button'
            ? { type: elementType, name, value }
            : {
                download,
                href,
                rel,
                target,
            };
        return (h(Host, { id: id, role: role, "aria-label": this.label, class: Object.assign({}, itemEl.class()) }, h(TagType, Object.assign({}, attrs, { class: Object.assign(Object.assign({}, button.class()), button.modifier(`color-${this.color}`).class()), part: "native", onFocus: this.onFocus, onBlur: this.onBlur, onClick: this.onClick, ref: el => (this.buttonEl = el) }), this.isOnLoadEventDone && this.src !== undefined ? (h("img", Object.assign({ class: Object.assign({}, image.class()), draggable: false, onDragStart: () => false, "aria-hidden": "true", src: this.src }, this.imageInheritAttributes))) : this.isOnLoadEventDone && this.svgContent !== undefined ? (h("div", { class: Object.assign({}, image.class()), innerHTML: this.svgContent })) : (''), this.label !== undefined ? h("span", { class: Object.assign({}, label.class()) }, this.label) : '', h("slot", null))));
    }
    get el() { return this; }
    static get watchers() { return {
        "svg": ["svgChanged"]
    }; }
}, [260, "bal-carousel-item", {
        "src": [513],
        "label": [513],
        "svg": [1],
        "htmlRole": [1, "html-role"],
        "elementType": [1, "element-type"],
        "name": [513],
        "value": [520],
        "href": [1],
        "target": [1],
        "rel": [1],
        "download": [1],
        "color": [1],
        "isOnLoadEventDone": [32],
        "containerId": [32],
        "svgContent": [32],
        "setFocus": [64]
    }, undefined, {
        "svg": ["svgChanged"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["bal-carousel-item"];
    components.forEach(tagName => { switch (tagName) {
        case "bal-carousel-item":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, CarouselItem);
            }
            break;
    } });
}

const BalCarouselItem = CarouselItem;
const defineCustomElement = defineCustomElement$1;

export { BalCarouselItem, defineCustomElement };
