import{q as o,n as t}from"./vendor-react-Br0ZiotI.js";import{b$ as A,cv as H,bY as b,bN as K,E as L,b_ as P,z as R}from"./index-B-EDPu3R.js";import"./vendor-dayjs-BcsA502E.js";import{D as Y}from"./download-WcmBmPFH.js";import{Z as B}from"./zap-Ca_NrEyM.js";import"./vendor-query-9i1Av1pr.js";import"./vendor-i18n-C54Hc0CQ.js";import"./vendor-antd-core-CbYNMZQB.js";import"./vendor-sentry-Cx26FE6p.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 W=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],z=A("smartphone",W),O="avalog:pwa:dismissedAt",x="avalog:pwa:visits",h="avalog:pwa:totalSeconds",p="avalog:pwa:lkVisits",T="avalog:pwa:sessionMarked",F=3,Z=120,q=5,U=2,X=3e4,$=7,G=$*864e5,J=1e4;function i(e,l=localStorage){try{const c=l.getItem(e);return c&&Number(c)||0}catch{return 0}}function w(e,l,c=localStorage){try{c.setItem(e,String(l))}catch{}}function Q(){var e;return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)||window.navigator.standalone===!0}function tt(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)&&!/Mac/i.test(navigator.vendor)}function et(){const e=i(O);return e>0&&Date.now()-e<G}function y(){w(O,Date.now())}function st(){try{if(sessionStorage.getItem(T)==="1")return i(x);sessionStorage.setItem(T,"1")}catch{}const e=i(x)+1;return w(x,e),e}function nt(){if(!window.location.pathname.startsWith("/lk"))return i(p);const e=i(p)+1;return w(p,e),e}const at=[{icon:t.jsx(B,{className:"w-4 h-4 text-yellow-500"}),text:"Быстрый запуск с экрана"},{icon:t.jsx(R,{className:"w-4 h-4 text-blue-500"}),text:"Push-уведомления о грузе"},{icon:t.jsx(z,{className:"w-4 h-4 text-indigo-500"}),text:"Работает без браузера"}];function ht(){const[e,l]=o.useState(null),[c,v]=o.useState(!1),[S,V]=o.useState(!1),d=o.useRef(null),r=H("pwa_install_prompt_v2",["a","b"]);o.useEffect(()=>{if(Q()||et())return;const n=st(),_=nt(),E=Date.now();let N=!1;const u=()=>{if(N)return;N=!0;const s=Math.round((Date.now()-E)/1e3),a=i(h)+s;w(h,a)},D=()=>{document.visibilityState==="hidden"&&u()};window.addEventListener("pagehide",u),document.addEventListener("visibilitychange",D);const m=(s,a)=>{d.current||(d.current=s,v(!0),b("pwa_install_prompt_shown",{trigger:s,mode:a,variant:r,visits:i(x),total_seconds:i(h),lk_visits:i(p)}))},j=s=>{if(r==="a")return n>=U?window.setTimeout(()=>m("visits",s),X):null;if(n>=F)return m("visits",s),null;if(_>=q)return m("lk_visits",s),null;const a=window.setInterval(()=>{const M=Math.round((Date.now()-E)/1e3);i(h)+M>=Z&&(window.clearInterval(a),m("time",s))},J);return a};let f=null,g=null;const k=s=>{s.preventDefault(),l(s);const a=j("native");a&&(r==="a"?f=a:g=a)};if(window.addEventListener("beforeinstallprompt",k),tt()){V(!0);const s=j("ios");s&&(r==="a"?f=s:g=s)}return()=>{window.removeEventListener("beforeinstallprompt",k),window.removeEventListener("pagehide",u),document.removeEventListener("visibilitychange",D),f!==null&&window.clearTimeout(f),g!==null&&window.clearInterval(g),u()}},[r]);const C=o.useCallback(async()=>{if(e){try{await e.prompt();const n=await e.userChoice;b(n.outcome==="accepted"?"pwa_install_accepted":"pwa_install_dismissed",{trigger:d.current,variant:r,source:"native"}),n.outcome==="dismissed"&&y()}catch{y()}v(!1),l(null)}},[e,r]),I=o.useCallback(()=>{y(),v(!1),b("pwa_install_dismissed",{trigger:d.current,variant:r,source:S?"ios_guide":"ui"})},[r,S]);return c?t.jsxs("div",{className:P("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:I,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(K,{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:n=>{n.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:at.map((n,_)=>t.jsxs("li",{className:"flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300",children:[n.icon,n.text]},_))}),S?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(L,{className:"flex-1 gap-2",onClick:C,children:[t.jsx(Y,{className:"w-4 h-4"}),"Установить"]}),t.jsx(L,{variant:"ghost",onClick:I,className:"flex-shrink-0",children:"Не сейчас"})]})]}):null}export{ht as PwaInstallPromptDS};