"use strict";var e=require("@gem-sdk/core"),t=require("react");exports.useDropdownSwatches=n=>{let{option:r,variantGroup:a,variants:i,initValue:l,hasPreSelected:s,presetConfiguration:u}=n,{setSelectedOption:c,forceSelectedOption:o,selectedOptions:d}=e.useSelectedOption(),f=e.useProduct(),p=t.useMemo(()=>{if(!u)return;let{presets:e,optionType:t}=u;return e?.[t||"rectangle_list"]},[u]),[v,y]=t.useState(s?l:"blank");t.useEffect(()=>{y(d?.[r?.name??"blank"])},[d,r]),t.useEffect(()=>{s||y("blank")},[s]);let g=t=>{let n=i?.find(e=>e?.id===t);if(n&&n.selectedOptions){let t=e.parseSelectedOption(n.selectedOptions);t&&o(t,f?.id,!1,!0)}};return{value:v,preset:p,handleOnChangeSelect:e=>{a?g(e.target?.value):c(r?.name,e.target?.value,f?.id)},checkVariantInStock:e=>!!e&&(e?.inventoryQuantity&&e.inventoryQuantity>0||!e?.manageInventory||"CONTINUE"===e.inventoryPolicy)}};
