'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),core=require("@gem-sdk/core"),DropdownOption=require("./DropdownOption.js"),React=require("react"),VariantOption=require("./VariantOption.js");const DropdownVariant=({option:e,optionPosition:t,optionNumber:n,variantGroup:p,variants:a,price:i,blankText:s,combineWidth:r,combineFullWidth:o,label:l,initValue:d,hasPreSelected:g,soldOutStyle:u,soldOutMark:c,preset:x})=>{let{setSelectedOption:m,forceSelectedOption:j,selectedOptions:h}=core.useSelectedOption(),v=core.useProduct(),w=React.useMemo(()=>"Disable"===u&&c,[u,c]),f=e=>{let t=a?.find(t=>t?.id===e);if(t&&t.selectedOptions){let e=core.parseSelectedOption(t.selectedOptions);e&&j(e,v?.id)}},[R,b]=React.useState(g?d:"blank");React.useEffect(()=>{b(h?.[e?.name??"blank"])},[h,e]),React.useEffect(()=>{g||b("blank")},[g]);let y=e=>!!e&&(e?.inventoryQuantity&&e.inventoryQuantity>0||!e?.manageInventory||"CONTINUE"===e.inventoryPolicy),O=React.useMemo(()=>p?core.makeStyleResponsive("w",core.makeWidth(r,o)):core.makeStyleResponsive("w",core.makeWidth(x?.width,x?.fullWidth)),[x?.width,x?.fullWidth,p,r,o]);return jsxRuntime.jsx("div",{className:"gp-grid gp-w-full gp-gap-y-[9px] gp-leading-[1.3]",style:{...O},children:jsxRuntime.jsxs("div",{className:"gp-relative",children:[jsxRuntime.jsx("label",{className:"!gp-max-w-[calc(100%_-_66px)] gp-absolute gp-left-[12px] gp-top-[6px] gp-p-0 gp-text-xs gp-leading-[1.3] gp-text-[#737373] gp-transition-[top]",children:jsxRuntime.jsx("span",{className:"gp-max-w-full",children:jsxRuntime.jsx("span",{className:"gp-block gp-overflow-hidden",children:l})})}),jsxRuntime.jsx("select",{autoComplete:"off",name:e?.name||"Select Option",className:"gp-min-h-[47px] gp-appearance-none gp-bg-transparent gp-w-full gp-whitespace-nowrap gp-rounded-[5px] gp-border gp-border-[#d9d9d9] gp-pb-[6px] gp-pl-[11px] gp-pr-[40px] gp-pt-[21px] gp-text-[14px] gp-outline-none gp-text-[#545454]",value:R??d,onChange:t=>{p?f(t.target?.value):m(e?.name,t.target?.value,v?.id)},children:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!g&&jsxRuntime.jsx("option",{value:"blank",children:s??"Please select an option"}),e?.values?.map(p=>jsxRuntime.jsx(DropdownOption.default,{value:p,optionName:e.name,optionPosition:t,optionNumber:n,isSoldOutMark:w},p?.id)),p&&a?.map(e=>jsxRuntime.jsx(VariantOption.default,{disabled:!y(e)&&w,value:e?.id,variant:e,includePrice:i},e?.id))]})}),jsxRuntime.jsx("div",{className:"gp-pointer-events-none gp-absolute gp-right-[2px] gp-top-[50%] gp-flex gp-h-[43%] gp-w-[40px] gp-translate-y-[-50%] gp-items-center gp-justify-center gp-border-l-[1px] gp-bg-white gp-border-[#545454]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",focusable:"false","aria-hidden":"true",role:"presentation",className:"gp-h-[10px] gp-w-[10px]",children:jsxRuntime.jsx("path",{d:"M0 5h20L10 15"})})})]})})};exports.default=DropdownVariant;
