https://www.actugaming.net/wp-content/themes/actugaming/dist/theme/assets/FeedbackIsland-Clf0JujC.js
1import{a as n,j as e}from"./vendor-2Qcv06Ow.js";import{a as v,u as S}from"./apiClient-C_suo9XD.js";import{A as x}from"./AgButton-Dk1bwuYs.js";import{S as P}from"./close-square-D3doeRjV.js";function E(s,a){const t=[["page",String(s.page)],["per_page",String(s.per_page)]];if(s.sort_by&&t.push(["sort_by",s.sort_by]),s.sort_order&&t.push(["sort_order",s.sort_order]),s.filters&&t.push(["filters",s.filters]),s.with&&t.push(["with",s.with]),a)for(const[r,c]of Object.entries(a))t.push([r,c]);return"?"+new URLSearchParams(t).toString()}const j={getByGameId(s,a){const t=E(a,{game_id:String(s)});return v.get(`/feedbacks${t}`)},getGameStats(s){return v.get(`/feedbacks/games/${s}/stats`).then(a=>a.data??a)},getUserFeedbackForGame(s){return v.get(`/feedbacks/games/${s}/user`).then(a=>a.data??null)},create(s){return v.post("/feedbacks",s).then(a=>a.data??a)}};function w(s){const[a,t]=n.useState(null),[r,c]=n.useState(!1),[o,i]=n.useState(null),{userLogged:u}=S(),l=n.useCallback(async()=>{if(u)try{t(await j.getUserFeedbackForGame(s))}catch{}},[s,u]);n.useEffect(()=>{l()},[l]);const b=n.useCallback(async(g,m)=>{c(!0),i(null);try{const _=await j.create({score:g,review:m,game_id:s});return t(_),!0}catch(_){return i(_),!1}finally{c(!1)}},[s]);return{userFeedback:a,hasUserFeedback:!!a,isSubmitting:r,error:o,checkUserFeedback:l,submitFeedback:b}}const L={count:0,average:0,bad_scores:0,medium_scores:0,good_scores:0,top_scores:0};function M(s){const[a,t]=n.useState(L),[r,c]=n.useState(!1),o=n.useCallback(async()=>{c(!0);try{t(await j.getGameStats(s))}catch{}finally{c(!1)}},[s]);n.useEffect(()=>{o()},[o]);const i=g=>a.count>0?Math.round(g*100/a.count):0,u=n.useMemo(()=>i(a.bad_scores),[a]),l=n.useMemo(()=>i(a.medium_scores),[a]),b=n.useMemo(()=>i(a.good_scores),[a]),h=n.useMemo(()=>i(a.top_scores),[a]);return{stats:a,isLoading:r,loadStats:o,badPercent:u,mediumPercent:l,goodPercent:b,topPercent:h}}const A="M25 9.1c-0.2-0.5-0.6-0.9-1.1-0.9l-7.2-0.7 -2.9-6.7C13.5 0.3 13.1 0 12.5 0s-1 0.3-1.2 0.8L8.4 7.5 1.2 8.2c-0.5 0-1 0.4-1.1 0.9s0 1.1 0.4 1.4l5.5 4.8 -1.6 7.1c-0.1 0.5 0.1 1.1 0.5 1.4C5.1 23.9 5.3 24 5.6 24c0.2 0 0.5-0.1 0.7-0.2l6.2-3.7 6.2 3.7c0.5 0.3 1 0.2 1.5-0.1 0.4-0.3 0.6-0.9 0.5-1.4l-1.6-7.1 5.5-4.8C25 10.1 25.1 9.6 25 9.1z",V=[0,2,4,6,8];function H({average:s,disabled:a=!1}){const t=["ag-ratings",a&&"ag-ratings--disabled"].filter(Boolean).join(" ");return e.jsx("div",{className:t,children:V.map(r=>e.jsx("svg",{className:`ag-ratings__star${s>r?" ag-ratings__star--active":""}`,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 24",children:e.jsx("path",{d:A})},r))})}function T({percent:s=0,radius:a=100,stroke:t=20}){const r=a-t/5*2,c=r*2*Math.PI,o=c-s/100*c,i=c.toFixed(3),u=`${i} ${i}`,l=o.toFixed(3);return e.jsx("svg",{className:"ag-gauge",viewBox:"0 0 200 200",preserveAspectRatio:"xMinYMin meet","aria-hidden":"true",focusable:"false",children:e.jsx("circle",{className:"ag-gauge__ring",stroke:"#EF233C",fill:"transparent",strokeWidth:t,strokeDasharray:u,strokeDashoffset:l,r,cx:a,cy:a})})}function N({score:s,dark:a=!1,stroke:t=23}
1){const r=["ag-score",a&&"ag-score--dark"].filter(Boolean).join(" ");return e.jsxs("div",{className:r,children:[e.jsx("div",{className:"ag-score__gauge",children:e.jsx(T,{percent:s?s*10:0,stroke:t})}),e.jsx("div",{className:"ag-score__value",children:e.jsx("span",{children:s??"-"})})]})}const F=s=>n.createElement("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...s},n.createElement("path",{d:"M20.1449 1.61719H3.83162C2.12599 1.61719 0.738281 3.00462 0.738281 4.71053V14.6939C0.738281 16.396 2.11995 17.7812 3.82063 17.7873V22.3176L10.3313 17.7873H20.1449C21.8506 17.7873 23.2383 16.3996 23.2383 14.6939V4.71053C23.2383 3.00462 21.8506 1.61719 20.1449 1.61719ZM21.9199 14.6939C21.9199 15.6725 21.1237 16.4689 20.1449 16.4689H9.91763L5.13899 19.7942V16.4689H3.83162C2.85287 16.4689 2.05664 15.6725 2.05664 14.6939V4.71053C2.05664 3.73164 2.85287 2.93555 3.83162 2.93555H20.1449C21.1237 2.93555 21.9199 3.73164 21.9199 4.71053V14.6939Z",fill:"currentColor"}),n.createElement("path",{d:"M6.76025 6.27539H17.2162V7.59375H6.76025V6.27539Z",fill:"currentColor"}),n.createElement("path",{d:"M6.76025 9.08789H17.2162V10.4062H6.76025V9.08789Z",fill:"currentColor"}),n.createElement("path",{d:"M6.76025 11.9004H17.2162V13.2188H6.76025V11.9004Z",fill:"currentColor"}));function k({label:s,range:a,count:t,percent:r,variant:c}){return e.jsxs("div",{className:"ag-feedback-bar",children:[e.jsxs("span",{className:"ag-feedback-bar__label",children:[e.jsx("b",{children:s})," ",a]}),e.jsx("div",{className:"ag-feedback-bar__track",children:e.jsx("div",{className:`ag-feedback-bar__fill ag-feedback-bar__fill--${c}`,style:{width:`${r}%`}})}),e.jsxs("span",{className:"ag-feedback-bar__count",children:[t," avis"]})]})}function U({gameId:s,hasUserFeedback:a,onAddFeedback:t}){const{stats:r,badPercent:c,mediumPercent:o,goodPercent:i,topPercent:u}=M(s),{userLogged:l}=S();return e.jsxs("div",{className:"ag-feedback-summary",children:[e.jsx("h2",{className:"ag-feedback-summary__title",children:"La note des lecteurs"}),e.jsxs("div",{className:"ag-feedback-summary__container",children:[e.jsxs("div",{className:"ag-feedback-resume",children:[e.jsx(N,{score:r.average||null,dark:!0}),e.jsxs("span",{className:"ag-feedback-resume__baseline",children:[r.count," avis"]}),e.jsx(H,{average:r.average})]}),e.jsxs("div",{className:"ag-feedback-stats",children:[e.jsx(k,{label:"Superbe",range:"(10)",count:r.top_scores,percent:u,variant:"green"}),e.jsx(k,{label:"Tres bon",range:"(7 - 9)",count:r.good_scores,percent:i,variant:"yellow"}),e.jsx(k,{label:"Acceptable",range:"(4 - 6)",count:r.medium_scores,percent:o,variant:"orange"}),e.jsx(k,{label:"Mauvais",range:"(0 - 3)",count:r.bad_scores,percent:c,variant:"red"}),e.jsxs("div",{className:"ag-feedback-summary__action",children:[l&&!a&&e.jsx(x,{content:e.jsxs(e.Fragment,{children:[e.jsx(F,{"aria-hidden":"true"})," ","Partagez votre avis"]}),variant:"red",bold:!0,uppercase:!1,onClick:t}),!l&&e.jsx(x,{content:"Se connecter pour laisser un avis",variant:"red",bold:!0,uppercase:!1,link:"/login"})]})]})]})]})}const $={page:1,per_page:10,sort_by:"created_at",sort_order:"desc",with:"user",filters:"full"};function R(s){const[a,t]=n.useState([]),[r,c]=n.useState(!1),[o,i]=n.useState(1),[u,l]=n.useState(1),[b,h]=n.useState(0),g=n.useCallback(async(p={})=>{c(!0);try{const d={...$,...p},f=await j.getByGameId(s,d);d.page===1?t(f.data):t(C=>[...C,...f.data]),i(f.meta.current_page),l(f.meta.last_page),h(f.meta.total)}catch{}finally{c(!1)}},[s]);n.useEffect(()=>{g()},[g]);const m=o<u,_=n.useCallback(()=>{if(m)return g({page:o+1})},[m,o,g]);return{feedbacks:a,isLoading:r,hasNextPage:m,total:b,loadFeedbacks:g,loadNextPage:_}}function z(s){const a=Math.floor((Date.now()-new Date(s).getTime())/1e3),t=[[31536e3,"an"],[2592e3,"mois"],[86400,"jour"],[3600,"heure"],[60,"minute"]];for(const[r,c]of t){const o=Math.floor(a/r);if(o>=1){if(c==="mois")return o===1?"il y a 1 mois":`il y a ${o} mois`;const i=o>1&&c!=="mois"?"s":"";return`il y a ${o} ${c}${i}`}}return"il y a quelques secondes"}function B({feedback:s,maxLength:a=400}){const[t,r]=n.useState(!1),c=s.review??"",o=c.length>a,i=!o||t?c.trim():c.slice(0,a).trim();return e.jsxs("div",{className:"ag-feedback-card",children:[e.jsxs("div",{className:"ag-feedback-card__meta",children:[e.jsxs("div",{className:"ag-feedback-card__user",children:[s.gravatar_url&&e.jsx("figure",{className:"ag-feedback-card__avatar",children:e.jsx("img",{src:s.gravatar_url,alt:""})}),e.jsx("div",{className:"ag-feedback-card__author",children:s.user_name})]}),e.jsx("div",{className:"ag-feedback-card__score ag-feedback-card__score--mobile",children:e.jsx(N,{score:s.score,dark:!0})})]}),e.jsxs("div",{className:"ag-feedback-card__content",children:[e.jsxs("p",{children:[i,o&&!t&&e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"ag-feedback-card__read-more",onClick:()=>r(!0),children:"Lire plus »"})]})]}),e.jsx("div",{className:"ag-feedback-card__date",children:z(s.created_at)})]}),e.jsx("div",{className:"ag-feedback-card__score ag-feedback-card__score--desktop",children:e.jsx(N,{score:s.score,dark:!0})})]})}function D({gameId:s,hasUserFeedback:a,onAddFeedback:t}){const{feedbacks:r,isLoading:c,hasNextPage:o,loadNextPage:i}=R(s),{userLogged:u}=S();return!c&&r.length===0?e.jsxs("div",{className:"ag-feedback-list",children:[e.jsx("h2",{className:"ag-feedback-list__title",children:"L'avis des lecteurs"}),e.jsx("p",{className:"ag-feedback-list__empty",children:"Soyez le premier a donner votre avis sur le jeu !"})]}):e.jsxs("div",{className:"ag-feedback-list",children:[e.jsx("h2",{className:"ag-feedback-list__title",children:"L'avis des lecteurs"}),r.length>0&&e.jsxs("div",{className:"ag-feedback-list__container",children:[e.jsx("div",{className:"ag-feedback-list__content",children:r.map(l=>e.jsx(B,{feedback:l},l.id))}),o&&!c&&e.jsx("button",{className:"ag-feedback-list__more",type:"button",onClick:i,children:"Voir plus d'avis"}),c&&e.jsx("div",{className:"ag-feedback-list__spinner"}),e.jsxs("div",{className:"ag-feedback-list__action",children:[u&&!a&&e.jsx(x,{content:e.jsxs(e.Fragment,{children:[e.jsx(F,{"aria-hidden":"true"})," ","Partagez votre avis"]}
1),variant:"red",bold:!0,uppercase:!1,onClick:t}),!u&&e.jsx(x,{content:"Se connecter pour laisser un avis",variant:"red",bold:!0,uppercase:!1,link:"/login"})]})]}),c&&r.length===0&&e.jsx("div",{className:"ag-feedback-list__spinner"})]})}const y=140;function G({gameId:s,onClose:a,onSubmitted:t}){const{submitFeedback:r,isSubmitting:c,error:o}=w(s),[i,u]=n.useState(5),[l,b]=n.useState(""),[h,g]=n.useState([]),m=l.length;function _(){const d=[];return l.length<y&&d.push("Votre critique doit faire au moins 140 caracteres."),g(d),d.length===0}async function p(d){if(d.preventDefault(),!_())return;await r(i,l)&&(t(),a())}return e.jsxs("div",{className:"ag-feedback-form",children:[e.jsxs("div",{className:"ag-feedback-form__header",children:[e.jsx("h2",{className:"ag-feedback-form__title",children:"Donner votre avis"}),e.jsx("button",{type:"button",className:"ag-feedback-form__close",onClick:a,children:e.jsx(P,{"aria-hidden":"true"})})]}),e.jsxs("form",{className:"ag-feedback-form__body",onSubmit:p,children:[e.jsxs("div",{className:"ag-feedback-form__field",children:[e.jsx("label",{className:"ag-feedback-form__label",htmlFor:"ag-fb-score",children:"Notez le jeu sur 10"}),e.jsxs("div",{className:"ag-feedback-form__score-select",children:[e.jsx("select",{id:"ag-fb-score",value:i,onChange:d=>{u(Number(d.target.value)),g([])},children:Array.from({length:11},(d,f)=>e.jsx("option",{value:f,children:f},f))}),e.jsx("span",{children:"/ 10"})]})]}),e.jsxs("div",{className:"ag-feedback-form__field",children:[e.jsx("label",{className:"ag-feedback-form__label",htmlFor:"ag-fb-review",children:"Ecrivez votre critique"}),e.jsxs("div",{className:"ag-feedback-form__review",children:[e.jsx("textarea",{id:"ag-fb-review",value:l,rows:10,cols:30,onChange:d=>{b(d.target.value),g([])}}),e.jsxs("span",{className:m>=y?"ag-feedback-form__chars--ok":"ag-feedback-form__chars--error",children:["Nombre de caracteres : ",m]})]}),h.map(d=>e.jsx("p",{className:"ag-feedback-form__error",children:d},d)),o&&e.jsx("p",{className:"ag-feedback-form__error",children:"Une erreur est survenue lors de l'envoi de votre avis. Veuillez reessayer."})]}),e.jsx(x,{content:c?"Envoi en cours...":"Partagez votre avis",type:"submit",variant:"red",bold:!0,uppercase:!1,disabled:c,classes:"ag-feedback-form__submit"}),e.jsx("p",{className:"ag-feedback-form__legal",children:e.jsx("small",{children:"Ne pas diffuser des informations ou contenus contrevenant aux droits d'autrui ou a caractere diffamatoire, injurieux, obscene, offensant, violent ou incitant a la violence, politique, raciste ou xenophobe et de maniere generale tout contenu contraire a l'objet d'Actugaming.net, aux lois et reglements en vigueur ou aux bonnes moeurs."})})]})]})}function Q({gameId:s=0}){const{hasUserFeedback:a,checkUserFeedback:t}=w(s),[r,c]=n.useState(!1);return s?r?e.jsx(G,{gameId:s,onClose:()=>c(!1),onSubmitted:t}):e.jsxs("div",{className:"ag-feedbacks",children:[e.jsx(U,{gameId:s,hasUserFeedback:a,onAddFeedback:()=>c(!0)}),e.jsx(D,{gameId:s,hasUserFeedback:a,onAddFeedback:()=>c(!0)})]}):null}export{Q as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.