import{v as x,r as h,j as s}from"./app-BGey7YPf.js";import{D as f,b as j,c as g,d as y,e as D,g as S}from"./dialog-OAe1w9Cd.js";import{B as v}from"./button-D5r5edT8.js";import{L as E}from"./label-BbSRpehS.js";import{P as k}from"./post-editor-BzjujAtF.js";import"./index-BFyaOBDQ.js";import"./x-C4WIHhXm.js";function A({open:o,onClose:t,comment:e,isUpdate:r,post:n}){const{data:m,setData:d,post:c,put:u,processing:p,errors:l,reset:i}=x({body:(e==null?void 0:e.body)??""});h.useEffect(()=>{o&&(r&&e?d({body:e.body}):i())},[o]);const b=a=>{a.preventDefault(),r&&e?u(route("forum.comments.update",{comment:e.id}),{preserveScroll:!0,onSuccess:()=>{i(),t()}}):c(route("forum.posts.comments.store",n.id),{preserveScroll:!0,onSuccess:()=>{i(),t()}})};return s.jsx(f,{open:o,onOpenChange:a=>!a&&t(),children:s.jsxs(j,{children:[s.jsxs(g,{children:[s.jsx(y,{children:r?"Edit Komentar":"Tambah Komentar"}),s.jsx(D,{children:r?"Ubah isi komentar yang sudah ada.":"Tambahkan komentar baru ke dalam post."})]}),s.jsxs("form",{onSubmit:b,className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(E,{children:"Isi Komentar"}),s.jsx(k,{model:m.body,onChange:a=>d("body",a)}),l.body&&s.jsx("p",{className:"text-red-500 text-xs",children:l.body})]}),s.jsx(S,{children:s.jsx(v,{type:"submit",disabled:p,children:r?"Update":"Simpan"})})]})]})})}export{A as default};
