// retoor <retoor@molodetz.nl>

import { assetUrl } from "./assetVersion.js";

const EMOJI_DATA_SOURCE = assetUrl("/static/vendor/emoji-picker-element/data.json");

let pickerElementModule = null;

export class EmojiPickerElement {
    static load() {
        if (!pickerElementModule) {
            pickerElementModule = import(
                assetUrl("/static/vendor/emoji-picker-element/index.js")
            ).catch(() => {});
        }
        return pickerElementModule;
    }

    static create(onSelect) {
        const picker = document.createElement("emoji-picker");
        picker.setAttribute("data-source", EMOJI_DATA_SOURCE);
        picker.addEventListener("emoji-click", (event) => onSelect(event.detail.unicode));
        return picker;
    }
}
window.EmojiPickerElement = EmojiPickerElement;
