| 1 |
import{j as e}from"./chunks/jsx-runtime.js?ver=1.7.0";import{b as i}from"./chunks/BlockEditorTranslator.js?ver=1.7.0";import{E as x}from"./chunks/EditorPanel.js?ver=1.7.0";import{E as h}from"./chunks/EditorPanelRow.js?ver=1.7.0";import{R as j,u as g,a as N}from"./chunks/reviewBlockShared.js?ver=1.7.0";import{s as _}from"./chunks/Icons.js?ver=1.7.0";import"./chunks/SelectProductModal.js?ver=1.7.0";import"./chunks/index6.js?ver=1.7.0";import"./chunks/ProductListItem.js?ver=1.7.0";import"./chunks/index5.js?ver=1.7.0";import"./chunks/add-query-args.js?ver=1.7.0";import"./chunks/SingleProductContext.js?ver=1.7.0";const{InspectorControls:y}=wp.blockEditor,{ColorPicker:P}=wp.components,E=({attributes:t,setAttributes:a,selectedProduct:c,setSelectedProduct:l,insideParent:o})=>e.jsx(y,{children:e.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card fct-inspector-control-wrap--review-summary",children:e.jsx("div",{className:"fct-inspector-control-group",children:e.jsxs("div",{className:"fct-inspector-control-body",children:[!o&&e.jsx(j,{attributes:t,setAttributes:a,selectedProduct:c,setSelectedProduct:l}),e.jsx(x,{title:i("Star Color"),children:e.jsx(h,{children:e.jsx(P,{color:t.starColor,onChange:r=>a({starColor:r}),enableAlpha:!1})})})]})})})}),C=({hasProductData:t,avgRating:a,reviewCount:c,ratingBreakdown:l,starColor:o})=>t?e.jsxs("div",{className:"fct-reviews-block-real-summary",children:[e.jsxs("div",{className:"fct-reviews-block-real-average",children:[e.jsx("span",{className:"fct-reviews-block-real-average-number",children:a||0}),e.jsx("span",{className:"fct-reviews-block-real-average-max",children:"/5"})]}),e.jsx("div",{className:"fct-reviews-block-real-stars",children:[1,2,3,4,5].map(r=>e.jsx("span",{style:{color:r<=Math.round(a)?o:"#d1d5db"},children:"� |
| 2 |
"},r))}),e.jsxs("div",{className:"fct-reviews-block-real-total",children:[i("Based on")," ",c," ",c===1?i("review"):i("reviews")]}),e.jsx("div",{className:"fct-reviews-block-real-bars",children:[5,4,3,2,1].map(r=>{const n=parseInt(l[r],10)||0,s=c>0?Math.round(n/c*100):0;return e.jsxs("div",{className:"fct-reviews-block-real-bar-row",children:[e.jsxs("span",{className:"fct-reviews-block-real-bar-label",children:[r," � |
| 3 |
"]}),e.jsx("div",{className:"fct-reviews-block-skeleton-bar-track",children:e.jsx("div",{className:"fct-reviews-block-real-bar-fill",style:{width:`${s}%`,background:o}})}),e.jsx("span",{className:"fct-reviews-block-real-bar-count",children:n})]},r)})})]}):e.jsxs("div",{className:"fct-reviews-block-skeleton-aside",children:[e.jsx("div",{className:"fct-reviews-block-skeleton-score"}),e.jsx("div",{className:"fct-reviews-block-skeleton-line is-short"}),[5,4,3,2,1].map(r=>e.jsxs("div",{className:"fct-reviews-block-skeleton-bar-row",children:[e.jsx("div",{className:"fct-reviews-block-skeleton-bar-label"}),e.jsx("div",{className:"fct-reviews-block-skeleton-bar-track"})]},r))]}),{useBlockProps:I}=wp.blockEditor,{registerBlockType:R}=wp.blocks,{useEffect:B}=wp.element,d=window.fluent_cart_product_review_summary_data;R(d.slug+"/"+d.name,{apiVersion:3,title:d.title,description:d.description,icon:{src:_},category:"fluent-cart",attributes:{query_type:{type:"string",default:"default"},product_id:{type:["string","number"],default:""},starColor:{type:"string",default:"#f59e0b"}},edit:({attributes:t,setAttributes:a,clientId:c})=>{var f;const l=I({className:"fct-review-summary-block-editor"}),o=g(c),{selectedProduct:r,setSelectedProduct:n,reviewSummary:s,effectiveProductId:u}=N(t,o,!0);B(()=>{o&&t.query_type!=="default"&&a({query_type:"default"})},[o,t.query_type]);const p=((f=r==null?void 0:r.detail)==null?void 0:f.other_info)||{},v=parseFloat((s==null?void 0:s.average)??p.average_rating)||0,b=parseInt((s==null?void 0:s.total)??p.review_count,10)||0,k=(s==null?void 0:s.breakdown)||p.rating_breakdown||{},w=t.starColor||"#f59e0b",m=!!u&&!!(r!=null&&r.ID);return e.jsxs("div",{...l,children:[e.jsx(E,{attributes:t,setAttributes:a,selectedProduct:r,setSelectedProduct:n,insideParent:o}),e.jsxs("div",{className:"fct-reviews-block-skeleton",children:[e.jsx(C,{hasProductData:m,avgRating:v,reviewCount:b,ratingBreakdown:k,starColor:w}),!m&&!o&&e.jsx("div",{className:"fct-reviews-block-skeleton-caption",children:i("Reviews will be displayed for the current product")})]})]})},save:function(){return null},supports:{html:!1,align:!0,typography:{fontSize:!0,lineHeight:!0,__experimentalFontFamily:!0,__experimentalFontWeight:!0,__experimentalDefaultControls:{fontSize:!0}},color:{text:!0,background:!0},spacing:{margin:!0,padding:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0}}}); |