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