import { r as registerInstance, h, H as Host, a as getElement } from './index-Co4V4Zk-.js';

const spwCardCss = () => `@charset "UTF-8";html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:block;position:relative;width:100%;--spw-card-background:var(--spw-ds-white);--spw-card-box-shadow:var(--spw-effect-elevation-6);--spw-card-border:none}:host[data-modal-trigger]{cursor:pointer}:host(.--is-full-height){height:100%}.spw-card{display:block;border-radius:5px;background:var(--spw-card-background);box-shadow:var(--spw-card-box-shadow);border:var(--spw-card-border);transition:all 0.3s ease-in-out}:host(.--is-full-height) .spw-card{height:100%}.spw-card--hoverable:hover{box-shadow:var(--spw-effect-elevation-4);transform:translateY(-5px)}.spw-card__dates{cursor:pointer;position:absolute;top:50%;left:0;transform:translate(-50%, -50%);flex-direction:column;line-height:1.1;width:80px;height:80px;text-align:center;color:white;display:inline-flex;align-items:center;justify-content:center;background:var(--spw-ds-primary);border-radius:50%;font-size:18px;text-decoration:none;z-index:2}.spw-card__date-item span:first-of-type{font-weight:bold}.spw-card__link{display:block;height:100%;width:100%;color:inherit;text-decoration:none}.spw-card--no-image .spw-card__link{padding-top:15px}.spw-card__link:focus-visible{outline:3px solid white;outline-offset:-1px;box-shadow:0 0 0 5px black;border-radius:5px}.spw-card--vertical .spw-card__link,.spw-card--video .spw-card__link{display:flex;min-height:240px}.spw-card--event .spw-card__link{display:flex}.spw-card--sidebar{box-shadow:none}.spw-card--sidebar:hover{box-shadow:none}.spw-card--sidebar .spw-card__link{display:flex;gap:16px}.spw-card--event{position:relative;width:calc(100% - 40px);left:40px}.spw-card--rounded-picture{box-shadow:none;background:transparent}.spw-card--rounded-picture:hover{box-shadow:none}.spw-card--rounded-picture .spw-card__link{display:flex;flex-direction:column}`;

