import{r as e}from"./chunk-QTnfLwEv.js";import{h as t,n,p as r}from"./index-7yDgay5u.js";import{o as i,t as a}from"./jsx-runtime-DHSfUA5-.js";import{P as o,R as s,u as c}from"./test.id-DxQrYxPk.js";import{f as l,o as u}from"./route-CPr17rXr.js";import{t as d}from"./useSuccessToast-CW8oLO3e.js";import{f,m as p,o as m,s as h,w as g}from"./selectors-DZWoTA9D.js";import{t as _}from"./useDiaryModel-BQGj9xs8.js";import{t as v}from"./HeaderPage-CPQpvQQw.js";import{t as y}from"./CellList-UkuVgkhN.js";import{t as b}from"./useLoadingToast-BBb6RyKX.js";var x={"zh-CN":{productName:`屿声`,notebookLabel:`日记本`,timeLabel:`时间`,roleLabel:`角色`,contentLabel:`内容`},"en-US":{productName:`ISLET`,notebookLabel:`NOTEBOOK`,timeLabel:`TIME`,roleLabel:`ROLE`,contentLabel:`CONTENT`}};function S(e,t,n={}){let r=p(e,t);if(!r)return;let i=D(n.locale),a=C(r.name,n),o=m(e,r.id).filter(E),s=o.map(t=>{let n=T(e,t),a=[`${i.notebookLabel}: ${r.name}`,`${i.timeLabel}: ${w(h(t))}`];return n&&a.push(`${i.roleLabel}: ${n}`),a.push(`${i.contentLabel}: ${t.text??``}`),a.join(`
`)});return{filename:a,entryCount:o.length,text:s.join(`

`)+(s.length>0?`
`:``)}}function C(e,t={}){let n=D(t.locale),r=e.trim();if(!r)throw Error(`Notebook name is required.`);let i=r.replace(/[\\/:*?"<>|]+/g,`_`).replace(/\s+/g,` `).slice(0,60);return`${n.productName}-${i}.txt`}function w(e){return g(new Date(e),`yyyy-MM-dd HH:mm:ss`)}function T(e,t){if(t.identityId)return f(e,t.identityId)?.name.trim()||void 0}function E(e){return e.type===`text`&&!!e.text?.trim()}function D(e){return t(e??r())===`zh-CN`?x[`zh-CN`]:x[`en-US`]}var O=e(i(),1),k=a();function A(){let{notebookId:e}=l(),t=_(),r=o(s),i=b(),a=d(),[f,m]=(0,O.useState)(!1);if(!(e&&p(t,e))||!e)return(0,k.jsx)(u,{to:`/diaries`,replace:!0});let h=async()=>{let o=S(t,e);if(!o||o.entryCount===0){a({message:n(`diary.export.empty`,`No text to export`),icon:`none`,testId:c.failureToast});return}m(!0);let s=i({message:n(`diary.export.exporting`,`Preparing export...`)});try{await r.exportTextFile({filename:o.filename,text:o.text,mimeType:`text/plain;charset=utf-8`}),a({message:n(`diary.export.done`,`Export ready`),testId:c.successToast})}catch{a({message:n(`diary.export.failed`,`Could not export text`),icon:`none`,testId:c.failureToast})}finally{s.dispose(),m(!1)}};return(0,k.jsx)(v,{pageTestId:c.page,contentTestId:c.content,header:{title:n(`diary.export.title`,`Export`),showBack:!0},children:(0,k.jsx)(y,{items:[{type:`action`,label:n(`diary.export.allText`,`Export all text`),testId:c.allText,onClick:()=>void h(),disabled:f}]})})}export{A as DiaryChatExportPage};
//# sourceMappingURL=export-C2_yK4-A.js.map