'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),React=require("react"),useStockCounterInteraction=require("../hooks/useStockCounterInteraction.js"),system=require("@gem-sdk/system"),useStockCounter=require("../hooks/useStockCounter.js"),helpers=require("../common/helpers.js"),classes=require("../common/classes.js"),styles=require("../common/styles.js"),attrs=require("../common/attrs.js");const StockCounter=({setting:e,styles:s,builderProps:t})=>{let{displayProgressBar:r,borderRadius:l}=s??{},{showIcon:a,icon:c,layout:n="full",oosIcon:u}=e??{},{outputMessage:o,isOutOfStock:i,inventoryQuantity:m,shouldHideCounter:y}=useStockCounter.useStockCounter(e,s),j=React.useRef(null),{dispatchStockCounterInteraction:x}=useStockCounterInteraction.useStockCounterInteraction({element:j,uid:t?.uid}),C=helpers.getInlineCss(t?.uid,l),S=!1!==r&&!i,d="progress-bar"!==n,g=system.createClass({...classes.getProgressBarClasses(s)}),p=system.createStyle({...styles.getProgressBarStyles(s,e)}),I=system.createStyle({...styles.getContainerStyles(s)}),R=system.createClass({...classes.getContainerClasses(e)}),h=system.createStyle({...styles.getWrapperStyles(s)}),k=system.createClass({...classes.getWrapperIconClasses(e)}),N=system.createClass({...classes.getIconClasses()}),_=system.createClass({...classes.getOuterIconClasses()}),f=t=>system.createStyle({...styles.getIconStyles(s,e,t)}),q=({isOutOfStockIcon:e,isVisible:s})=>system.createAttr({...attrs.getIconAttrs(e,s)}),v=system.createClass({...classes.getTextClasses(s)}),O=e=>system.createStyle({...styles.getTextStyles(s,e)}),T=system.createClass({...classes.getWrapperClasses(e,i)}),M=system.createAttr({...attrs.getWrapperAttrs(t)});return(React.useEffect(()=>{x(m)},[m]),y)?null:jsxRuntime.jsxs("div",{...M,style:h,ref:j,className:T,children:[jsxRuntime.jsx("style",{children:C}),jsxRuntime.jsxs("div",{className:R,style:I,children:[jsxRuntime.jsxs("div",{className:k,children:[a&&(i?jsxRuntime.jsx("div",{...q({isOutOfStockIcon:i,isVisible:i}),style:f(!0),className:_,children:jsxRuntime.jsx("span",{className:N,dangerouslySetInnerHTML:{__html:u||""}})}):jsxRuntime.jsx("div",{...q({isOutOfStockIcon:!i,isVisible:!i}),style:f(!1),className:_,children:jsxRuntime.jsx("span",{className:N,dangerouslySetInnerHTML:{__html:c||""}})})),d&&(i?jsxRuntime.jsx("p",{dangerouslySetInnerHTML:{__html:o()},className:v,style:O(!0)}):jsxRuntime.jsx("p",{dangerouslySetInnerHTML:{__html:o()},className:v,style:O(!1)}))]}),S&&jsxRuntime.jsx("div",{style:p,className:g})]})]})};exports.default=StockCounter;
