/* Notifications helper — permission + local/push display via the service worker.
   The in-app feed (bell + sheet) lives in app.js; this handles the OS layer.
   Real push needs a VAPID server + subscribe(); sw.js already handles 'push'. */
window.Notify = (function () {
    function supported() { return 'Notification' in window; }
    function permission() { return supported() ? Notification.permission : 'unsupported'; }

    async function request() {
        if (!supported()) return 'unsupported';
        try { return await Notification.requestPermission(); }
        catch (e) { return Notification.permission; }
    }

    async function showLocal(title, opts) {
        opts = opts || {};
        if (permission() !== 'granted') return false;
        var base = { icon: './icons/icon-192.png', badge: './icons/icon-192.png', vibrate: [80, 40, 80] };
        try {
            if (navigator.serviceWorker) {
                var reg = await navigator.serviceWorker.ready;
                await reg.showNotification(title, Object.assign(base, opts));
                return true;
            }
        } catch (e) { /* fall through */ }
        try { new Notification(title, Object.assign(base, opts)); return true; } catch (e) { return false; }
    }

    return { supported: supported, permission: permission, request: request, showLocal: showLocal };
})();
