import{C as e,D as t,E as n,F as r,H as i,N as a,Q as o,S as s,T as c,Y as l,_ as u,a as d,b as f,et as p,q as m,x as h}from"./app-vGYB2KPL.js";import{t as g}from"./i18n-7F7mITXO.js";import{t as _}from"./PrimaryButton-zDFIhHEO.js";import{a as v,i as y,r as b,t as x}from"./push-Cl6j2SWS.js";import{t as S}from"./SecondaryButton-C1X7eRtc.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=t({__name:`PushToggle`,setup(t){let p=d(),j=()=>p.props.pushKey??``,M=m(!1),N=m(!1),P=m(!1),F=m(``);a(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=m(!1),z=m(``);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(t,a)=>(r(),e(`section`,null,[f(`header`,null,[f(`h2`,C,o(l(g)(`Push notifications`)),1),f(`p`,w,o(l(g)(`Get browser notifications for replies, mentions and reactions — even when {app} isn't open.`,{app:`Convoro`})),1)]),f(`div`,T,[M.value?(r(),e(u,{key:1},[N.value?(r(),h(S,{key:1,disabled:P.value,onClick:L},{default:i(()=>[c(o(P.value?l(g)(`Disabling…`):l(g)(`Disable push notifications`)),1)]),_:1},8,[`disabled`])):(r(),h(_,{key:0,disabled:P.value,onClick:I},{default:i(()=>[c(o(P.value?l(g)(`Enabling…`):l(g)(`Enable push notifications`)),1)]),_:1},8,[`disabled`])),N.value?(r(),e(`p`,D,o(l(g)(`Push is enabled on this device.`)),1)):s(``,!0),F.value?(r(),e(`p`,O,o(F.value),1)):s(``,!0),N.value?(r(),e(`div`,k,[n(S,{disabled:R.value,onClick:B},{default:i(()=>[c(o(R.value?l(g)(`Sending…`):l(g)(`Send a test notification`)),1)]),_:1},8,[`disabled`]),z.value?(r(),e(`p`,A,o(z.value),1)):s(``,!0)])):s(``,!0)],64)):(r(),e(`p`,E,o(l(g)(`Push isn't available in this browser (or the site isn't served over HTTPS).`)),1))])]))}}),M=p({default:()=>N}),N=j;export{M as n,N as t};