const SpwCard = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.hasImage = false;
        this.childHoveredCount = 0;
        /** Type de variante de carte */
        this.variant = 'news';
        /** Type d'élément du bouton */
        this.elementType = 'a';
        /** Attribut target, s'applique uniquement si href est rempli */
        this.target = '_self';
        /** Si vrai, les cartes ont la même hauteur */
        this.fullHeight = false;
        /** Si désactivée, la carte n'est pas utilisable */
        this.disabled = false;
        this.onNestedCardEnter = () => {
            this.childHoveredCount++;
            this.setImageHovered(false);
        };
        this.onNestedCardLeave = () => {
            this.childHoveredCount = Math.max(0, this.childHoveredCount - 1);
            if (this.childHoveredCount === 0 && this.isPointerInside(this.el)) {
                this.setImageHovered(true);
            }
        };
    }
    componentWillLoad() {
        this.checkForImage();
        this.applyVariantToChildren();
        this.attachNestedCardListeners();
    }
    slotChanged() {
        this.checkForImage();
        this.applyVariantToChildren();
        this.attachNestedCardListeners();
    }
    onMouseEnter() {
        if (this.childHoveredCount === 0) {
            this.setImageHovered(true);
        }
    }
    onMouseLeave() {
        this.setImageHovered(false);
    }
    attachNestedCardListeners() {
        requestAnimationFrame(() => {
            const nestedCards = this.el.querySelectorAll('spw-card');
            nestedCards.forEach(card => {
                card.addEventListener('mouseenter', this.onNestedCardEnter.bind(this), true);
                card.addEventListener('mouseleave', this.onNestedCardLeave.bind(this), true);
            });
        });
    }
    isPointerInside(element) {
        const rect = element.getBoundingClientRect();
        const { left, top, right, bottom } = rect;
        const { clientX, clientY } = window;
        return clientX >= left && clientX <= right && clientY >= top && clientY <= bottom;
    }
    checkForImage() {
        requestAnimationFrame(() => {
            const imageElement = this.el.querySelector('spw-card-image');
            const contentElement = this.el.querySelector('spw-card-content');
            this.hasImage = !!imageElement;
            if (!this.hasImage) {
                contentElement === null || contentElement === void 0 ? void 0 : contentElement.classList.add('--no-image');
            }
        });
    }
    formatDate(date) {
        if (!date)
            return [];
        const parts = date.split('/');
        return parts.flatMap((part, index) => (index < parts.length - 1 ? [h("span", null, part), h("span", null, "/")] : [h("span", null, part)]));
    }
    applyVariantToChildren() {
        requestAnimationFrame(() => {
            const variantClass = `--${this.variant}`;
            const contentElement = this.el.querySelector('spw-card-content');
            const imageElement = this.el.querySelector('spw-card-image');
            const titleElement = this.el.querySelector('spw-card-title');
            const excerptElement = this.el.querySelector('spw-card-excerpt');
            const subtagsElement = this.el.querySelector('spw-card-subtags');
            contentElement === null || contentElement === void 0 ? void 0 : contentElement.classList.add(variantClass);
            imageElement === null || imageElement === void 0 ? void 0 : imageElement.classList.add(variantClass);
            titleElement === null || titleElement === void 0 ? void 0 : titleElement.classList.add(variantClass);
            excerptElement === null || excerptElement === void 0 ? void 0 : excerptElement.classList.add(variantClass);
            subtagsElement === null || subtagsElement === void 0 ? void 0 : subtagsElement.classList.add(variantClass);
        });
    }
    setImageHovered(isHovered) {
        const imageElement = this.el.querySelector('spw-card-image');
        const titleElement = this.el.querySelector('spw-card-title');
        if (imageElement && this.href) {
            imageElement.classList.toggle('--hovered', isHovered);
        }
        if (titleElement && this.href) {
            titleElement.classList.toggle('--hovered', isHovered);
        }
    }
    get elementClass() {
        return {
            'spw-card': true,
            'spw-card--hoverable': !!this.href,
            'spw-card--no-image': !this.hasImage,
            [`spw-card--${this.variant}`]: true,
        };
    }
    render() {
        const { href, rel, target, dateStart, dateEnd, variant } = this;
        const TagType = this.href === undefined ? 'div' : 'a';
        const attrs = TagType === 'div'
            ? {}
            : {
                href,
                rel,
                target,
            };
        const ariaAttributes = {
            'aria-label': this === null || this === void 0 ? void 0 : this.accAriaLabel,
            'aria-disabled': this.disabled ? 'true' : null,
        };
        return (h(Host, { key: '1ba4f06ba66af1625688a01d08c34fab95499577', class: { '--is-full-height': this.fullHeight } }, h("article", { key: '135ae12d051e9ebc078029c99ac52ea49bf540db', class: this.elementClass }, variant === 'event' && (h(TagType, Object.assign({ key: '99c5e749128c5293c44ddeb4c85bf143dbe3c6b1' }, attrs, { class: "spw-card__dates" }), dateStart && h("div", { key: 'fcf0661e3aae2de10ad7b845da453553662b3154', class: "spw-card__date-item" }, this.formatDate(dateStart)), dateEnd && h("div", { key: '11cc7956f31154ac081e6e819294fcfe6aafff5d', class: "spw-card__date-item" }, this.formatDate(dateEnd)))), h(TagType, Object.assign({ key: 'bc3380c036847c8ac197e731f05f0333a2734634' }, attrs, ariaAttributes, { class: "spw-card__link" }), h("slot", { key: 'c4c0f79011ee0ca8a893a080c177f17c51526768' })))));
    }
    get el() { return getElement(this); }
};
SpwCard.style = spwCardCss();

export { SpwCard as spw_card };
