import{q as a,n as t}from"./vendor-react-DfNOgXDS.js";import{c6 as v,bS as y,r as u,c3 as j,o as N}from"./index-CRANE7wv.js";import"./vendor-dayjs-BrZ9gQN4.js";import{D as _}from"./download-By2tPPRM.js";import{Z as S}from"./zap-DLo9YKtg.js";import"./vendor-query-CutdBoCI.js";import"./vendor-antd-core-R0BvUBa1.js";import"./vendor-i18n-BWzZRYJm.js";import"./vendor-sentry-BlaL7Aw0.js";/**
* @license lucide-react v1.16.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const k=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],D=v("smartphone",k),p="pwa_install_dismissed_until",x="pwa_visit_count",E=30,h=3e4;function I(){var e;return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)||window.navigator.standalone===!0}function C(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)&&!/Mac/i.test(navigator.vendor)}function P(){const e=localStorage.getItem(p);return!!e&&Number(e)>Date.now()}function m(){localStorage.setItem(p,String(Date.now()+E*864e5))}function T(){const e=Number(sessionStorage.getItem(x)??"0")+1;return sessionStorage.setItem(x,String(e)),e}function c(e,n){const r=window.posthog;try{r==null||r.capture(e,n??{})}catch{}}const A=[{icon:t.jsx(S,{className:"w-4 h-4 text-yellow-500"}),text:"Быстрый запуск с экрана"},{icon:t.jsx(N,{className:"w-4 h-4 text-blue-500"}),text:"Push-уведомления о грузе"},{icon:t.jsx(D,{className:"w-4 h-4 text-indigo-500"}),text:"Работает без браузера"}];function U(){const[e,n]=a.useState(null),[r,i]=a.useState(!1),[g,f]=a.useState(!1);a.useEffect(()=>{if(I()||P())return;const s=T(),o=l=>{if(l.preventDefault(),n(l),s>=2){const b=setTimeout(()=>{i(!0),c("pwa_install_prompt_shown",{mode:"native",visit:s})},h);return()=>clearTimeout(b)}};if(window.addEventListener("beforeinstallprompt",o),C()&&s>=2){f(!0);const l=setTimeout(()=>{i(!0),c("pwa_install_prompt_shown",{mode:"ios",visit:s})},h);return()=>{window.removeEventListener("beforeinstallprompt",o),clearTimeout(l)}}return()=>window.removeEventListener("beforeinstallprompt",o)},[]);const w=a.useCallback(async()=>{if(e){try{await e.prompt();const s=await e.userChoice;c("pwa_install_choice",{outcome:s.outcome}),s.outcome==="dismissed"&&m()}catch{m()}i(!1),n(null)}},[e]),d=a.useCallback(()=>{m(),i(!1),c("pwa_install_dismissed")},[]);return r?t.jsxs("div",{className:j("fixed bottom-4 left-4 right-4 z-[9990] max-w-sm mx-auto","rounded-2xl bg-white dark:bg-gray-900 shadow-2xl border border-gray-100 dark:border-gray-700","p-5 animate-in slide-in-from-bottom-4 duration-300"),role:"dialog","aria-label":"Установить приложение",children:[t.jsx("button",{onClick:d,className:"absolute top-3 right-3 p-1 rounded-full text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors","aria-label":"Закрыть",children:t.jsx(y,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-blue-600 flex items-center justify-center flex-shrink-0",children:t.jsx("img",{src:"/favicon.svg",alt:"Avalog",className:"w-8 h-8",onError:s=>{s.target.style.display="none"}})}),t.jsxs("div",{children:[t.jsx("p",{className:"font-bold text-gray-900 dark:text-white text-sm",children:"Avalog"}),t.jsx("p",{className:"text-xs text-gray-500",children:"Установить как приложение"})]})]}),t.jsx("ul",{className:"space-y-2 mb-4",children:A.map((s,o)=>t.jsxs("li",{className:"flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300",children:[s.icon,s.text]},o))}),g?t.jsxs("div",{className:"rounded-xl bg-gray-50 dark:bg-gray-800 p-3 text-xs text-gray-600 dark:text-gray-300 leading-relaxed",children:["Нажмите ",t.jsx("strong",{children:"↗ Поделиться"})," в Safari →"," ",t.jsx("strong",{children:'«На экран "Домой"»'})]}):t.jsxs("div",{className:"flex gap-2",children:[t.jsxs(u,{className:"flex-1 gap-2",onClick:w,children:[t.jsx(_,{className:"w-4 h-4"}),"Установить"]}),t.jsx(u,{variant:"ghost",onClick:d,className:"flex-shrink-0",children:"Не сейчас"})]})]}):null}export{U as PwaInstallPromptDS};