import { r as registerInstance, c as createEvent, h, H as Host, a as getElement } from './index-DBTJNfo7.js';
import { i as isItem } from './is-item-CrvUOVvg.js';
import { g as getIconName } from './get-icon-props-CgNJbSP4.js';
import { g as getMouseEventHandlers } from './3d-tilt-hover-effect-5eP2N9QI.js';

const cardCss = () => `@charset "UTF-8";*{box-sizing:border-box;min-width:0;min-height:0}:host(limel-card){display:flex;border-radius:var(--card-border-radius, 0.95rem)}section{box-sizing:border-box;display:flex;gap:0.5rem;flex-direction:column}:host(limel-card[orientation=landscape]) section{flex-direction:row}section{width:100%;border-radius:var(--card-border-radius, 0.95rem);border:1px solid rgb(var(--contrast-500));padding:0.25rem;background-color:var(--card-background-color, rgb(var(--contrast-300)))}section:hover{border-color:transparent;background-color:var(--card-background-color--hovered, var(--card-background-color, rgb(var(--contrast-200))))}.body{flex-grow:1;display:flex;flex-direction:column;gap:0.5rem}.image-wrapper{flex-shrink:0;display:flex;align-items:center;justify-content:center}:host(limel-card[orientation=portrait]) .image-wrapper{width:100%}:host(limel-card[orientation=landscape]) .image-wrapper{flex-shrink:0;max-width:40%;height:100%}:host(limel-card[orientation=landscape]) .image-wrapper img{height:100%}img{transition:filter 0.6s ease;object-fit:cover;border-radius:calc(var(--card-border-radius, 0.95rem) / 1.4);min-width:0.5rem;min-height:0.5rem;max-width:100%;max-height:100%}section:hover img,section:focus-visible img{transition-duration:0.2s;filter:saturate(1.3)}.markdown-wrapper{position:relative;flex-grow:1;display:flex;flex-direction:column}.markdown-wrapper limel-markdown{overflow-y:auto;flex-grow:1;padding:0.5rem 0.75rem}.markdown-wrapper::before{top:0;background:radial-gradient(farthest-side at 50% 0%, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0))}.markdown-wrapper::after{bottom:0;background:radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0))}.markdown-wrapper::before,.markdown-wrapper::after{content:"";pointer-events:none;position:absolute;right:0;left:0;height:0.75rem;opacity:0;transition:opacity 0.6s ease;background-repeat:no-repeat}.markdown-wrapper.can-scroll-up::before,.markdown-wrapper.can-scroll-down::after{opacity:1}header{flex-shrink:0;display:flex;justify-content:center;gap:0.5rem;padding:0.25rem 0.75rem}:host(limel-card[orientation=landscape]) header{padding-top:0.5rem}header:has(limel-icon){padding-left:0.25rem}header .headings{flex-grow:1;display:flex;flex-direction:column;gap:0.125rem}header .title{padding-right:1.25rem}header limel-icon{flex-shrink:0;width:2rem}header h1{font-size:1.125rem;font-weight:500;color:var(--card-heading-color, rgb(var(--contrast-1100)));letter-spacing:-0.03125rem}header h2{font-size:var(--limel-theme-default-font-size);font-weight:400;color:var(--card-subheading-color, rgb(var(--contrast-1000)))}header h1,header h2{word-break:break-word;hyphens:auto;-webkit-hyphens:auto;margin:0}limel-action-bar{flex-shrink:0;--action-bar-background-color:transparent;margin-left:auto}limel-3d-hover-effect-glow{border-radius:var(--card-border-radius, 0.95rem)}:host(limel-card){isolation:isolate;transform-style:preserve-3d;perspective:1000px}@media (prefers-reduced-motion){:host(limel-card){perspective:2000px}}section{position:relative;transition-duration:0.8s;transition-property:transform, box-shadow, background-color;transition-timing-function:ease-out;transform:scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg)}section:focus{outline:none}section:hover,section:focus,section:focus-visible,section:focus-within{will-change:background-color, box-shadow, transform}section:hover,section:focus,section:focus-visible,section:active{transition-duration:0.2s}section:hover,section:focus-visible{box-shadow:var(--button-shadow-hovered), var(--shadow-depth-16)}section:hover{transform:scale3d(1.01, 1.01, 1.01) rotate3d(var(--limel-3d-hover-effect-rotate3d))}section:focus-visible{outline:none;transform:scale3d(1.01, 1.01, 1.01)}section:hover limel-3d-hover-effect-glow{--limel-3d-hover-effect-glow-opacity:0.5}@media (prefers-reduced-motion){section:hover limel-3d-hover-effect-glow{--limel-3d-hover-effect-glow-opacity:0.2}}:host(limel-card[clickable]) section{cursor:pointer;box-shadow:var(--button-shadow-normal)}:host(limel-card[clickable]) section:hover,:host(limel-card[clickable]) section:focus-visible{box-shadow:var(--button-shadow-hovered), var(--shadow-depth-16)}:host(limel-card[clickable]) section:active{transform:scale3d(1, 1, 1) rotate3d(0, 0, 0, 0deg);box-shadow:var(--button-shadow-pressed)}:host(limel-card[clickable]) section:focus-visible{box-shadow:var(--shadow-depth-8-focused), var(--button-shadow-hovered)}:host(limel-card[clickable]) section:focus-visible:active{box-shadow:var(--shadow-depth-8-focused), var(--button-shadow-pressed)}`;

