import{n as e}from"./chunk-QTnfLwEv.js";import{C as t,D as n,E as r,F as i,L as a,S as o,W as s,Y as c,Z as l,et as u,k as d,o as f,v as p,w as m,x as h}from"./app-glTSJfQ8.js";import{t as g}from"./i18n-B0fQ-YqU.js";import{t as _}from"./PrimaryButton-Br9vr24z.js";import{a as v,i as y,r as b,t as x}from"./push-Cl6j2SWS.js";import{t as S}from"./SecondaryButton-BhHMqmcJ.js";var C={class:`text-lg font-medium text-gray-900 dark:text-gray-100`},w={class:`mt-1 text-sm text-gray-600 dark:text-gray-400`},T={class:`mt-6`},E={key:0,class:`text-sm text-gray-500 dark:text-gray-400`},D={key:2,class:`mt-2 text-sm text-green-600 dark:text-green-400`},O={key:3,class:`mt-2 text-sm text-red-600 dark:text-red-400`},k={key:4,class:`mt-4`},A={key:0,class:`mt-2 text-sm text-ink-2`},j=d({__name:`PushToggle`,setup(e){let d=f(),j=()=>d.props.pushKey??``,M=c(!1),N=c(!1),P=c(!1),F=c(``);i(async()=>{M.value=b()&&!!j(),M.value&&(N.value=!!await x())});async function I(){F.value=``,P.value=!0;try{await y(j())?N.value=!0:F.value=g(`Permission was denied or push is unavailable.`)}catch(e){F.value=e?.message??g(`Could not enable push.`)}finally{P.value=!1}}async function L(){P.value=!0;try{await v(),N.value=!1}catch(e){F.value=e?.message??g(`Could not disable push.`)}finally{P.value=!1}}let R=c(!1),z=c(``);async function B(){R.value=!0,z.value=``;try{let e=decodeURIComponent((document.cookie.match(/XSRF-TOKEN=([^;]+)/)||[])[1]||``);z.value=(await fetch(`/push/test`,{method:`POST`,headers:{"X-XSRF-TOKEN":e,Accept:`application/json`,"X-Requested-With":`XMLHttpRequest`}})).ok?g(`Sent! Check your device — it can take a moment.`):g(`Could not send. Make sure push is enabled on this device.`)}catch{z.value=g(`Could not send the test notification.`)}finally{R.value=!1}}return(e,i)=>(a(),m(`section`,null,[h(`header`,null,[h(`h2`,C,u(l(g)(`Push notifications`)),1),h(`p`,w,u(l(g)(`Get browser notifications for replies, mentions and reactions — even when {app} isn't open.`,{app:`Convoro`})),1)]),h(`div`,T,[M.value?(a(),m(p,{key:1},[N.value?(a(),o(S,{key:1,disabled:P.value,onClick:L},{default:s(()=>[r(u(P.value?l(g)(`Disabling…`):l(g)(`Disable push notifications`)),1)]),_:1},8,[`disabled`])):(a(),o(_,{key:0,disabled:P.value,onClick:I},{default:s(()=>[r(u(P.value?l(g)(`Enabling…`):l(g)(`Enable push notifications`)),1)]),_:1},8,[`disabled`])),N.value?(a(),m(`p`,D,u(l(g)(`Push is enabled on this device.`)),1)):t(``,!0),F.value?(a(),m(`p`,O,u(F.value),1)):t(``,!0),N.value?(a(),m(`div`,k,[n(S,{disabled:R.value,onClick:B},{default:s(()=>[r(u(R.value?l(g)(`Sending…`):l(g)(`Send a test notification`)),1)]),_:1},8,[`disabled`]),z.value?(a(),m(`p`,A,u(z.value),1)):t(``,!0)])):t(``,!0)],64)):(a(),m(`p`,E,u(l(g)(`Push isn't available in this browser (or the site isn't served over HTTPS).`)),1))])]))}}),M=e({default:()=>N}),N=j;export{M as n,N as t};