1import{B as e,C as t,D as n,F as r,I as i,L as a,O as o,Q as s,R as c,T as l,U as u,X as d,Y as f,Z as p,d as m,j as h,q as g,z as _}from"./index-WjbVjHVB.js";var v=u(`<div style=display:flex>`),y=u(`<div class=peach-lock-view-header><button class=peach-lock-restore-link>‹ back`),b=u(`<div class=peach-settings-group><div class=peach-restore-warning>Restoring now replaces the locked local vault on this device with a fresh one from your backup or export file.`),x=u(`<div class="peach-settings-body peach-export-menu"><div class="peach-settings-group peach-export-card peach-export-card--primary"><p class=peach-settings-label>peachscript</p><p class=peach-export-card-copy>Paste a PeachScript backup from another Peach device.</p><button class="peach-btn peach-btn--subtle peach-btn--sm">Paste PeachScript →</button></div><div class="peach-settings-group peach-export-card"><p class=peach-settings-label>backup file</p><p class=peach-export-card-copy>A Peach JSON export, or a file from Bitwarden, Proton Pass, 1Password, or a browser CSV (Chrome, Safari, Edge).</p><button class="peach-btn peach-btn--subtle peach-btn--sm">Choose file →`),S=u(`<div class=peach-settings-group><div class=peach-restore-warning>Restoring now replaces the locked local vault on this device with a fresh one from your backup.`),C=u(`<p class=peach-settings-label style=margin-top:4px>new master password`),w=u(`<p class=peach-export-card-copy>This password unlocks Peach on this device after the restore.`),T=u(`<p class=peach-export-note style=color:var(--peach-t2)>Passwords don't match`),E=u(`<div class="peach-settings-stack peach-export-password-stack"><input class=peach-settings-input type=password placeholder="master password (min 8 chars)"><input class=peach-settings-input type=password placeholder="confirm master password">`),D=u(`<div class=peach-restore-error>`),O=u(`<div class=peach-export-success><span class=peach-export-success-check>✓</span><span>Restored <!> entr<!>.`),k=u(`<div class=peach-settings-body><div class="peach-settings-group peach-export-card peach-export-card--primary peach-export-pass-group"><p class=peach-settings-label>paste peachscript</p><p class=peach-export-card-copy></p><textarea class=peach-script-input placeholder="paste PeachScript here…"></textarea><label class="peach-btn peach-btn--ghost peach-btn--sm"style=display:inline-flex;align-items:center;justify-content:center;cursor:pointer>Load .peach file<input type=file accept=.peach,application/x-peach,text/plain style=display:none></label><div class="peach-settings-stack peach-export-password-stack"><input class=peach-settings-input type=password placeholder="PeachScript password"></div><button class="peach-btn peach-btn--subtle peach-btn--sm">`),A=u(`<div class=peach-settings-group><p class=peach-settings-label>unlock backup</p><p class=peach-export-card-copy>Enter the password used when you created this encrypted Peach JSON backup.</p><input class=peach-restore-input type=password placeholder="backup password"><div class=peach-settings-actions><button class="peach-btn peach-btn--subtle peach-btn--sm">Decrypt →`),j=u(`<div class=peach-import-preview-more>...and <!> more`),M=u(`<div class=peach-settings-group><p class=peach-settings-label></p><div class=peach-import-summary>Found <strong></strong> entr</div><div class=peach-import-preview>`),N=u(`<div class=peach-restore-warning style=margin-top:6px>Replace forever? This cannot be undone.`),P=u(`<div class=peach-settings-group><p class=peach-settings-label>merge or replace</p><label class=peach-import-choice><input type=radio name=merge-mode value=add><span class=peach-import-choice-main><span class=peach-import-choice-label>Add to existing vault</span><span class=peach-import-choice-sub>This will add <!> entries to your existing <!>.</span></span></label><label class=peach-import-choice><input type=radio name=merge-mode value=replace><span class=peach-import-choice-main><span class=peach-import-choice-label>Replace vault</span><span class=peach-import-choice-sub>This will replace your <!> entries with <!> imported ones.`),F=u(`<div class=peach-settings-group><p class=peach-settings-label>new master password</p><p class=peach-export-card-copy>This password unlocks the Peach vault created on this device after import.</p><div class=peach-auth-grid><input class=peach-restore-input type=password placeholder="new master password"><input class=peach-restore-input type=password placeholder="confirm master password">`),I=u(`<div class=peach-settings-group><div class=peach-restore-error>`),L=u(`<div class=peach-settings-group><div class=peach-import-summary>Importing... [<!> / <!>]`),R=u(`<div class=peach-settings-group><div class=peach-export-card-copy> <!> to be duplicates of existing ones. They were still imported — you can review and delete them in your vault.`),z=u(`<div class=peach-settings-group><div class=peach-settings-actions><button class="peach-btn peach-btn--subtle peach-btn--sm">`),B=u(`<div class=peach-settings-body><div class="peach-settings-group peach-export-card peach-export-card--primary"><p class=peach-settings-label>choose a file</p><p class=peach-export-card-copy>Bitwarden, 1Password, Proton Pass, Chrome / Edge / Safari CSV, FIDO credential-exchange passkeys, or a Peach JSON backup.</p><div class=peach-provider-chips><span class=peach-provider-chip>Peach JSON</span><span class=peach-provider-chip>FIDO passkeys</span><span class=peach-provider-chip>Proton Pass</span><span class=peach-provider-chip>Bitwarden</span><span class=peach-provider-chip>1Password</span><span class=peach-provider-chip>Browser CSV</span></div><input class=peach-restore-file type=file accept=.csv,.json,.peach,application/x-peach>`),ee=u(`<div class=peach-import-preview-row><span class=peach-import-preview-title></span><span class=peach-import-preview-meta>`),V=u(`<div class=peach-overlay-header><button class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"aria-label=Back><svg width=7 height=12 viewBox="0 0 7 12"fill=none stroke=currentColor stroke-width=1.1 stroke-linecap=round stroke-linejoin=round><path d="M6 1L1 6L6 11"></path></svg></button><span class=peach-overlay-title></span><div class=peach-overlay-spacer>`);function H(e){let[t,n]=s(e.initialView??`menu`),[r,i]=s(``),o=()=>e.mode??`existing`,c=()=>o()===`onboarding`,l=()=>e.initialView?e.onBack():n(`menu`);return(()=>{var s=v();return _(s,f(g,{get when(){return t()===`menu`},get children(){return f(U,{get mode(){return o()},get replacesExistingVault(){return e.replacesExistingVault},get onBack(){return e.onBack},onPick:e=>n(e)})}}),null),_(s,f(g,{get when(){return t()===`peachscript`},get children(){return f(W,{get mode(){return o()},get replacesExistingVault(){return e.replacesExistingVault},get initialScript(){return r()},onBack:()=>{i(``),l()},get onImport(){return e.onImport}})}}),null),_(s,f(g,{get when(){return t()===`file`},get children(){return f(G,{get mode(){return o()},get replacesExistingVault(){return e.replacesExistingVault},onBack:l,get onImport(){return e.onImport},onLoadPeachFile:e=>{i(e),n(`peachscript`)}})}}),null),p(()=>a(s,c()?`peach-lock-view`:`peach-overlay-view ov-enter-right`)),s})()}function U(e){let t=e.mode===`onboarding`;return[f(g,{when:t,get fallback(){return f(K,{title:`import`,get onBack(){return e.onBack}})},get children(){var t=y(),n=t.firstChild;return _(t,f(h,{class:`peach-wordmark-wrap`}),n),i(n,`click`,e.onBack,!0),t}}),(()=>{var n=x(),r=n.firstChild,i=r.firstChild.nextSibling;i.firstChild;var a=i.nextSibling,o=r.nextSibling.firstChild.nextSibling.nextSibling;return _(n,f(g,{get when(){return t&&e.replacesExistingVault},get children(){return b()}}),r),_(i,()=>e.mode===`existing`?` We'll merge it into your vault.`:``,null),a.$$click=()=>e.onPick(`peachscript`),o.$$click=()=>e.onPick(`file`),n})()]}function W(i){let[a,c]=s(i.initialScript??``),[u,m]=s(``),[h,v]=s(``),[y,b]=s(``),[x,A]=s(!1),[j,M]=s(null),[N,P]=s(null),F=d(()=>n(a())),I=i.mode===`onboarding`,L=d(()=>h().length>=8&&h()===y());async function R(){if(M(null),P(null),!F()){M(`Paste your PeachScript first.`);return}if(!u().trim()){M(`Enter the backup password.`);return}A(!0);try{let e=await t(l(o(a())),u());if(I){if(!L())throw Error(`MASTER_PASSWORD_REQUIRED`);if(!(await r({type:`CREATE_VAULT`,payload:{password:h()}})).ok)throw Error(`CREATE_VAULT_FAILED`)}let n=await r({type:`RESTORE_ENTRIES`,payload:{entries:e.entries,mode:`merge`,settings:e.settings}});if(!n.ok)throw Error(n.error??`RESTORE_FAILED`);e.license?.key&&await r({type:`ACTIVATE_LICENSE`,payload:{key:e.license.key}}).catch(()=>{}),P({entryCount:e.entries.length}),await i.onImport()}catch(e){M(J(e instanceof Error?e.message:String(e)))}finally{A(!1)}}return[f(q,{title:`peachscript`,get onBack(){return i.onBack},get mode(){return i.mode}}),(()=>{var t=k(),n=t.firstChild,r=n.firstChild.nextSibling,o=r.nextSibling,s=o.nextSibling,l=s.firstChild.nextSibling,d=s.nextSibling,A=d.firstChild,P=d.nextSibling;return _(t,f(g,{get when(){return I&&i.replacesExistingVault},get children(){return S()}}),n),_(r,I?`Paste a PeachScript backup from another Peach device to restore your vault — or load a .peach file from disk.`:`We'll merge the entries into your existing vault. You can paste PeachScript or load a .peach file.`),o.$$input=e=>c(e.target.value),l.addEventListener(`change`,async e=>{let t=e.currentTarget,n=t.files?.[0];if(n)try{c(await n.text())}catch(e){M(e instanceof Error?e.message:`Couldn't read file.`)}finally{t.value=``}}),A.$$input=e=>m(e.target.value),_(n,f(g,{when:I,get children(){return[C(),w(),(()=>{var t=E(),n=t.firstChild,r=n.nextSibling;return n.$$input=e=>v(e.target.value),r.$$input=e=>b(e.target.value),_(t,f(g,{get when(){return e(()=>y().length>0)()&&h()!==y()},get children(){return T()}}),null),p(()=>n.value=h()),p(()=>r.value=y()),t})()]}}),P),P.$$click=()=>void R(),_(P,()=>x()?`decoding…`:`Restore from PeachScript`),_(n,f(g,{get when(){return j()},get children(){var e=D();return _(e,j),e}}),null),_(n,f(g,{get when(){return N()},get children(){var e=O(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling,r=n.nextSibling.nextSibling;return r.nextSibling,_(t,()=>N().entryCount,n),_(t,()=>N().entryCount===1?`y`:`ies`,r),e}}),null),p(()=>P.disabled=x()||!F()||!u().trim()||I&&!L()),p(()=>o.value=a()),p(()=>A.value=u()),t})()]}function G(t){let i=t.mode===`onboarding`,a=()=>i,[o,c]=s(null),[l,u]=s(null),[h,v]=s(``),[y,b]=s(``),[x,C]=s(``),[w,T]=s(!1),[E,D]=s(null),[O,k]=s(`add`),[V,H]=s(!1),[U,W]=s(null),[G,K]=s(0),[Y,te]=s(0),X=d(()=>o()?.requiresPassword??!1),Z=d(()=>y().length>=8&&y()===x());async function ne(){i||te(((await r({type:`GET_ENTRIES`})).data??[]).length)}ne();async function Q(e,t){try{let n=await m(e,t);return c(n),D(null),n.format===`unknown`&&D(`We couldn't recognise this file format. Peach supports: Peach JSON backups, Bitwarden JSON/CSV, Proton Pass JSON/CSV, 1Password JSON, and generic browser CSV exports.`),n}catch(e){let t=e instanceof Error?e.message:String(e);return c(null),D(J(t)),null}}async function re(e){let r=e.target,i=r.files?.[0];if(!i)return;c(null),u(null),v(``),D(null),H(!1);let a=await i.text();if(i.name.toLowerCase().endsWith(`.peach`)||n(a)){if(t.onLoadPeachFile){t.onLoadPeachFile(a),r.value=``;return}D(`This is a .peach file. Open the PeachScript card to import it.`);return}u(a),await Q(a)}async function $(){let e=l();!e||!h().trim()||await Q(e,h())}async function ie(e){if(e.length===0)return 0;let t=((await r({type:`GET_ENTRIES`})).data??[]).filter(e=>!e.deletedAt),n=(e,t,n)=>`${(e??``).toLowerCase()}|${(t??``).toLowerCase()}|${(n??``).toLowerCase()}`,i=new Set(t.map(e=>n(e.title,e.url,e.username))),a=0;for(let t of e){let e=`username`in t?t.username:void 0,r=`url`in t?t.url:void 0;i.has(n(t.title,r,e))&&(a+=1)}return a}async function ae(){let e=o();if(e){if(X()&&!h().trim()){D(`Enter the backup password used for this export.`);return}if(a()){if(y().length<8){D(`Master password must be at least 8 characters.`);return}if(!Z()){D(`Master passwords do not match.`);return}}if(!i&&O()===`replace`&&!V()){H(!0);return}T(!0),D(null),K(0),W(null);try{if(e.entries.length===0)throw Error(`NO_ENTRIES_IMPORTED`);if(a()&&!(await r({type:`CREATE_VAULT`,payload:{password:y()}})).ok)throw Error(`CREATE_VAULT_FAILED`);if(!i&&O()===`replace`&&!(await r({type:`CLEAR_VAULT_ENTRIES`})).ok)throw Error(`CLEAR_VAULT_FAILED`);let n=0;!i&&O()===`add`&&(n=await ie(e.entries));let o=0;W({current:0,total:e.entries.length});let s=await r({type:`BATCH_ADD_ENTRIES`,payload:{entries:e.entries}});if(s.ok)o=(s.data??[]).length,W({current:o,total:e.entries.length});else for(let t of e.entries)(await r({type:`ADD_ENTRY`,payload:t})).ok&&(o+=1),W({current:o,total:e.entries.length});if(o===0)throw Error(`NO_ENTRIES_IMPORTED`);e.licenseKey&&await r({type:`ACTIVATE_LICENSE`,payload:{key:e.licenseKey}}).catch(()=>{}),K(n),await t.onImport()}catch(e){D(J(e instanceof Error?e.message:String(e))),T(!1),W(null);return}T(!1),W(null)}}return[f(q,{title:`backup file`,get onBack(){return t.onBack},get mode(){return t.mode}}),(()=>{var n=B(),r=n.firstChild,s=r.firstChild.nextSibling.nextSibling.nextSibling;return _(n,f(g,{get when(){return i&&t.replacesExistingVault},get children(){return S()}}),r),s.addEventListener(`change`,e=>void re(e)),_(n,f(g,{get when(){return X()},get children(){var e=A(),t=e.firstChild.nextSibling.nextSibling,n=t.nextSibling.firstChild;return t.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),$())},t.addEventListener(`blur`,()=>{h().trim()&&$()}),t.$$input=e=>v(e.target.value),n.$$click=()=>void $(),p(()=>n.disabled=!h().trim()),p(()=>t.value=h()),e}}),null),_(n,f(g,{get when(){return e(()=>!!(o()&&!X()))()&&o().format!==`unknown`},get children(){var t=M(),n=t.firstChild,r=n.nextSibling,i=r.firstChild.nextSibling;i.nextSibling;var a=r.nextSibling;return _(n,()=>o().label),_(i,()=>o().entries.length),_(r,()=>o().entries.length===1?`y`:`ies`,null),_(r,(()=>{var t=e(()=>o().skippedItems>0);return()=>t()?`. ${o().skippedItems} skipped because no password was present.`:`.`})(),null),_(a,()=>o().entries.slice(0,8).map(t=>(()=>{var n=ee(),r=n.firstChild,i=r.nextSibling;return _(r,()=>t.title),_(i,(()=>{var n=e(()=>!!t.passkey);return()=>n()?`${t.passkey.userName} • ${t.passkey.rpId} (passkey)`:e(()=>t.type===`note`)()?`secure note`:t.username||t.url||`password item`})()),n})()),null),_(a,f(g,{get when(){return o().entries.length>8},get children(){var e=j(),t=e.firstChild.nextSibling;return t.nextSibling,_(e,()=>o().entries.length-8,t),e}}),null),t}}),null),_(n,f(g,{get when(){return e(()=>!!(!i&&o()&&!X()&&o().format!==`unknown`))()&&o().entries.length>0},get children(){var e=P(),t=e.firstChild.nextSibling,n=t.firstChild,r=n.nextSibling.firstChild.nextSibling,i=r.firstChild.nextSibling,a=i.nextSibling.nextSibling;a.nextSibling;var s=t.nextSibling.firstChild,c=s.nextSibling.firstChild.nextSibling,l=c.firstChild.nextSibling,u=l.nextSibling.nextSibling;return u.nextSibling,n.addEventListener(`change`,()=>{k(`add`),H(!1)}),_(r,()=>o().entries.length,i),_(r,Y,a),s.addEventListener(`change`,()=>k(`replace`)),_(c,Y,l),_(c,()=>o().entries.length,u),_(e,f(g,{get when(){return V()},get children(){return N()}}),null),p(()=>n.checked=O()===`add`),p(()=>s.checked=O()===`replace`),e}}),null),_(n,f(g,{get when(){return e(()=>!!(a()&&o()&&!X()))()&&o().format!==`unknown`},get children(){var e=F(),t=e.firstChild.nextSibling.nextSibling.firstChild,n=t.nextSibling;return t.$$input=e=>b(e.target.value),n.$$input=e=>C(e.target.value),p(()=>t.value=y()),p(()=>n.value=x()),e}}),null),_(n,f(g,{get when(){return E()},get children(){var e=I(),t=e.firstChild;return _(t,E),e}}),null),_(n,f(g,{get when(){return e(()=>!!w())()&&U()},get children(){var e=L(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling.nextSibling;return r.nextSibling,_(t,()=>U().current,n),_(t,()=>U().total,r),e}}),null),_(n,f(g,{get when(){return e(()=>G()>0)()&&!w()},get children(){var e=R(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,_(t,G,n),_(t,()=>G()===1?`entry appears`:`entries appear`,r),e}}),null),_(n,f(g,{get when(){return e(()=>!!(o()&&!X()))()&&o().format!==`unknown`},get children(){var t=z(),n=t.firstChild.firstChild;return n.$$click=()=>void ae(),_(n,(()=>{var t=e(()=>!!w());return()=>t()?`importing...`:i?`Create vault + import ${o().entries.length}`:O()===`replace`?V()?`Yes, replace forever`:`Replace vault with ${o().entries.length}`:`Import ${o().entries.length}`})()),p(()=>n.disabled=w()||o().entries.length===0||a()&&!Z()),t}}),null),n})()]}function K(e){return(()=>{var t=V(),n=t.firstChild,r=n.nextSibling;return i(n,`click`,e.onBack,!0),_(r,()=>e.title),t})()}function q(e){return f(g,{get when(){return e.mode===`onboarding`},get fallback(){return f(K,{get title(){return e.title},get onBack(){return e.onBack}})},get children(){var t=y(),n=t.firstChild;return _(t,f(h,{class:`peach-wordmark-wrap`}),n),i(n,`click`,e.onBack,!0),t}})}function J(e){switch(e){case`UNSUPPORTED_IMPORT_FORMAT`:return`Unrecognised file format. Use CSV, Bitwarden JSON, Proton Pass JSON/CSV, or a Peach encrypted backup.`;case`INVALID_EXPORT_PASSWORD`:case`INVALID_PASSPHRASE`:return`Wrong backup password. This is the password you chose when you created the backup.`;case`INVALID_PEACH_EXPORT`:return`This Peach backup file looks corrupted or incomplete.`;case`INVALID_PEACHSCRIPT_CHARACTER`:return`This doesn't look like PeachScript. Make sure you copied the entire backup string.`;case`PAYLOAD_TOO_SHORT`:return`PeachScript looks truncated. Copy the full backup string and try again.`;case`BAD_MAGIC`:case`UNSUPPORTED_VERSION`:return`This PeachScript was created by a different version of Peach.`;case`CHECKSUM_FAILED`:return`PeachScript appears corrupted. Re-copy from the source device.`;case`CREATE_VAULT_FAILED`:return`Peach couldn't create a new local vault before importing.`;case`CLEAR_VAULT_FAILED`:return`Peach couldn't clear the existing vault before replacing it.`;case`MASTER_PASSWORD_REQUIRED`:return`Choose a master password for your new vault first.`;case`RESTORE_FAILED`:return`Restore failed. Your existing vault is unchanged.`;case`vault locked`:return`Peach is locked. Open Peach with your master password and try again.`;case`refuse to replace with empty entry set`:return`This PeachScript decoded to zero entries — refusing to wipe the vault.`;case`NO_ENTRIES_IMPORTED`:return`No importable password entries were found in that file.`;default:return e}}c([`click`,`input`,`keydown`]);export{H as ImportView};