const Card = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.actionSelected = createEvent(this, "actionSelected");
        /**
         * Actions to display in the card,
         * to provide the user with options to interact with the content.
         */
        this.actions = [];
        /**
         * When true, improve the accessibility of the component and hints the user
         * that the card can be interacted width.
         */
        this.clickable = false;
        /**
         * The orientation of the card,
         * specially useful when the card has an image.
         */
        this.orientation = 'portrait';
        this.canScrollUp = false;
        this.canScrollDown = false;
        this.setMarkdownElement = (element) => {
            var _a;
            if (element === this.markdownElement) {
                return;
            }
            if (this.markdownElement) {
                (_a = this.markdownResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
                this.markdownElement.removeEventListener('scroll', this.checkIfScrollable);
            }
            this.markdownElement = element;
            if (!this.markdownElement) {
                return;
            }
            this.markdownResizeObserver = new ResizeObserver(this.checkIfScrollable);
            this.markdownResizeObserver.observe(this.markdownElement);
            this.markdownElement.addEventListener('scroll', this.checkIfScrollable, { passive: true });
            this.checkIfScrollable();
        };
        this.checkIfScrollable = () => {
            if (!this.markdownElement) {
                return;
            }
            const scrollHeight = this.markdownElement.scrollHeight;
            const clientHeight = this.markdownElement.clientHeight;
            const scrollTop = this.markdownElement.scrollTop;
            const isScrollable = scrollHeight > clientHeight;
            // Use a 2px tolerance to handle sub-pixel rounding issues
            const isScrolledToBottom = scrollTop + clientHeight >= scrollHeight - 2;
            const shouldShowBottomShadow = isScrollable && !isScrolledToBottom;
            const isScrolledToTop = scrollTop <= 1;
            const shouldShowTopShadow = isScrollable && !isScrolledToTop;
            if (this.canScrollDown !== shouldShowBottomShadow) {
                this.canScrollDown = shouldShowBottomShadow;
            }
            if (this.canScrollUp !== shouldShowTopShadow) {
                this.canScrollUp = shouldShowTopShadow;
            }
        };
        this.handleActionSelect = (event) => {
            event.stopPropagation();
            if (isItem(event.detail)) {
                this.actionSelected.emit(event.detail);
            }
        };
    }
    componentWillLoad() {
        const { handleMouseEnter, handleMouseLeave } = getMouseEventHandlers(this.host);
        this.handleMouseEnter = handleMouseEnter;
        this.handleMouseLeave = handleMouseLeave;
    }
    disconnectedCallback() {
        var _a, _b;
        (_a = this.markdownResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
        (_b = this.markdownElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('scroll', this.checkIfScrollable);
    }
    componentDidLoad() {
        this.setMarkdownElement(this.markdownElement);
    }
    render() {
        return (h(Host, { key: 'a5b8b7c2bead5c54c7970b6d382704922c066e73', onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave }, h("section", { key: 'cb7c4392b7d92bc47ee533c24a1ca92818aa7076', tabindex: this.clickable ? 0 : '' }, this.renderImage(), h("div", { key: '484d033da40562d5a460d629ba7cfa6116d9461d', class: "body" }, this.renderHeader(), this.renderSlot(), this.renderValue(), this.renderActionBar()), h("limel-3d-hover-effect-glow", { key: 'e86f33835e34306ec046d7c5fcf7fdb0f667fa86' }))));
    }
    renderImage() {
        var _a;
        if (!((_a = this.image) === null || _a === void 0 ? void 0 : _a.src)) {
            return;
        }
        return (h("div", { class: "image-wrapper" }, h("img", { src: this.image.src, alt: this.image.alt, loading: "lazy" })));
    }
    renderHeader() {
        if (!this.heading && !this.subheading && !this.icon) {
            return;
        }
        return (h("header", null, this.renderIcon(), h("div", { class: "headings" }, this.renderHeading(), this.renderSubheading())));
    }
    renderIcon() {
        var _a;
        const icon = getIconName(this.icon);
        const color = typeof this.icon === 'string' ? undefined : (_a = this.icon) === null || _a === void 0 ? void 0 : _a.color;
        if (!icon) {
            return;
        }
        return (h("limel-icon", { style: {
                color: `${color}`,
            }, badge: true, name: icon }));
    }
    renderHeading() {
        if (!this.heading) {
            return;
        }
        return h("h1", { class: "title" }, this.heading);
    }
    renderSubheading() {
        if (!this.subheading) {
            return;
        }
        return h("h2", null, this.subheading);
    }
    renderSlot() {
        return h("slot", { name: "component" });
    }
    renderValue() {
        if (!this.value) {
            return;
        }
        return (h("div", { class: {
                'markdown-wrapper': true,
                'can-scroll-up': this.canScrollUp,
                'can-scroll-down': this.canScrollDown,
            } }, h("limel-markdown", { class: "body-text", ref: this.setMarkdownElement, value: this.value })));
    }
    renderActionBar() {
        if (this.actions.length === 0) {
            return;
        }
        return (h("limel-action-bar", { actions: this.actions, onItemSelected: this.handleActionSelect }));
    }
    get host() { return getElement(this); }
};
Card.style = cardCss();

export { Card as limel_card };
