import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,s as r}from"./hooks.module-BrXTvcfS.js";import{Dt as i,H as a,et as o}from"./content_renderer-DOj8g78V.js";import{N as s,U as c,a as l}from"./i18n-BaLR3UdQ.js";import{t as u}from"./jsxRuntime.module-Cao1NCKs.js";import{J as d}from"./hooks-ClTXKdUl.js";import{t as f}from"./Modal-hBkTa-Ee.js";import{n as p,t as m}from"./Button-Du0dYm4Z.js";import{r as h,t as g}from"./Card-DHxlpCRf.js";import{t as _}from"./Badge-B9svkCt1.js";import{n as v}from"./Admonition-C4vnc1XO.js";import{n as y,t as b}from"./SelectableCard-WSpOV0Di.js";n(),t();function x(){let[t,n]=r(),[o,s]=r(`subtree`),[c,x]=r(`html`),[S,C]=r(`html`),[w,T]=r(!1);d(`showExportDialog`,async({notePath:e,defaultType:t})=>{let{noteId:r,parentNoteId:o}=i.getNoteIdAndParentIdFromUrl(e);if(!o)return;let c=await a.getBranchId(o,r);s(t??`subtree`),n({noteTitle:r&&await i.getNoteTitle(r),defaultType:t,branchId:c}),T(!0)});let A=o===`subtree`?E:D,j=o===`subtree`?c:S,M=o===`subtree`?x:C;return u(f,{className:`export-dialog`,title:`${l(`export.export_note_title`)} ${t?.noteTitle??``}`,size:`lg`,onSubmit:()=>{!t||!t.branchId||(k(t.branchId,o,j,t.noteTitle||`export`),T(!1))},onHidden:()=>T(!1),footer:u(e,{children:[u(m,{text:l(`modal.cancel`),onClick:()=>T(!1)}),u(m,{className:`export-button`,text:l(`export.export`),kind:`primary`})]}),show:w,children:[u(g,{heading:l(`export.what_to_export`),children:u(h,{children:u(p,{className:`export-type-group`,children:[u(`button`,{type:`button`,className:`btn btn-secondary ${o===`subtree`?`active`:``}`,onClick:()=>s(`subtree`),children:l(`export.export_type_subtree`)}),u(`button`,{type:`button`,className:`btn btn-secondary ${o===`single`?`active`:``}`,onClick:()=>s(`single`),children:l(`export.export_type_single`)})]})})}),u(g,{heading:l(`export.format`),children:u(h,{children:u(y,{columns:2,children:A.map(e=>u(b,{icon:e.icon,title:e.recommended?u(`span`,{className:`export-format-heading`,children:[e.name,u(_,{text:l(`export.recommended`),className:`export-recommended-badge`,outline:!0})]}):e.name,description:e.description,selected:j===e.value,onSelect:()=>M(e.value)},e.value))})})}),u(v,{type:`note`,icon:`bx bx-info-circle`,children:O(o,j)})]})}var S={value:`html`,name:l(`export.format_html_name`),description:l(`export.format_html_description`),icon:`bx bxl-html5`,recommended:!0},C={value:`markdown`,name:l(`export.format_markdown_name`),description:l(`export.format_markdown_description`),icon:`bx bxl-markdown`},w={value:`share`,name:l(`export.format_share_name`),description:l(`export.format_share_description`),icon:`bx bx-globe`},T={value:`opml`,name:l(`export.format_opml_name`),description:l(`export.format_opml_description`),icon:`bx bx-list-ul`},E=[S,C,...s?[]:[w],T],D=[S,C];function O(e,t){return l(t===`opml`?`export.result_opml`:t===`share`?`export.result_share`:e===`single`?t===`markdown`?`export.result_single_markdown`:`export.result_single_html`:t===`markdown`?`export.result_subtree_markdown`:`export.result_subtree_html`)}async function k(e,t,n,r){let i=c.randomString(10);if(c.isElectron()&&t===`subtree`&&n!==`opml`){await window.electronApi?.nativeExport.exportSubtreeToFile({branchId:e,format:n,title:r,taskId:i});return}let a=o.getUrlForDownload(`api/branches/${e}/export/${t}/${n}/${i}`);o.download(a)}export{x as default};