import { p as proxyCustomElement, H, e as createEvent, h, c as Host } from './p-ae373651.js';
import { C as ChatHead } from './p-38d22d57.js';
import { a as sanitizeLink } from './p-efabd2ce.js';
import { e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import { d as downloadFile } from './p-47314bc7.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as defineCustomElement$3 } from './p-85587a5c.js';
import { d as defineCustomElement$2 } from './p-3e0452c4.js';
import { d as defineCustomElement$1 } from './p-e6245534.js';

const rtkImageMessageCss = ":host{line-height:initial;font-family:var(--rtk-font-family, sans-serif);font-feature-settings:normal;font-variation-settings:normal}p{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px)}.image-spinner{cursor:wait}.image-errored{cursor:not-allowed}";
const RtkImageMessageStyle0 = rtkImageMessageCss;

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
        r = Reflect.decorate(decorators, target, key, desc);
    else
        for (var i = decorators.length - 1; i >= 0; i--)
            if (d = decorators[i])
                r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const RtkImageMessage = /*@__PURE__*/ proxyCustomElement(class RtkImageMessage extends H {
    constructor() {
        super();
        this.__registerHost();
        this.stateUpdate = createEvent(this, "rtkStateUpdate", 7);
        /** Date object of now, to calculate distance between dates */
        this.now = new Date();
        /** Whether the message is continued by same user */
        this.isContinued = false;
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        /** show message in bubble */
        this.showBubble = false;
        this.status = 'loading';
    }
    render() {
        return (h(Host, { key: '8ac3f237a8d77254219f8b5763dd6b53d2cb764b' }, !this.isContinued && (h(ChatHead, { key: '6eb17e16b4fd4e12d3b8a7ce8a5bcfd548930a50', name: this.message.displayName, time: this.message.time, now: this.now })), h("div", { key: 'd5cce1675057a0378425452898fcbc4c738b7bb2', class: {
                body: true,
                bubble: this.showBubble,
            }, part: "body" }, h("div", { key: '45f073d8268c92aee4fec8b139fd325e668dab76', class: { image: true, loaded: this.status === 'loaded' } }, h("img", { key: '28a206e34b791205e042233ee7f317f389f421da', src: sanitizeLink(this.message.link), onLoad: () => {
                this.status = 'loaded';
            }, onError: () => {
                this.status = 'errored';
            }, onClick: () => {
                if (this.status === 'loaded') {
                    this.stateUpdate.emit({ image: this.message });
                }
            } }), this.status === 'loading' && (h("div", { key: 'b7862bff3f6c9df7042bdab2f6b0370e7c362f02', class: "image-spinner", title: this.t('chat.img.loading'), "aria-label": this.t('chat.img.loading') }, h("rtk-spinner", { key: '460074eae700cd3f522019f967ba5955b9eb972e', iconPack: this.iconPack }))), this.status === 'errored' && (h("div", { key: 'bdf48c8fdc5057d2c77d10b64d7af5576f478556', class: "image-errored", title: this.t('chat.error.img_not_found'), "aria-label": this.t('chat.error.img_not_found') }, h("rtk-icon", { key: '523e5ff6dd4579082e5953346155df9b7b23862f', icon: this.iconPack.image_off }))), this.status === 'loaded' && (h("div", { key: '89e3679101615838ec6a0f521b98386454d25197', class: "actions" }, h("rtk-button", { key: 'ccaed0a3d70945d66e7b700e01bbc5289421f8ae', class: "action", variant: "secondary", kind: "icon", onClick: () => {
                this.stateUpdate.emit({ image: this.message });
            } }, h("rtk-icon", { key: 'ee20f5497dbb38590de65c4a404eda90b0d5c4e5', icon: this.iconPack.full_screen_maximize })), h("rtk-button", { key: '181d39cfd837e45d3da1aa0fa0f97226c50cb46a', class: "action", variant: "secondary", kind: "icon", onClick: () => downloadFile(this.message.link, { fallbackName: 'image' }) }, h("rtk-icon", { key: '53c7e551ec4a2efb32d60d16eb2a4a02144abf4f', icon: this.iconPack.download }))))))));
    }
    static get style() { return RtkImageMessageStyle0; }
}, [0, "rtk-image-message", {
        "message": [16],
        "now": [16],
        "isContinued": [516, "is-continued"],
        "iconPack": [16],
        "t": [16],
        "showBubble": [4, "show-bubble"],
        "status": [32]
    }]);
__decorate([
    SyncWithStore()
], RtkImageMessage.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkImageMessage.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-image-message", "rtk-button", "rtk-icon", "rtk-spinner"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-image-message":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkImageMessage);
            }
            break;
        case "rtk-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "rtk-spinner":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkImageMessage as R, defineCustomElement as d };
