import{v as f,r as g,j as t}from"./app-BGey7YPf.js";import{D as b,b as S,c as v,d as D,e as y,g as P}from"./dialog-OAe1w9Cd.js";import{B as _}from"./button-D5r5edT8.js";import{S as E,a as N,b as k,c as C,d as T}from"./select-BqSuhmAT.js";import{L as d}from"./label-BbSRpehS.js";import{I}from"./input-CGSIKYsG.js";import{P as B}from"./post-editor-BzjujAtF.js";import"./index-BFyaOBDQ.js";import"./x-C4WIHhXm.js";import"./index-Q2wK6uZI.js";import"./index-CwO5dfCw.js";import"./index-BuSoVzfP.js";import"./chevron-down-DOZGaFlM.js";function K({open:a,onClose:n,post:i,isUpdate:s,topics:m}){const{data:r,setData:o,post:x,processing:p,errors:l,reset:c,transform:u}=f({id:"",title:"",topic_id:"",body:""});u(e=>({...e,_method:s?"put":"post"})),g.useEffect(()=>{a&&(s&&i?o({id:i.id.toString(),title:i.title,topic_id:i.topic.id.toString(),body:i.body}):c())},[a]);const h=e=>{e.preventDefault();const j=s?route("forum.posts.update",r.id):route("forum.posts.store");x(j,{preserveScroll:!0,onSuccess:()=>{c(),n()}})};return t.jsx(b,{open:a,onOpenChange:e=>!e&&n(),children:t.jsxs(S,{children:[t.jsxs(v,{children:[t.jsx(D,{children:s?"Edit Post":"Tambah Post"}),t.jsx(y,{children:s?"Ubah data post yang sudah ada.":"Masukkan data post baru ke dalam forum."})]}),t.jsxs("form",{onSubmit:h,className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx(d,{htmlFor:"topic_id",children:"Topik"}),t.jsxs(E,{value:r.topic_id||"",onValueChange:e=>o("topic_id",e),children:[t.jsx(N,{className:"w-full",children:t.jsx(k,{placeholder:"-- Pilih Topik --"})}),t.jsx(C,{children:m.map(e=>t.jsx(T,{value:e.id.toString(),children:e.name},e.id))})]}),t.jsx("p",{className:"text-red-500 text-xs",children:l.topic_id})]}),t.jsxs("div",{children:[t.jsx(d,{children:"Judul"}),t.jsx(I,{value:r.title,onChange:e=>o("title",e.target.value)}),t.jsx("p",{className:"text-red-500 text-xs",children:l.title})]}),t.jsxs("div",{children:[t.jsx(d,{children:"Isi Post"}),t.jsx(B,{model:r.body,onChange:e=>o("body",e)}),t.jsx("p",{className:"text-red-500 text-xs",children:l.body})]}),t.jsx(P,{children:t.jsx(_,{type:"submit",disabled:p,children:s?"Update":"Simpan"})})]})]})})}export{K as default};
