1import{P as i,j as e,aw as f,V as w,ad as D,B as r,aJ as h,T as p,W as b,aU as k,bk as T,bJ as z,aY as B,d_ as v,a_ as P,R as E,b0 as M,ig as N,am as F,d1 as H,d as U,e as $,cb as V,cL as Y,ch as J,eT as Q,Q as _,ay as X,cR as q}from"./vendor-DRQg1ZAU.js";import{eU as K,eV as W,eW as O,eX as Z,b0 as ee,Q as te,eY as se,dp as ae}from"./index-DUkk2-Lr.js";function re({prompts:d,setPrompts:o}){const[s,C]=i.useState(K()),[a,m]=i.useState({title:"",category:""}),[I,u]=i.useState(!1),[g,y]=i.useState(!1),[x,l]=i.useState({type:null,message:""});i.useEffect(()=>{s in d||(u(!0),W(s,o).finally(()=>u(!1)))},[s]);const n=d[s]??[],j=async t=>{const c=U($(ee,"prompts"),s);await V(c,{prompts:t}),o(R=>({...R,[s]:t}))},S=async()=>{if(!a.title||!a.category)return;const t={id:crypto.randomUUID(),title:a.title,category:a.category};await j([...n,t]),m({title:"",category:""})},A=async t=>{await j(n.filter(c=>c.id!==t))},G=async()=>{y(!0),l({type:null,message:""});try{const t=await Z({weekString:s,force:!0});console.log("Generation result:",t),t.data.success?(l({type:"success",message:`Successfully generated ${t.data.promptCount} prompts!`}),await W(s,o)):l({type:"error",message:t.data.message||"Failed to generate prompts"})}catch(t){console.error("Error generating prompts:",t),l({type:"error",message:"An error occurred while generating prompts"})}finally{y(!1)}},L=O(s);return e.jsx(f,{container:!0,spacing:4,children:e.jsxs(f,{size:{xs:12},children:[x.type&&e.jsx(w,{severity:x.type,sx:{mb:2},onClose:()=>l({type:null,message:""}),children:x.message}),e.jsx(D,{elevation:3,children:e.jsxs(r,{p:3,children:[e.jsx(r,{display:"flex",gap:2,alignItems:"flex-start",mb:2,children:e.jsx(h,{type:"week",label:"Weekly prompts for",value:`${s.slice(0,4)}-W${s.slice(4)}`,onChange:t=>C(t.target.value.replace(/-W/g,"")),fullWidth:!0,InputLabelProps:{shrink:!0},inputProps:{style:{cursor:"pointer"},onClick:t=>t.currentTarget.showPicker()}})}),e.jsx(p,{variant:"body2",color:"text.secondary",mb:1,ml:1.75,children:L}),n.length>=16?e.jsx(w,{severity:"info",sx:{mb:2},children:"This week already has prompts. Remove some to generate new ones."}):e.jsx(b,{variant:"contained",color:"secondary",startIcon:g?e.jsx(k,{size:20,color:"inherit"}):e.jsx(T,{}),onClick:G,disabled:g||n.length>=10,sx:{minWidth:200,whiteSpace:"nowrap",mb:2},children:g?"Generating...":"Generate with AI"}),e.jsx(p,{variant:"h6",mb:1,children:"Add New Prompt"}),e.jsxs(r,{display:"flex",gap:2,alignItems:"flex-start",mb:3,children:[e.jsx(h,{size:"small",label:"Prompt title",multiline:!0,value:a.title,onChange:t=>m({...a,title:t.target.value}),sx:{flexGrow:1}}),e.jsx(h,{size:"small",label:"Category",value:a.category,onChange:t=>m({...a,category:t.target.value}),sx:{width:180}}),e.jsx(b,{variant:"contained",startIcon:e.jsx(z,{}),onClick:S,disabled:!a.title||!a.category,children:"Add"})]}),I?e.jsx(r,{display:"flex",justifyContent:"center",py:3,children:e.jsx(k,{size:28})}):e.jsx(B,{children:n.length===0?e.jsx(v,{children:e.jsx(P,{primary:"No prompts added for this week"})}):n.map((t,c)=>e.jsxs(E.Fragment,{children:[c>0&&e.jsx(M,{}),e.jsxs(v,{children:[e.jsx(P,{primary:t.title,secondary:`Category: ${t.category}`}),e.jsx(N,{children:e.jsx(F,{edge:"end","aria-label":"delete",onClick:()=>A(t.id),size:"large",children:e.jsx(H,{})})})]})]},t.id))})]})})]})})}const oe=()=>{const d=Y(te),[o,s]=J(se);return e.jsxs(r,{className:"full-viewport-height",display:"flex",flexDirection:"column",children:[e.jsxs(Q,{children:[e.jsx("title",{children:"WritingHabit | Manage Writing Prompts"}),e.jsx("meta",{name:"description",content:"Manage writing prompts"}),e.jsx("link",{rel:"canonical",href:"https://writinghabit.app/writing-prompts/manage"})]}),e.jsx(ae,{staticHeader:!0}),e.jsx(_,{in:!0,timeout:250,children:e.jsx(r,{sx:{flexGrow:1,overflowY:"auto",pt:d?3:4},children:e.jsxs(X,{maxWidth:"md",sx:{pb:6},children:[e.jsx(p,{variant:"body2",component:q,to:"/writing-prompts",color:"primary.main",children:"Back to writing prompts"}),e.jsx(p,{variant:"h1",children:"Writing Prompt Manager"}),e.jsx(r,{py:4,children:e.jsx(re,{prompts:o,setPrompts:s})})]})})})]})};export{oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.