1import{B as e,E as t,F as n,I as r,Q as i,R as a,S as o,U as s,W as c,X as l,Y as u,Z as d,q as f,z as p}from"./index-BDCqaA55.js";import{encodeMayan as m}from"./mayan-BJLC4cpV.js";import{t as h}from"./RuneCanvas-DEkyDXOT.js";var g=s(`<div class="peach-overlay-view ov-enter-right"style=display:flex>`),_=s(`<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=s(`<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=s(`<div class=peach-settings-group><div class=peach-restore-error>`),b=s(`<div class=peach-settings-body>`),x=s(`<p class=peach-export-note style=color:var(--peach-t2)>Passwords don't match`),S=s(`<p class=peach-export-note style=color:var(--peach-t2)>At least 8 characters`),C=s(`<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=s(`<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=s(`<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=s(`<button class="peach-btn peach-btn--ghost peach-btn--sm">I understand — continue`),D=s(`<button class="peach-btn peach-btn--subtle peach-btn--sm">`),O=s(`<div class=peach-settings-group><div class=peach-export-success><span class=peach-export-success-check>✓</span><span>`),k=s(`<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=s(`<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]=i(`menu`);return(()=>{var r=g();return p(r,u(f,{get when(){return t()===`menu`},get children(){return u(N,{get onBack(){return e.onBack},onPick:e=>n(e)})}}),null),p(r,u(f,{get when(){return t()===`peachscript`},get children(){return u(P,{onBack:()=>n(`menu`)})}}),null),p(r,u(f,{get when(){return t()===`qr`},get children(){return u(F,{onBack:()=>n(`menu`)})}}),null),p(r,u(f,{get when(){return t()===`csv`},get children(){return u(I,{onBack:()=>n(`menu`)})}}),null),r})()}function N(e){return[u(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(n){let[r,a]=i(``),[o,s]=i(``),[m,g]=i(!1),[_,w]=i(null),[T,E]=i(null),[D,O]=i(0),[k,A]=i({cards:0,passkeys:0,notes:0,logins:0}),[M,N]=i(!1),P=l(()=>r().length>=j&&r()===o());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(r());O(e.entryCount),A(e.stats),w(t(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[u(L,{title:`peachscript`,get onBack(){return n.onBack}}),(()=>{var t=b();return p(t,u(f,{get when(){return _()},get fallback(){return(()=>{var t=C(),n=t.firstChild.nextSibling.nextSibling,i=n.firstChild,l=i.nextSibling,h=n.nextSibling;return i.$$keydown=e=>{e.key===`Enter`&&P()&&!m()&&(e.preventDefault(),F())},i.$$input=e=>a(e.target.value),c(e=>queueMicrotask(()=>e.focus()),i),l.$$keydown=e=>{e.key===`Enter`&&P()&&!m()&&(e.preventDefault(),F())},l.$$input=e=>s(e.target.value),p(n,u(f,{get when(){return e(()=>o().length>0)()&&r()!==o()},get children(){return x()}}),null),p(n,u(f,{get when(){return e(()=>r().length>0)()&&r().length<j},get children(){return S()}}),null),h.$$click=()=>void F(),p(h,()=>m()?`encoding…`:`Generate PeachScript`),d(()=>h.disabled=m()||!P()),d(()=>i.value=r()),d(()=>l.value=o()),t})()},get children(){var t=v(),n=t.firstChild.nextSibling,r=n.firstChild,i=n.nextSibling.firstChild,a=i.nextSibling;return p(t,u(h,{get runeString(){return _()??``},width:288,height:240}),n),p(n,D,r),p(n,()=>D()===1?`y`:`ies`,null),p(n,(()=>{var t=e(()=>k().cards>0);return()=>t()?` · ${k().cards} card${k().cards===1?``:`s`}`:``})(),null),p(n,(()=>{var t=e(()=>k().passkeys>0);return()=>t()?` · ${k().passkeys} passkey${k().passkeys===1?``:`s`}`:``})(),null),p(n,(()=>{var t=e(()=>k().notes>0);return()=>t()?` · ${k().notes} note${k().notes===1?``:`s`}`:``})(),null),i.$$click=()=>void I(),p(i,()=>M()?`copied ✓`:`Copy`),a.$$click=z,t}}),null),p(t,u(f,{get when(){return T()},get children(){var e=y(),t=e.firstChild;return p(t,T),e}}),null),t})()]}function F(e){let[t,n]=i(``),[r,a]=i(``),[o,s]=i(!1),[h,g]=i(null),[_,v]=i(null),[x,S]=i(0),C,E=l(()=>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}s(!0);try{let e=await R(t());if(e.bytes.length>1e5){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.paperSize===`A3`?v(`Mayan symbol is ${n.symbolSize}×${n.symbolSize} modules — print on A3 paper for best results.`):n.paperSize===`A3-required`&&v(`Mayan symbol is ${n.symbolSize}×${n.symbolSize} modules — A3 paper required to print at full resolution. 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{s(!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[u(L,{title:`print backup`,get onBack(){return e.onBack}}),(()=>{var e=b();return p(e,u(f,{get when(){return h()},get fallback(){return(()=>{var e=T(),i=e.firstChild.nextSibling.nextSibling,s=i.firstChild,l=s.nextSibling,u=i.nextSibling;return s.$$keydown=e=>{e.key===`Enter`&&E()&&!o()&&(e.preventDefault(),D())},s.$$input=e=>n(e.target.value),c(e=>queueMicrotask(()=>e.focus()),s),l.$$keydown=e=>{e.key===`Enter`&&E()&&!o()&&(e.preventDefault(),D())},l.$$input=e=>a(e.target.value),u.$$click=()=>void D(),p(u,()=>o()?`encoding…`:`Generate Mayan code`),d(()=>u.disabled=o()||!E()),d(()=>s.value=t()),d(()=>l.value=r()),e})()},get children(){var e=w(),t=e.firstChild,n=t.nextSibling,r=n.firstChild,i=r.nextSibling;i.nextSibling;var a=n.nextSibling,o=C;return typeof o==`function`?c(o,t):C=t,p(n,x,r),p(n,()=>x()===1?`y`:`ies`,i),p(n,H,null),a.$$click=O,e}}),null),p(e,u(f,{get when(){return _()},get children(){var e=y(),t=e.firstChild;return p(t,_),e}}),null),e})()]}function I(e){let[t,r]=i(!1),[a,o]=i(!1),[s,c]=i(null),[l,m]=i(null);async function h(){c(null),m(null),o(!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){c(`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){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}return[u(L,{title:`export as CSV`,get onBack(){return e.onBack}}),(()=>{var e=k(),n=e.firstChild;return n.firstChild,p(n,u(f,{get when(){return!t()},get children(){var e=E();return e.$$click=()=>r(!0),e}}),null),p(n,u(f,{get when(){return t()},get children(){var e=D();return e.$$click=()=>void h(),p(e,()=>a()?`exporting…`:`Download CSV`),d(()=>e.disabled=a()),e}}),null),p(e,u(f,{get when(){return s()},get children(){var e=y(),t=e.firstChild;return p(t,s),e}}),null),p(e,u(f,{get when(){return l()},get children(){var e=O(),t=e.firstChild.firstChild.nextSibling;return p(t,l),e}}),null),e})()]}function L(e){return(()=>{var t=A(),n=t.firstChild,i=n.nextSibling;return r(n,`click`,e.onBack,!0),p(i,()=>e.title),t})()}async function R(e){let t=(await n({type:`GET_ENTRIES`})).data??[],r=(await n({type:`GET_SETTINGS`})).data??{},i;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&&(i={key:t,...e.issued?{activatedAt:new Date(e.issued).getTime()}:{}})}}catch{}let a=z(t);return{bytes:await o({entries:t,settings:r,license:i,passphrase:e}),entryCount:t.length,stats:a}}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)}a([`click`,`input`,`keydown`]);export{M as ExportView};