'use strict';

var index = require('./index-C_OnxXhP.js');
var dom = require('./dom--t_vVnyU.js');
var index_esm = require('./index.esm-C1i_NocP.js');

const mentionCss = () => `:host(limebb-mention){display:inline}a{transition:background-color 0.2s ease;white-space:normal;overflow-wrap:break-word;word-break:break-word;padding:0 0.125rem;border-radius:0.25rem;text-decoration:none;color:rgb(var(--color-blue-default));background-color:rgb(var(--color-blue-default), 0.06)}a:hover{background-color:rgb(var(--color-blue-default), 0.16)}a:before,span:before{content:"@";opacity:0.7}`;

const Mention = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
    }
    connectedCallback() {
        const element = dom.findParentElement(index.getElement(this), this.hasPlatform);
        if (!element) {
            return;
        }
        this.loadLimeObject(element.platform);
    }
    hasPlatform(element) {
        if (!('platform' in element)) {
            return false;
        }
        if (!element.platform) {
            return false;
        }
        return typeof element.platform === 'object';
    }
    async loadLimeObject(platform) {
        const repository = platform.get(index_esm.n.LimeObjectRepository);
        this.limeobject = repository.getObject(this.limetype, this.objectid);
        if (this.limeobject) {
            return;
        }
        try {
            await repository.loadObject(this.limetype, this.objectid);
        }
        catch (_a) {
            console.error('Could not load mentioned object');
        }
        this.limeobject = repository.getObject(this.limetype, this.objectid);
    }
    render() {
        if (!this.limeobject) {
            return this.renderSlot();
        }
        return this.renderLimeObject(this.limeobject);
    }
    renderLimeObject(limeobject) {
        return (index.h("a", { href: `object/${this.limetype}/${this.objectid}` }, limeobject.descriptive, this.renderSlot({ hidden: true })));
    }
    renderSlot(attributes = {}) {
        return (index.h("span", Object.assign({}, attributes), index.h("slot", null)));
    }
};
Mention.style = mentionCss();

exports.limebb_mention = Mention;
