1import{t as e}from"./peachPayload-BpK1tYQG.js";import{A as t,D as n,F as r,H as i,I as a,M as o,O as s,U as c,V as l,W as u,f as d,j as f,z as p}from"./index-BP9j8KNs.js";import{encodeMayan as m}from"./mayan-Dby7Nm8-.js";import{t as h}from"./RuneCanvas-DMj80DmI.js";var g=r(`<div class="peach-overlay-view ov-enter-right"style=display:flex>`),_=r(`<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>Your vault as a string of Peach symbols you can paste into Peach on another device. Designed for Peach-to-Peach transfer.</p><button class="peach-btn peach-btn--subtle peach-btn--sm">Create PeachScript →</button></div><div class="peach-settings-group peach-export-card"><p class=peach-settings-label>print backup</p><p class=peach-export-card-copy>Save a Mayan code you can print and store. Scan it with Peach on any device to restore.</p><button class="peach-btn peach-btn--subtle peach-btn--sm">Save Mayan code →</button></div><div class="peach-settings-group peach-export-card"><p class=peach-settings-label>CSV (leaving peach)</p><p class=peach-export-card-copy>Plain-text export for moving into another password manager. Anyone with the file can read your passwords.</p><button class="peach-btn peach-btn--ghost peach-btn--sm">Export as CSV →`),v=r(`<div class="peach-settings-group peach-export-card peach-export-card--primary peach-export-result-group"><p class=peach-settings-label>peachscript</p><p class=peach-export-card-copy style="margin:0 0 8px"> entr</p><div style=display:flex;gap:8px><button class="peach-btn peach-btn--subtle peach-btn--sm"style=flex:1></button><button class="peach-btn peach-btn--subtle peach-btn--sm"style=flex:1>Download .peach</button></div><p class=peach-export-card-copy style=margin-top:8px>Paste the script — or import the .peach file — into Peach on your other device to restore your vault. Won't work anywhere else.`),y=r(`<div class=peach-settings-group><div class=peach-restore-error>`),b=r(`<div class=peach-settings-body>`),x=r(`<p class=peach-export-note style=color:var(--peach-t2)>Passwords don't match`),S=r(`<p class=peach-export-note style=color:var(--peach-t2)>At least 8 characters`),C=r(`<div class="peach-settings-group peach-export-card peach-export-card--primary peach-export-pass-group"><p class=peach-settings-label>backup password</p><p class=peach-export-card-copy>Choose a password to lock this PeachScript. You'll need it to restore on another device.</p><div class="peach-settings-stack peach-export-password-stack"><input class=peach-settings-input type=password placeholder="backup password (min 8 chars)"><input class=peach-settings-input type=password placeholder="confirm backup password"></div><button class="peach-btn peach-btn--subtle peach-btn--sm">`),w=r(`<div class="peach-settings-group peach-export-card peach-export-card--primary"><div class=peach-qr-canvas-wrap></div><p class=peach-export-card-copy style=text-align:center> entr<!> · </p><button class="peach-btn peach-btn--subtle peach-btn--sm">Save PNG</button><p class=peach-export-card-copy style=margin-top:8px>Print this and keep it somewhere safe. Scan it with Peach to restore your vault on any device.`),T=r(`<div class="peach-settings-group peach-export-card peach-export-card--primary"><p class=peach-settings-label>backup password</p><p class=peach-export-card-copy>Set a password to lock this Mayan code backup. You'll need it to restore — without it the printed code is unreadable.</p><div class="peach-settings-stack peach-export-password-stack"><input class=peach-settings-input type=password placeholder="backup password (min 8 chars)"><input class=peach-settings-input type=password placeholder="confirm backup password"></div><button class="peach-btn peach-btn--subtle peach-btn--sm">`),E=r(`<button class="peach-btn peach-btn--ghost peach-btn--sm">I understand — continue`),D=r(`<button class="peach-btn peach-btn--subtle peach-btn--sm">`),O=r(`<div class=peach-settings-group><div class=peach-export-success><span class=peach-export-success-check>✓</span><span>`),k=r(`<div class=peach-settings-body><div class="peach-settings-group peach-export-card"><div class=peach-csv-warning>This export is unencrypted. Anyone who gets this file can read your passwords. Only use this to move to another password manager — delete it once the import is done.`),A=r(`<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>`),j=8;function M(e){let[t,n]=u(`menu`);return(()=>{var r=g();return f(r,l(p,{get when(){return t()===`menu`},get children(){return l(N,{get onBack(){return e.onBack},onPick:e=>n(e)})}}),null),f(r,l(p,{get when(){return t()===`peachscript`},get children(){return l(P,{onBack:()=>n(`menu`)})}}),null),f(r,l(p,{get when(){return t()===`qr`},get children(){return l(F,{onBack:()=>n(`menu`)})}}),null),f(r,l(p,{get when(){return t()===`csv`},get children(){return l(I,{onBack:()=>n(`menu`)})}}),null),r})()}function N(e){return[l(L,{title:`export`,get onBack(){return e.onBack}}),(()=>{var t=_(),n=t.firstChild,r=n.firstChild.nextSibling.nextSibling,i=n.nextSibling,a=i.firstChild.nextSibling.nextSibling,o=i.nextSibling.firstChild.nextSibling.nextSibling;return r.$$click=()=>e.onPick(`peachscript`),a.$$click=()=>e.onPick(`qr`),o.$$click=()=>e.onPick(`csv`),t})()]}function P(e){let[t,n]=u(``),[r,s]=u(``),[m,g]=u(!1),[_,w]=u(null),[T,E]=u(null),[D,O]=u(0),[k,A]=u({cards:0,passkeys:0,notes:0,logins:0}),[M,N]=u(!1),P=i(()=>t().length>=j&&t()===r());async function F(){if(E(null),w(null),N(!1),!P()){E(`Backup passwords don't match or are too short.`);return}g(!0);try{let e=await R(t());O(e.entryCount),A(e.stats),w(d(e.bytes))}catch(e){E(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function I(){let e=_();if(e)try{await navigator.clipboard.writeText(e),N(!0),setTimeout(()=>N(!1),2e3)}catch(e){E(e instanceof Error?e.message:`Couldn't copy to clipboard.`)}}function z(){let e=_();if(!e)return;let t=new Blob([e],{type:`application/x-peach;charset=utf-8`}),n=URL.createObjectURL(t),r=new Date().toISOString().slice(0,10),i=document.createElement(`a`);i.href=n,i.download=`peach-backup-${r}.peach`,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(n),5e3)}return[l(L,{title:`peachscript`,get onBack(){return e.onBack}}),(()=>{var e=b();return f(e,l(p,{get when(){return _()},get fallback(){return(()=>{var e=C(),i=e.firstChild.nextSibling.nextSibling,u=i.firstChild,d=u.nextSibling,h=i.nextSibling;return u.$$keydown=e=>{e.key===`Enter`&&P()&&!m()&&(e.preventDefault(),F())},u.$$input=e=>n(e.target.value),a(e=>queueMicrotask(()=>e.focus()),u),d.$$keydown=e=>{e.key===`Enter`&&P()&&!m()&&(e.preventDefault(),F())},d.$$input=e=>s(e.target.value),f(i,l(p,{get when(){return o(()=>r().length>0)()&&t()!==r()},get children(){return x()}}),null),f(i,l(p,{get when(){return o(()=>t().length>0)()&&t().length<j},get children(){return S()}}),null),h.$$click=()=>void F(),f(h,()=>m()?`encoding…`:`Generate PeachScript`),c(()=>h.disabled=m()||!P()),c(()=>u.value=t()),c(()=>d.value=r()),e})()},get children(){var e=v(),t=e.firstChild.nextSibling,n=t.firstChild,r=t.nextSibling.firstChild,i=r.nextSibling;return f(e,l(h,{get runeString(){return _()??``},width:288,height:240}),t),f(t,D,n),f(t,()=>D()===1?`y`:`ies`,null),f(t,(()=>{var e=o(()=>k().cards>0);return()=>e()?` · ${k().cards} card${k().cards===1?``:`s`}`:``})(),null),f(t,(()=>{var e=o(()=>k().passkeys>0);return()=>e()?` · ${k().passkeys} passkey${k().passkeys===1?``:`s`}`:``})(),null),f(t,(()=>{var e=o(()=>k().notes>0);return()=>e()?` · ${k().notes} note${k().notes===1?``:`s`}`:``})(),null),r.$$click=()=>void I(),f(r,()=>M()?`copied ✓`:`Copy`),i.$$click=z,e}}),null),f(e,l(p,{get when(){return T()},get children(){var e=y(),t=e.firstChild;return f(t,T),e}}),null),e})()]}function F(e){let[t,n]=u(``),[r,o]=u(``),[s,d]=u(!1),[h,g]=u(null),[_,v]=u(null),[x,S]=u(0),C,E=i(()=>t().length>=j&&t()===r());async function D(){if(v(null),g(null),!E()){v(`Backup passwords don't match or are too short.`);return}d(!0);try{let e=await R(t());if(e.bytes.length>65535){v(`This vault is too large for a Mayan code backup (${e.bytes.length} bytes). Use PeachScript instead.`);return}S(e.entryCount);let n=m(e.bytes,3),r=m(e.bytes,4);n.printable||v(`Mayan symbol is ${n.symbolSize}×${n.symbolSize} modules — too large for one A4 page. Save as PNG for digital backup.`),C&&(C.innerHTML=``,C.appendChild(n.canvas)),g(r.canvas.toDataURL(`image/png`))}catch(e){v(e instanceof Error?e.message:String(e))}finally{d(!1)}}function O(){let e=h();if(!e)return;let t=document.createElement(`a`);t.href=e,t.download=`peach-mayan-backup-${V()}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}return[l(L,{title:`print backup`,get onBack(){return e.onBack}}),(()=>{var e=b();return f(e,l(p,{get when(){return h()},get fallback(){return(()=>{var e=T(),i=e.firstChild.nextSibling.nextSibling,l=i.firstChild,u=l.nextSibling,d=i.nextSibling;return l.$$keydown=e=>{e.key===`Enter`&&E()&&!s()&&(e.preventDefault(),D())},l.$$input=e=>n(e.target.value),a(e=>queueMicrotask(()=>e.focus()),l),u.$$keydown=e=>{e.key===`Enter`&&E()&&!s()&&(e.preventDefault(),D())},u.$$input=e=>o(e.target.value),d.$$click=()=>void D(),f(d,()=>s()?`encoding…`:`Generate Mayan code`),c(()=>d.disabled=s()||!E()),c(()=>l.value=t()),c(()=>u.value=r()),e})()},get children(){var e=w(),t=e.firstChild,n=t.nextSibling,r=n.firstChild,i=r.nextSibling;i.nextSibling;var o=n.nextSibling,s=C;return typeof s==`function`?a(s,t):C=t,f(n,x,r),f(n,()=>x()===1?`y`:`ies`,i),f(n,H,null),o.$$click=O,e}}),null),f(e,l(p,{get when(){return _()},get children(){var e=y(),t=e.firstChild;return f(t,_),e}}),null),e})()]}function I(e){let[t,r]=u(!1),[i,a]=u(!1),[o,s]=u(null),[d,m]=u(null);async function h(){s(null),m(null),a(!0);try{let e=(await n({type:`GET_ENTRIES`})).data??[],t=e.filter(e=>e.deletedAt===void 0).filter(e=>!(e.passkey&&!e.password)).map(e=>e.passkey?{...e,passkey:void 0}:e),r=e.filter(e=>e.deletedAt===void 0&&e.passkey).length;if(t.length===0){s(`Your vault has no entries to export.`);return}let i=B(t),a=`peach-export-${V()}.csv`;U(i,`text/csv`,a);let o=r>0?` ${r} passkey${r===1?``:`s`} excluded — passkeys can't be represented in CSV.`:``;m(`Exported ${t.length} entr${t.length===1?`y`:`ies`} to ${a}.${o}`)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}return[l(L,{title:`export as CSV`,get onBack(){return e.onBack}}),(()=>{var e=k(),n=e.firstChild;return n.firstChild,f(n,l(p,{get when(){return!t()},get children(){var e=E();return e.$$click=()=>r(!0),e}}),null),f(n,l(p,{get when(){return t()},get children(){var e=D();return e.$$click=()=>void h(),f(e,()=>i()?`exporting…`:`Download CSV`),c(()=>e.disabled=i()),e}}),null),f(e,l(p,{get when(){return o()},get children(){var e=y(),t=e.firstChild;return f(t,o),e}}),null),f(e,l(p,{get when(){return d()},get children(){var e=O(),t=e.firstChild.firstChild.nextSibling;return f(t,d),e}}),null),e})()]}function L(e){return(()=>{var t=A(),n=t.firstChild,r=n.nextSibling;return s(n,`click`,e.onBack,!0),f(r,()=>e.title),t})()}async function R(t){let r=(await n({type:`GET_ENTRIES`})).data??[],i=(await n({type:`GET_SETTINGS`})).data??{},a;try{let e=(await n({type:`GET_LICENSE`})).data;if(e?.valid&&e.plan===`pro`){let t=(await n({type:`GET_LICENSE_KEY`})).data;t&&(a={key:t,...e.issued?{activatedAt:new Date(e.issued).getTime()}:{}})}}catch{}let o=z(r);return{bytes:await e({entries:r,settings:i,license:a,passphrase:t}),entryCount:r.length,stats:o}}function z(e){let t=0,n=0,r=0,i=0;for(let a of e)if(!a.deletedAt){if(a.passkey){n++,a.type===`login`&&a.password&&i++;continue}a.type===`card`?t++:a.type===`note`?r++:i++}return{cards:t,passkeys:n,notes:r,logins:i}}function B(e){let t=[`name`,`url`,`username`,`password`,`notes`,`type`,`tags`,`totp`],n=e.map(e=>{let t=e.type===`note`?`note`:e.type===`card`?`card`:`login`,n=e.type===`card`?e.cardholderName??``:e.username??``,r=e.type===`card`?e.cardNumber??``:e.password??``;return[e.title,e.url??``,n,r,e.notes??``,t,Array.isArray(e.tags)?e.tags.join(`|`):``,e.totp??``].map(e=>`"${String(e).replace(/\r?\n/g,` `).replace(/"/g,`""`)}"`).join(`,`)});return[t.join(`,`),...n].join(`2`)}function V(){return new Date().toISOString().split(`T`)[0]}function H(){let e=new Date;return`${[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`][e.getMonth()]} ${e.getFullYear()}`}function U(e,t,n){let r=URL.createObjectURL(new Blob([e],{type:t})),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}t([`click`,`input`,`keydown`]);export{M as ExportView};