import{C as e,D as t,E as n,F as r,H as i,I as a,Q as o,S as s,T as c,U as l,X as u,Y as d,_ as f,b as p,f as m,g as h,i as g,n as _,p as v,q as y,r as b}from"./app-C984PpLk.js";import{n as x}from"./upload-CsRIgK58.js";import{t as S}from"./AppLayout-BvbFaVld.js";import{t as C}from"./Editor-CLoyXBnW.js";var w={class:`mx-auto max-w-[760px]`},T={class:`rounded-c border border-line bg-surface p-5`},E={key:0,class:`mt-1 text-sm text-red-500`},D=[`value`],O={class:`mt-2 flex flex-wrap gap-2`},k=[`onClick`],A={key:0,class:`text-sm text-ink-muted`},j={class:`mt-2 flex items-center gap-3`},M=[`src`],N={key:1,class:`text-sm text-ink-muted`},P={key:0,class:`mt-1 text-sm text-red-500`},F={class:`flex items-center gap-3`},I=[`disabled`],L=t({__name:`Create`,props:{categories:{},tags:{}},setup(t){let L=t,R=y(null),z=y(!1),B=g({title:``,category_id:L.categories[0]?.id??null,tags:[],cover:``,body_html:``,body_json:``});function V(e){let t=B.tags.indexOf(e);t===-1?B.tags.push(e):B.tags.splice(t,1)}async function H(e){let t=e.target.files?.[0];if(t){z.value=!0;try{let{url:e}=await x(t);B.cover=e}catch{}finally{z.value=!1}}}function U(){if(!R.value||R.value.isEmpty()){B.setError(`body_html`,`Write something first.`);return}B.body_html=R.value.getHTML(),B.body_json=R.value.getJSON(),B.post(`/topics`)}return(g,y)=>(r(),e(f,null,[n(d(_),{title:`Start a topic`}),n(S,null,{default:i(()=>[p(`div`,w,[y[9]||=p(`h1`,{class:`mb-5 text-2xl font-extrabold tracking-tight`},`Start a topic`,-1),p(`form`,{class:`space-y-5`,onSubmit:h(U,[`prevent`])},[p(`div`,T,[y[3]||=p(`label`,{class:`block text-sm font-semibold text-ink-2`},`Title`,-1),l(p(`input`,{"onUpdate:modelValue":y[0]||=e=>d(B).title=e,type:`text`,maxlength:`160`,placeholder:`What do you want to discuss?`,class:`mt-1.5 w-full rounded-lg border-line bg-surface-2 text-ink placeholder:text-ink-muted focus:border-primary focus:ring-primary`},null,512),[[v,d(B).title]]),d(B).errors.title?(r(),e(`p`,E,o(d(B).errors.title),1)):s(``,!0),y[4]||=p(`label`,{class:`mt-4 block text-sm font-semibold text-ink-2`},`Category`,-1),l(p(`select`,{"onUpdate:modelValue":y[1]||=e=>d(B).category_id=e,class:`mt-1.5 w-full rounded-lg border-line bg-surface-2 text-ink focus:border-primary focus:ring-primary`},[y[2]||=p(`option`,{value:null},`— none —`,-1),(r(!0),e(f,null,a(t.categories,t=>(r(),e(`option`,{key:t.id,value:t.id},o(t.name),9,D))),128))],512),[[m,d(B).category_id]]),y[5]||=p(`label`,{class:`mt-4 block text-sm font-semibold text-ink-2`},`Tags`,-1),p(`div`,O,[(r(!0),e(f,null,a(t.tags,t=>(r(),e(`button`,{key:t.id,type:`button`,class:u([`rounded-full border px-3 py-1 text-xs font-semibold`,d(B).tags.includes(t.id)?`border-primary bg-primary/15 text-primary`:`border-line bg-surface-2 text-ink-2 hover:bg-surface`]),onClick:e=>V(t.id)},`#`+o(t.name),11,k))),128)),t.tags.length?s(``,!0):(r(),e(`span`,A,`No tags yet.`))]),y[6]||=p(`label`,{class:`mt-4 block text-sm font-semibold text-ink-2`},[c(`Cover image `),p(`span`,{class:`font-normal text-ink-muted`},`(optional, for grid view)`)],-1),p(`div`,j,[d(B).cover?(r(),e(`img`,{key:0,src:d(B).cover,alt:``,class:`h-14 w-24 rounded-lg object-cover`},null,8,M)):s(``,!0),p(`input`,{type:`file`,accept:`image/*`,class:`text-sm text-ink-2`,onChange:H},null,32),z.value?(r(),e(`span`,N,`Uploading…`)):s(``,!0)])]),p(`div`,null,[y[7]||=p(`label`,{class:`mb-1.5 block text-sm font-semibold text-ink-2`},`Post`,-1),n(C,{ref_key:`editor`,ref:R,placeholder:`Write your post… (rich text, drag images in)`},null,512),d(B).errors.body_html?(r(),e(`p`,P,o(d(B).errors.body_html),1)):s(``,!0)]),p(`div`,F,[p(`button`,{type:`submit`,disabled:d(B).processing,class:`rounded-c bg-primary px-5 py-2.5 text-sm font-semibold text-white shadow-lg shadow-primary/30 hover:bg-primary-600 disabled:opacity-60`},o(d(B).processing?`Posting…`:`Post topic`),9,I),n(d(b),{href:`/`,class:`text-sm font-semibold text-ink-2 hover:text-ink`},{default:i(()=>[...y[8]||=[c(`Cancel`,-1)]]),_:1})])],32)])]),_:1})],64))}});export{L as default};