import{aT as y,r as _,aU as R,j as e,bi as E,bj as n,bd as M}from"./react-vendor-xYZnmIII.js";import{D as T}from"./delete-modal-h3jQBOO6.js";import{I as x}from"./input-error-_LAmvivg.js";import{L as A}from"./loading-button-D7aXR3K4.js";import{T as D}from"./table-footer-Dfs_f5Wf.js";import{B as L,c as o,L as u,T as S,A as F,h as I,i as B,x as h}from"./ui-components-CQM92IK3.js";import C from"./review-edit-DAM96t16.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./use-lang-Dg6I_Fym.js";import"./route-D0xh7FtZ.js";import"./interactive-vendor-B1OgcAgP.js";const W=()=>{const{props:r}=y(),{translate:p}=r,{button:j,input:v,frontend:a,common:g}=p,[c,l]=_.useState(0),{data:i,setData:m,post:f,errors:d,processing:b,reset:w}=R({rating:0,review:"",user_id:r.auth.user.id,course_id:r.course.id}),N=s=>{s.preventDefault(),f(route("course-reviews.store"),{onError:t=>{t.user_id&&h.error(t.user_id),t.course_id&&h.error(t.course_id)},onSuccess:()=>{w()}})};return e.jsxs("div",{children:[r.course.instructor.user_id!==r.auth.user.id&&e.jsxs("div",{className:"border-t py-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"mb-6 text-xl font-semibold",children:r.userReview?a.review:a.submit_review}),r.userReview&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{review:r.userReview}),e.jsx(T,{routePath:route("course-reviews.destroy",r.userReview.id),actionComponent:e.jsx(L,{size:"icon",variant:"secondary",children:e.jsx(E,{})})})]})]}),r.userReview?e.jsxs("div",{children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(s=>{var t;return e.jsx("button",{type:"button",children:e.jsx(n,{className:o("h-6 w-6",s<=(c||((t=r.userReview)==null?void 0:t.rating)||0)?"fill-amber-400 text-amber-400":"text-gray-300")})},s)})}),e.jsx("p",{className:"mt-3 text-sm",children:r.userReview.review})]}):e.jsxs("form",{onSubmit:N,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{className:"text-sm font-medium",children:[g.rating," *"]}),e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(s=>e.jsx("button",{type:"button",className:"transition-transform hover:scale-110",onMouseEnter:()=>l(s),onMouseLeave:()=>l(0),onClick:()=>m("rating",s),children:e.jsx(n,{className:o("h-8 w-8 cursor-pointer transition-colors",s<=(c||i.rating)?"fill-amber-400 text-amber-400":"text-gray-300 hover:text-amber-200")})},s))}),i.rating>0&&e.jsxs("p",{className:"text-muted-foreground text-sm",children:[a.you_rated_this," ",i.rating," ",i.rating!==1?a.stars:a.star]}),e.jsx(x,{message:d.rating})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{className:"text-sm font-medium text-gray-700",children:[a.review," *"]}),e.jsx(S,{required:!0,value:i.review,onChange:s=>m("review",s.target.value),placeholder:v.review_placeholder,className:"min-h-[120px] w-full resize-none"}),e.jsx(x,{message:d.review})]}),e.jsx(A,{loading:b,children:j.submit_review})]})]}),e.jsxs("div",{className:"border-t py-6",children:[e.jsx("h3",{className:"mb-6 text-xl font-semibold",children:a.student_reviews}),e.jsx("div",{className:"space-y-6",children:r.reviews.data.length>0?r.reviews.data.map(s=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(F,{className:"h-8 w-8",children:[e.jsx(I,{src:s.user.photo||"",alt:s.user.name,className:"object-cover"}),e.jsx(B,{children:s.user.name.charAt(0)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:s.user.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(t=>e.jsx("button",{type:"button",children:e.jsx(n,{className:o("h-4 w-4",t<=s.rating?"fill-amber-400 text-amber-400":"text-gray-300")})},t))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:M(new Date(s.created_at),"MMM d, yyyy h:mm a")})]})]})]}),e.jsx("p",{className:"mt-3 text-sm",children:s.review})]},s.id)):e.jsx("p",{className:"p-3 text-center",children:a.no_reviews_found})}),e.jsx(D,{className:"mt-6",routeName:"course.player",paginationInfo:r.reviews,routeParams:{slug:r.course.slug,watch_history:r.watchHistory.id,lesson_id:r.watchHistory.current_watching_id}})]})]})};export{W as default};
