import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{Q as r,X as i,at as a}from"./vendor-mui-Ckcy4Lfd.js";import{a as o,g as s,o as c,s as l,t as u}from"./ui-BLXHSX1T.js";var d=e(n(),1),f=t();function p({note:e,onSubmit:t,onCancel:n,submitLabel:p=`Save`}){let[m,h]=(0,d.useState)(``),[g,_]=(0,d.useState)(``),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)(!1);(0,d.useEffect)(()=>{e&&(h(e.title),_(e.content),y(e.tags??[]))},[e]);let w=async()=>{if(!m.trim()){C(!0);return}x(!0);try{await t({title:m.trim(),content:g.trim(),tags:v})}finally{x(!1)}};return(0,f.jsxs)(r,{component:`form`,id:`note-form`,onSubmit:e=>{e.preventDefault(),w()},sx:{display:`flex`,flexDirection:`column`,gap:3},children:[(0,f.jsx)(o,{main:(0,f.jsxs)(r,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,f.jsx)(c,{fieldLabel:`Title`,required:!0,autoFocus:!0,fullWidth:!0,value:m,onChange:e=>{h(e.target.value),C(!1)},error:S,helperText:S?`Title is required`:void 0}),(0,f.jsxs)(r,{children:[(0,f.jsx)(l,{children:`Content`}),(0,f.jsx)(u,{value:g,onChange:_,height:300})]})]}),sidebar:(0,f.jsx)(r,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:(0,f.jsx)(s,{tags:v,editable:!0,onAdd:e=>y(t=>t.includes(e)?t:[...t,e]),onRemove:e=>y(t=>t.filter(t=>t!==e))})})}),(0,f.jsxs)(r,{sx:{display:`flex`,gap:1,justifyContent:`flex-end`},children:[(0,f.jsx)(i,{onClick:n,children:`Cancel`}),(0,f.jsx)(i,{variant:`contained`,onClick:w,disabled:b||!m.trim(),children:b?(0,f.jsx)(a,{size:20}):p})]})]})}export{p as t};