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