!function(e,t){"use strict";var r,s=null,a=!1;function i(e){return t.querySelector(e)}function n(e,t){var r=i("#easychat-webpush-toggle");if(r){r.dataset.state=e,r.title=t,r.classList.toggle("text-success","subscribed"===e),r.classList.toggle("text-warning","unsupported"===e||"blocked"===e),r.classList.toggle("text-muted-custom","subscribed"!==e&&"unsupported"!==e&&"blocked"!==e);var s=r.querySelector("i");s&&(s.className="subscribed"===e?"fa fa-bell fa-lg":"fa fa-bell-o fa-lg")}}function u(){return"serviceWorker"in navigator&&"PushManager"in e&&"Notification"in e&&e.isSecureContext?navigator.serviceWorker.getRegistration("./").then(function(e){return e?e.pushManager.getSubscription().then(function(e){return n(e?"subscribed":"idle",e?"Уведомления включены":"Включить браузерные уведомления"),!!e}):(n("idle","Включить браузерные уведомления"),!1)}).catch(function(){return n("idle","Включить браузерные уведомления"),!1}):(n("unsupported",e.isSecureContext?"Браузерные уведомления недоступны":"Нужен HTTPS"),Promise.resolve(!1))}function o(){if(e.EasyChatWebPushSubscribeFlow)return Promise.resolve(e.EasyChatWebPushSubscribeFlow);if(s)return s;var r=(e.EasyChatLazyAssetUrls||{}).webpushSubscribe||"";return r?s=new Promise(function(a,i){var n=t.querySelector('script[data-easychat-lazy-script="webpushSubscribe"]')||t.createElement("script");n.src=r,n.defer=!0,n.setAttribute("data-easychat-lazy-script","webpushSubscribe"),n.onload=function(){n.setAttribute("data-loaded","1"),e.EasyChatWebPushSubscribeFlow?a(e.EasyChatWebPushSubscribeFlow):i(new Error("webpush_subscribe_api_missing"))},n.onerror=function(){s=null,i(new Error("failed_lazy_asset_webpushSubscribe"))},n.parentNode||t.head.appendChild(n)}):Promise.reject(new Error("missing_lazy_asset_webpushSubscribe"))}function c(){var e=i("#easychat-webpush-toggle");return e&&(e.setAttribute("aria-busy","true"),n("loading","Проверка уведомлений...")),o().then(function(e){if(e&&"function"==typeof e.activateFromBootstrap)return e.activateFromBootstrap();if(e&&"function"==typeof e.activate)return e.activate();throw new Error("webpush_subscribe_activate_missing")}).catch(function(){n("blocked","Не удалось загрузить браузерные уведомления")}).then(function(){e&&e.setAttribute("aria-busy","false")})}e.EasyChatWebPushBootstrap={loadSubscribeFlow:o,refreshState:u,openFlow:c},r=function(){if(!a){a=!0;var e=i("#easychat-webpush-toggle");e&&(e.addEventListener("click",function(e){e.preventDefault(),c()}),u())}},"loading"===t.readyState?t.addEventListener("DOMContentLoaded",r,{once:!0}):r()}(window,document);