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