!function(e,t){"use strict";function a(t){if("function"==typeof e.EasyChatRouteUrl)return e.EasyChatRouteUrl(t);var a="index.php?route=",n=String(e.EasyChatRouteBase||"");return n&&0===t.indexOf(a)?n+t.substring(16):t}function n(e){return Array.prototype.slice.call(t.querySelectorAll(e))}function i(e,a,n){var i=t.createElement(e);return a&&(i.className=a),void 0!==n&&(i.textContent=String(n)),i}function d(t){t&&t.animate&&!e.matchMedia("(prefers-reduced-motion: reduce)").matches&&t.animate([{opacity:0,transform:"translateY(6px)"},{opacity:1,transform:"translateY(0)"}],{duration:220,easing:"cubic-bezier(.2,.8,.2,1)"})}function r(t,i,d){var r=new URLSearchParams;r.set("action",i),r.set("target_version_code",String(t.release.version_code)),fetch(a("index.php?route=index/deferAndroidUpdate"),{method:"POST",credentials:"same-origin",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded;charset=UTF-8","X-EasyChat-CSRF":e.EasyChatCsrfToken||""},body:r.toString()}).then(function(e){return e.json().then(function(t){if(!e.ok||!t||!t.success)throw new Error("defer_failed");return t})}).then(function(t){var a,i;i=function(){n("[data-android-update-notice]").forEach(function(e){e.hidden=!0})},(a=d)&&a.animate&&!e.matchMedia("(prefers-reduced-motion: reduce)").matches?a.animate([{opacity:1,transform:"translateY(0)"},{opacity:0,transform:"translateY(-5px)"}],{duration:160,easing:"ease-in"}).addEventListener("finish",i,{once:!0}):i(),e.EasyChatNotify&&t.message&&e.EasyChatNotify.info(t.message)}).catch(function(){e.EasyChatNotify&&e.EasyChatNotify.error("Не удалось сохранить выбор. Повторите ещё раз.")})}function o(e){var a=e.admin_summary,n=t.querySelector("[data-android-update-admin-summary]");if(n&&a&&!(a.known_total<=0)){var i=n.querySelector("[data-android-update-admin-text]"),r=n.querySelector("[data-android-update-admin-link]");i.textContent=a.outdated_total>0?a.outdated_total+" из "+a.known_total+" активных устройств требуют обновления.":"Все "+a.known_total+" активных устройств используют актуальную версию.",r&&(r.href=e.release.rustore_url),n.hidden=!1,d(n)}}function s(){(n("[data-android-update-notice]").length||t.querySelector("[data-android-update-admin-summary]"))&&fetch(a("index.php?route=index/androidUpdateStatus"),{method:"GET",credentials:"same-origin",headers:{Accept:"application/json"}}).then(function(e){if(!e.ok)throw new Error("status_failed");return e.json()}).then(function(t){t&&t.success&&(e.EasyChatAndroidUpdateSnapshot=t,t.visible&&n("[data-android-update-notice]").forEach(function(e){!function(e,t){e.replaceChildren();var a=i("section","android-update-notice"+(t.critical?" is-critical":""));a.setAttribute("role","region"),a.setAttribute("aria-label","Обновление Android");var n=i("div","android-update-notice-head"),o=i("span","android-update-notice-icon");o.setAttribute("aria-hidden","true"),o.appendChild(i("i","fa fa-android"));var s=i("div");s.appendChild(i("h3","","Android "+t.release.version_name+" доступен"));var c=1===t.outdated_total?t.devices[0].device_label+": установлена "+t.devices[0].current_version:t.outdated_total+" из "+t.known_total+" устройств требуют обновления";if(s.appendChild(i("p","",c)),n.appendChild(o),n.appendChild(s),t.can_dismiss){var u=i("button","android-update-notice-dismiss");u.type="button",u.title="Скрыть до следующей версии",u.setAttribute("aria-label",u.title),u.appendChild(i("i","fa fa-times")),u.addEventListener("click",function(){r(t,"dismiss",a)}),n.appendChild(u)}else n.appendChild(i("span"));if(a.appendChild(n),t.outdated_total>1){var p=i("ul","android-update-notice-devices");t.devices.slice(0,3).forEach(function(e){p.appendChild(i("li","",e.device_label+" · "+e.current_version))}),a.appendChild(p)}var l=i("div","android-update-notice-actions"),h=i("a","","Открыть RuStore");if(h.href=t.release.rustore_url,h.target="_blank",h.rel="noopener noreferrer",l.appendChild(h),!t.critical){var f=i("button","","Через 7 дней");f.type="button",f.addEventListener("click",function(){r(t,"snooze",a)}),l.appendChild(f)}a.appendChild(l),e.appendChild(a),e.hidden=!1,d(a)}(e,t)}),o(t))}).catch(function(){})}"loading"===t.readyState?t.addEventListener("DOMContentLoaded",s,{once:!0}):s(),t.addEventListener("htmx:afterSwap",function(){e.EasyChatAndroidUpdateSnapshot&&o(e.EasyChatAndroidUpdateSnapshot)})}(window,document);