"use strict";var core=require("@gem-sdk/core"),React=require("react"),helpers=require("../common/helpers.js");const useStockCounter=(e,r)=>{let t=core.useEditorMode(),{template:o,outOfStockMessage:s,continueSelling:n,unlimitedQuantityMessage:a}=e??{},{textColor:u}=r??{},i=u||"brand",l=core.useCurrentVariant(),h=React.useMemo(()=>Number(l?l.inventoryQuantity:0),[l]),c=!l||l.manageInventory,T=l?l.inventoryPolicy:"deny",p=c&&h<=helpers.NO_PRODUCT_LEFT&&T!==helpers.CONTINUE_SELLING_WHEN_OUT_OF_STOCK,O=T===helpers.CONTINUE_SELLING_WHEN_OUT_OF_STOCK&&h<=helpers.NO_PRODUCT_LEFT,g=!c&&a;function d(){return g?helpers.transformHighlighTag(a,i):p?helpers.transformHighlighTag(s||"",i):O?helpers.transformHighlighTag(n||"",i):helpers.transformHighlighTag(helpers.transformNumberTag(o||"",i,h),i)}let m=()=>{let e=r?.typo?.attrs?.transform==="capitalize";return e?d()?.toLocaleLowerCase():d()},_=React.useMemo(()=>{if("edit"===t)return!1;let r=!e?.displayByDefault&&h>=(e?.scarcityThreshold??0),o=e?.hiddenCounterWhenOutOfStock&&p;return r||o},[h,p,t,e?.displayByDefault,e?.hiddenCounterWhenOutOfStock,e?.scarcityThreshold]);return{outputMessage:m,isOutOfStock:p,inventoryQuantity:h,shouldHideCounter:_}};exports.useStockCounter=useStockCounter;
