import { createIcons, icons } from "lucide";
import EasyMDE from "easymde";
import "easymde/dist/easymde.min.css";

import { calculate as calculateHashes } from "./hashes.js";
import hovercard from "./hovercard.js";
import notifications from "./notifications.js";
import conversations from "./conversations.js";
import settings from "./settings.js";
import { initMobileMenu } from "./mobile-menu.js";

/**
 * Get config defined in meta.blade.php
 * @param {string} key
 * @return {string|null}
 */
window.getConfig = function( key ){
    return document.querySelector('meta[name="config-' + key +  '"]')?.getAttribute('content') ?? null;
}

// Lucide icons.
createIcons({ icons });

window.refreshIcons = (container = document) => {
    const pending = container.querySelectorAll('[data-lucide]');
    if (pending.length === 0) return;
    createIcons({ icons });
};

// EasyMDE.
window.EasyMDE = EasyMDE;

// Hashes.
window.calculateHashes = calculateHashes;

// Hover card.
Alpine.store('hovercard', hovercard() );

// Notifications
Alpine.store('notifications', notifications() );

// Conversations
Alpine.store('conversations', conversations() );

// Settings
Alpine.store('settings', settings() );

// Mobile Menu
document.addEventListener('DOMContentLoaded', initMobileMenu);
