import './bootstrap';
// import './calendar-interact.js';
import './calendar-week-canvas.js';
import agentVoiceOrb from './agent-voice-orb.js';

window.agentVoiceOrb = agentVoiceOrb;

import '../plugins/Notification/index.js';
import './websocket/connection.js';

document.addEventListener('livewire:init', () => {

    Livewire.on('notify', (payload) => {

        const data = Array.isArray(payload) ? payload[0] : payload;

        message.toast({
            type: data.type ?? 'info',
            title: data.title ?? '',
            text: data.message ?? '',
            duration: data.duration ?? undefined,

            onClick: () => {
                if (data.action?.event) {
                    Livewire.dispatch(data.action.event);
                }
            }
        });

    });

});


function openCenteredWindow(url, title, w, h) {
    // Calculate position
    const left = (screen.width / 2) - (w / 2);
    const top = (screen.height / 2) - (h / 2);

    return window.open(
        url,
        title,
        `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=${w}, height=${h}, top=${top}, left=${left}`
    );
}

window.openCenteredWindow = openCenteredWindow;
