import{j as s,W as L,aY as V,G as U,am as O,u as P,a8 as z,m as S,r as u,a1 as k,aZ as E,af as T,ag as W,Y as D,D as C,a as Q,a_ as A,_ as q,$ as G,a$ as M,b0 as K}from"./entry.client-CV0PzNS2.js";import{Avatar as Y}from"./Avatar-Cy6PhH03.js";import{u as B}from"./Select-CiUaCRv7.js";import{p as H}from"./parseQueryParams-Bd6KFXLi.js";import{N as X}from"./NoElementsFound-BYYh6uWM.js";import{u as Z}from"./useQuery-_I6Fb0gn.js";import{P as R}from"./Paginator-CdCtQQNK.js";import"./isNil-DJ_omAdg.js";import"./trim-BKnRwbL4.js";import"./useFlexiblePrefillValues-CdKhmvNK.js";import"./useFlexibleOptions-BzusANQ_.js";const J=a=>{const{item:e}=a;return s.jsx("div",{className:"h-full flex flex-row items-stretch p-2",children:s.jsxs(L,{color:"tertiary",elevated:!1,className:"w-full h-full hover:cursor-pointer p-4",children:[s.jsx("div",{className:"flex flex-row justify-center w-full mb-4",children:s.jsx(V,{rating:e.rating,color:"primary",maxRating:5,size:"3xl"})}),s.jsx("div",{className:"w-full line-clamp-5 italic text-center mb-4",children:e.review}),s.jsxs("div",{className:"flex-1 flex flex-row items-end w-full",children:[s.jsx("div",{className:"w-full text-gray-500 font-light text-sm capitalize whitespace-nowrap overflow-hidden text-ellipsis",children:`${e.user.firstname.toLowerCase()} ${e.user.lastname.toLowerCase()}`}),e.created_at&&s.jsx("div",{className:"text-right text-gray-500 font-light text-sm",children:U(new Date(e.created_at),"dd/MM/yyyy")})]})]})})},ee=a=>{const{items:e,perPage:m}=a,i=O(),{t:d}=P("core");return e.length>0?s.jsx("div",{className:"w-full",children:s.jsx(z,{slidesPerView:1,slidesPerViewSm:2,slidesPerViewMd:2,slidesPerViewLg:4,slidesPerViewXl:m,whiteSolid:!0,loop:!1,centeredSlide:!1,height:"100%",showNavigation:i>640,showPagination:!0,shouldFlattenChildren:!0,containerClassName:"pb-8 h-full",swiperClassName:"h-[285px]",children:S(e,(c,l)=>s.jsx(J,{item:c},l))})}):s.jsx("div",{className:"text-center flex items-center justify-center my-12",children:d("no_results")})},te=a=>{const{title:e,defaultValue:m,onChange:i,placeholder:d,fetchUrl:c}=a,{t:l}=P("core"),[f,r]=u.useState({value:m,label:m}),x=u.useCallback(async()=>{const{data:t}=await k.get(c);return{options:t,hasMore:!1,additional:{page:1}}},[c]),o=t=>{r(t),i(t)};return s.jsxs("div",{className:"mb-4 flex flex-row items-center justify-center gap-4",children:[s.jsx("div",{className:"flex flex-row items-center",children:e}),s.jsx(E,{className:"bg-transparent border-0 min-w-250 block sm:text-sm outline-none focus:shadow-none focus:ring-0 z-20",isSearchable:!0,isClearable:!0,placeholder:d,value:f,loadOptions:x,noOptionsMessage:()=>l("no_options_found"),loadingMessage:()=>l("loading"),onChange:o})]})},se=({review:a})=>{var i,d,c,l;const e=u.useCallback(()=>{const f="#"+Math.floor(Math.random()*16777215).toString(16);return T(f)&&W.contrast(f,"white")>1.2?f:e()},[]),m=u.useMemo(()=>e(),[e]);return s.jsxs("div",{className:"mb-4 pb-4 flex flex-col border border-gray-100 rounded-md p-4 w-full",children:[a.user&&s.jsxs("div",{className:"flex flex-row items-start justify-start border-b border-b-gray-200 mb-4 w-full pb-4",children:[s.jsx("div",{className:"flex flex-row items-center mr-4",children:s.jsx(Y,{size:"sm",user:a.user,color:m})}),s.jsxs("div",{className:"flex flex-col",children:[s.jsx("div",{className:"text-md font-medium",children:`${a.user.firstname} ${a.user.lastname}`}),s.jsxs("div",{className:"text-gray-500 font-light text-sm capitalize whitespace-nowrap",children:[a.user.city,(d=(i=a==null?void 0:a.user)==null?void 0:i.country)!=null&&d.name?`${a.user.city?" - ":""}${(l=(c=a==null?void 0:a.user)==null?void 0:c.country)==null?void 0:l.name}`:""]})]})]}),s.jsxs("div",{className:"flex flex-row items-center",children:[s.jsx(V,{rating:a.rating,color:"primary",maxRating:5,size:"2xl"}),a.created_at&&s.jsx("div",{className:"flex flex-row items-center justify-end flex-1 font-medium text-md text-black",children:U(new Date(a.created_at),"dd/MM/yyyy")})]}),s.jsx("div",{className:"flex flex-row py-2 mb-4 pb-4",children:a.review}),s.jsx("div",{className:"flex flex-row space-x-3",children:S(a.tags,(f,r)=>s.jsx("div",{className:"px-2 py-1 bg-gray-200 text-black rounded-full text-sm hover:cursor-pointer",children:f.label},r))})]})},ae=a=>{const{navigateTo:e,on:m}=D(),i=C(),{filters:d,filters_url:c}=i.route,[l,f]=u.useState(i.route.url);u.useEffect(()=>{f(window.location.pathname)},[]),m("navigate",t=>{f(t)});const r=l.split("?")[0].replace(/\/$/,""),x=u.useCallback(t=>{const p=H(l,t),h=p?r.concat(p):null;h&&e(h,["route"])},[l,r,e]),o=u.useCallback(t=>{const p=new RegExp(`\\/page\\/${i.page}(\\?|$)`),y=(c[a]?c[a]:c.default).split("/").indexOf(`:${a}:`),b=r.replace(p,"").split("/");t&&(y===-1||b.length<=y?b.push(t.slug):b[y]=t.slug);let v=b.join("/");l.split("?")[1]&&(v=v.concat("?"+l.split("?")[1])),e(v,["route"])},[i.page,c,a,r,l,e]);return{filters:d,setFilters:o,setQueryParams:x}},F=a=>{const{id:e,className:m,label:i,changeUrl:d=!1,filterKey:c=""}=a,{setQueryParams:l,setFilters:f}=ae(c),{filters:r,filters_selected:x}=C().route,o=B(),t=u.useMemo(()=>Q(r[e],n=>n.slug===x[e])[0],[r,e,x]),p=u.useMemo(()=>({label:(t==null?void 0:t.name)||r[e][0].name,value:x[e]}),[r,e,t==null?void 0:t.name,x]),h=u.useMemo(()=>S(r[e],n=>({label:n.name,value:n.slug})),[r,e]),y=n=>{d?f({slug:n??t[e].slug,name:t[e].name}):l({[e]:n??r[e][0].slug})},b={...o,control:n=>({...n,border:0,boxShadow:"none",background:"transparent"}),indicatorSeparator:n=>({...n}),menu:n=>({...n,width:"max-content",minWidth:"100%",right:0}),menuPortal:n=>({...n,zIndex:100})},_=A()?document.body:null;return s.jsxs("div",{className:`flex flex-row items-center border border-gray-300 rounded-md pl-3 w-full md:w-auto h-10 ${m}`,children:[s.jsx("span",{className:"text-gray-500 mr-1 contents text-sm whitespace-nowrap flex-1",children:i}),s.jsx(q,{Component:G,className:"!border-none react-select w-full lg:w-auto flex-1",isSearchable:!0,isClearable:!0,menuPosition:"absolute",onChange:n=>{y((n==null?void 0:n.value)??null)},defaultValue:p,menuPortalTarget:_,styles:b,isMulti:!1,options:h})]})},le=a=>{var x;const{response:e,infiniteScroll:m,isLoading:i,perPage:d=15,loadItems:c}=a,{filters:l}=C().route,{t:f}=P("core"),r=u.useRef(null);if(u.useEffect(()=>{const o=new IntersectionObserver(t=>{t[0].isIntersecting&&c()},{rootMargin:"100px",threshold:[]});return r.current&&o.observe(r.current),()=>{r.current&&o.unobserve(r.current)}},[c,r]),i&&!m)return[...Array(d)].map((o,t)=>s.jsx(M,{},t));if(!i&&!(e!=null&&e.items))return s.jsx("div",{className:"py-4 h-[300px] w-full flex flex-row items-center justify-center text-gray-200",children:f("no_elements_found")});if(e!=null&&e.items)return s.jsxs("div",{className:"flex flex-col w-full gap-4",children:[((l==null?void 0:l.course)||(l==null?void 0:l.province))&&s.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-2 mb-4 md:mb-0 justify-end",children:[(l==null?void 0:l.course)&&s.jsx(F,{className:"flex-1 justify-between",id:"course",label:"Corso:"}),(l==null?void 0:l.province)&&s.jsx(F,{id:"province",className:"justify-between w-1/3",label:"Provincia:"})]}),s.jsxs("div",{className:"flex flex-col w-full",children:[S(e.items,(o,t)=>{var p,h;return s.jsx(se,{review:o},`${((p=o.user)==null?void 0:p.firstname)??"null"}_${((h=o.user)==null?void 0:h.lastname)??"null"}_${o.created_at&&new Date(o.created_at).toISOString()}_${t}`)}),!!m&&(e==null?void 0:e.items.length)<e.total_items&&[...Array(d)].map((o,t)=>s.jsx(M,{ref:t===0?r:null},t)),!i&&!((x=e==null?void 0:e.items)!=null&&x.length)&&s.jsx(X,{})]})]})},he=a=>{const{name:e,fetchUrl:m,perPage:i,filters:d,reviews:c,paginated:l=!0,enableFetch:f=!0,paginationUrl:r,infiniteScroll:x=!1}=a,o=u.useRef(null),[t,p]=u.useState(c),[h,y]=u.useState(1),[b,v]=u.useState([]),_=j=>{y(j),o.current&&o.current.scrollIntoView({behavior:"smooth"})},n=u.useCallback(async()=>{const j={page:h,filters:b},g=(await k.get(m,{params:j})).data;return p(w=>({...g,items:w!=null&&w.items&&x?w.items.concat(g==null?void 0:g.items):g==null?void 0:g.items})),g},[h,m,x,b]),{isLoading:$}=Z({queryKey:["review",e,m,h,b],queryFn:n,refetchOnWindowFocus:!1,enabled:f||!f&&h>1}),I=(j,g)=>{v(w=>{const N=[...w];return g!=null&&g.value?N[j]=g.value:N.splice(j,1),N})};return s.jsxs("div",{className:"h-full w-full",children:[s.jsx("span",{ref:o}),d&&d.length>0&&s.jsx("div",{className:"flex flex-row items-center justify-end",children:S(d,(j,g)=>{const w=K(j);return s.jsx(te,{defaultValue:w.value,fetchUrl:w.fetchUrl,onChange:N=>I(g,N),placeholder:w.placeholder,title:w.label})})}),!x&&t&&e==="x_list_reviews"&&l&&t.total_pages>1&&s.jsx(R,{paginationUrl:r,onPageChange:_,currentPage:t==null?void 0:t.page,totalPages:t==null?void 0:t.total_pages}),e==="x_list_reviews"&&s.jsx(le,{loadItems:()=>y(j=>j+1),response:t,infiniteScroll:x,isLoading:$,perPage:Number(i)}),!x&&t&&e==="x_list_reviews"&&l&&t.total_pages>1&&s.jsx(R,{paginationUrl:r,onPageChange:_,currentPage:t==null?void 0:t.page,totalPages:t==null?void 0:t.total_pages}),!$&&t&&e==="x_carousel_reviews"&&s.jsx(ee,{items:t.items,perPage:i})]})};export{he as Reviews};