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