import{j as e}from"./chunks/jsx-runtime.js?ver=1.7.1";import{b as i}from"./chunks/BlockEditorTranslator.js?ver=1.7.1";import{E}from"./chunks/EditorPanel.js?ver=1.7.1";import{E as P}from"./chunks/EditorPanelRow.js?ver=1.7.1";import{R as S,u as H,a as M}from"./chunks/reviewBlockShared.js?ver=1.7.1";import{o as I,R as q}from"./chunks/Icons.js?ver=1.7.1";import"./chunks/SelectProductModal.js?ver=1.7.1";import"./chunks/index6.js?ver=1.7.1";import"./chunks/ProductListItem.js?ver=1.7.1";import"./chunks/index5.js?ver=1.7.1";import"./chunks/add-query-args.js?ver=1.7.1";import"./chunks/SingleProductContext.js?ver=1.7.1";import"./chunks/reviewStar2.js?ver=1.7.1";const{InspectorControls:A}=wp.blockEditor,{__experimentalNumberControl:_}=wp.components,B=({attributes:r,setAttributes:s,selectedProduct:l,setSelectedProduct:p,insideParent:d})=>e.jsx(A,{children:e.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card fct-inspector-control-wrap--product-rating",children:e.jsx("div",{className:"fct-inspector-control-group",children:e.jsxs("div",{className:"fct-inspector-control-body",children:[!d&&e.jsx(S,{attributes:r,setAttributes:s,selectedProduct:l,setSelectedProduct:p}),e.jsx(E,{title:i("Visibility"),children:e.jsxs(P,{className:"flex-col",children:[e.jsx(_,{label:i("Minimum Reviews"),help:i("Hide the rating until the product has at least this many reviews. 0 always shows it, including five empty stars on a product with none."),value:r.minReviewCount,min:0,step:1,onChange:n=>{const t=parseInt(n,10);s({minReviewCount:isNaN(t)||t<0?0:t})}}),e.jsx(_,{label:i("Minimum Average Rating"),help:i("Hide the rating unless the product averages at least this many stars. 0 shows every rating. Half stars are allowed."),value:r.minAverageRating,min:0,max:5,step:.5,onChange:n=>{const t=parseFloat(n);if(isNaN(t)||t<0){s({minAverageRating:0});return}s({minAverageRating:Math.min(5,t)})}})]})})]})})})}),{useBlockProps:F}=wp.blockEditor,{registerBlockType:z}=wp.blocks,o=window.fluent_cart_product_rating_data;z(o.slug+"/"+o.name,{apiVersion:3,title:o.title,description:o.description,icon:{src:I},category:"fluent-cart",attributes:{query_type:{type:"string",default:"default"},product_id:{type:["string","number"],default:""},minReviewCount:{type:"number",default:0},minAverageRating:{type:"number",default:0}},edit:({attributes:r,setAttributes:s,clientId:l})=>{var v,w,x,y;const p=F({className:"fct-product-rating-block-editor"}),d=!!o.reviews_active,n=H(l),{selectedProduct:t,setSelectedProduct:N}=M(r,n,!1);wp.element.useEffect(()=>{n&&r.query_type!=="default"&&s({query_type:"default"})},[n,r.query_type]);const u=((w=(v=t==null?void 0:t.detail)==null?void 0:v.other_info)==null?void 0:w.average_rating)||0,f=((y=(x=t==null?void 0:t.detail)==null?void 0:x.other_info)==null?void 0:y.review_count)||0,C=c=>{const R=[];for(let a=1;a<=5;a++){const j=a<=Math.floor(c),b=!j&&a===Math.floor(c)+1&&c-Math.floor(c)>=.5;let m="fct-star fct-star-empty";j?m="fct-star fct-star-filled":b&&(m="fct-star fct-star-half"),R.push(e.jsx("span",{className:m,children:e.jsx(q,{})},a))}return R},h=parseInt(r.minReviewCount,10)||0,g=parseFloat(r.minAverageRating)||0,k=h>0&&f0&&u