import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{i as n,o as r,r as i,t as a}from"./jsx-runtime-DHSfUA5-.js";import{P as o,R as s,r as c}from"./test.id-DxQrYxPk.js";import{n as l}from"./fileAssetService-gA4Q8V3n.js";import{t as u}from"./use-watch-event-Bmff5Oxc.js";import{t as d}from"./navigationService-BNBSAd9W.js";import{n as f}from"./appLockService-D-ij0gvy.js";import{t as p}from"./useSuccessToast-CW8oLO3e.js";import{t as m}from"./HeaderPage-CPQpvQQw.js";import{n as h}from"./useMembershipStatus-CuwuZX56.js";import{t as g}from"./useDialog-CjsjDZgz.js";var _=e(r(),1),v=a();function y(){let e=o(s),r=o(l),a=o(f),y=o(d),b=g(),x=p();u(a.onDidChange);let{status:S,data:C,isLoading:w}=h(),T=w||!C,[E,D]=(0,_.useState)();(0,_.useEffect)(()=>{let t=!1;return e.canUseDeviceAuth().then(e=>{t||D(e)}),()=>{t=!0}},[e]);let[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(),[P,F]=(0,_.useState)(!1),I=a.enabled,L=r.getSyncConfig(),R=!!(L?.recoveryKeyHash?.trim()||L?.recoveryKey?.trim()),z=()=>{k(!1),j(``),N(void 0)},B=e=>{if(e!==I){if(!e){b({title:t(`appLock.title`,`Authentication`),message:t(`appLock.disableConfirm`,`Turn off authentication?`),confirmLabel:t(`appLock.disableAction`,`Turn off`),cancelLabel:t(`common.cancel`,`Cancel`),rootTestId:c.disableDialog,confirmTestId:c.disableConfirm,onConfirm:()=>void a.disable()});return}if(!R){b({title:t(`appLock.title`,`Authentication`),message:t(`appLock.needSync`,`Authentication verifies your database encryption password. Set up cloud sync first.`),confirmLabel:t(`appLock.goSync`,`Set up cloud sync`),cancelLabel:t(`common.cancel`,`Cancel`),tone:`primary`,rootTestId:c.noSyncDialog,onConfirm:()=>y.navigate({path:`/settings/s3`})});return}if(!T){if(!S.active){b({title:t(`appLock.title`,`Authentication`),message:t(`appLock.memberOnly`,`Authentication is a membership feature. Get a membership to enable it.`),confirmLabel:t(`appLock.goPurchase`,`Get membership`),cancelLabel:t(`common.cancel`,`Cancel`),tone:`primary`,rootTestId:c.memberOnlyDialog,onConfirm:()=>y.navigate({path:`/settings/membership`})});return}k(!0)}}},V=async()=>{if(P)return;F(!0);let e=await a.enable(A).finally(()=>F(!1));if(e.ok){z(),x({message:t(`appLock.enabled`,`Authentication is on`)});return}N(e.error===`no-recovery-key`?t(`appLock.enable.noSync`,`Cloud sync is not set up.`):t(`appLock.enable.wrongKey`,`Incorrect password. Try again.`))};return(0,v.jsxs)(m,{pageTestId:c.page,contentTestId:c.content,header:{title:t(`appLock.title`,`Authentication`),showBack:!0},children:[(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`label`,{className:i(n.Cell.InsetGroup,n.AppLockPage.SwitchRow),children:[(0,v.jsx)(`span`,{className:n.AppLockPage.SwitchLabel,children:t(`appLock.switchLabel`,`Require authentication`)}),(0,v.jsx)(`input`,{type:`checkbox`,className:n.Choice.Input,"data-test-id":c.switch,checked:I,disabled:!I&&!E,onChange:e=>B(e.target.checked)})]}),(0,v.jsx)(`p`,{className:n.AppLockPage.GroupDesc,children:t(`appLock.desc`,`When enabled, returning to the app requires fingerprint, face, or device passcode verification. Your database encryption password also unlocks the app. Membership is required.`)}),E===!1&&(0,v.jsx)(`p`,{className:n.AppLockPage.WarnDesc,"data-test-id":c.unsupportedHint,children:t(`appLock.unsupported`,`System authentication is unavailable. Set up a screen lock or biometrics on this device first.`)})]}),O&&!I&&(0,v.jsxs)(`div`,{className:n.Common.SectionGap,"data-test-id":c.enableCard,children:[(0,v.jsxs)(`div`,{className:n.Cell.InsetGroup,children:[(0,v.jsx)(`div`,{className:n.Field.InputRow,children:(0,v.jsx)(`input`,{type:`password`,className:n.Field.BareInput,"data-test-id":c.keyInput,placeholder:t(`appLock.keyPlaceholder`,`Database encryption password`),value:A,onChange:e=>{j(e.target.value),N(void 0)}})}),M&&(0,v.jsx)(`p`,{className:n.AppLockPage.InputError,"data-test-id":c.keyError,children:M})]}),(0,v.jsx)(`p`,{className:n.AppLockPage.WarnDesc,children:t(`appLock.enable.warning`,`Verify your database encryption password to turn this on. Keep the password safe: if it is lost, data synced to the cloud cannot be recovered.`)}),(0,v.jsxs)(`div`,{className:n.AppLockPage.Actions,children:[(0,v.jsx)(`button`,{type:`button`,className:n.WeuiButton.Primary,"data-test-id":c.confirmEnable,disabled:P||A.trim().length===0,onClick:()=>void V(),children:t(`appLock.enable.confirm`,`Verify and turn on`)}),(0,v.jsx)(`button`,{type:`button`,className:n.WeuiButton.Default,"data-test-id":c.cancelEnable,onClick:z,children:t(`common.cancel`,`Cancel`)})]})]})]})}export{y as SettingsAuthenticationPage};
//# sourceMappingURL=authentication-DM3X3YfC.js.map