'use client';
import{jsx as e,jsxs as p,Fragment as t}from"react/jsx-runtime";import{useSelectedOption as a,useProduct as n,makeStyleResponsive as l,makeWidth as i,parseSelectedOption as r}from"@gem-sdk/core";import o from"./DropdownOption.js";import{useMemo as g,useState as s,useEffect as d}from"react";import c from"./VariantOption.js";let m=({option:m,optionPosition:u,optionNumber:x,variantGroup:h,variants:f,price:v,blankText:w,combineWidth:b,combineFullWidth:N,label:y,initValue:k,hasPreSelected:O,soldOutStyle:j,soldOutMark:P,preset:C})=>{let{setSelectedOption:D,forceSelectedOption:I,selectedOptions:M}=a(),Q=n(),S=g(()=>"Disable"===j&&P,[j,P]),V=e=>{let p=f?.find(p=>p?.id===e);if(p&&p.selectedOptions){let e=r(p.selectedOptions);e&&I(e,Q?.id)}},[W,_]=s(O?k:"blank");d(()=>{_(M?.[m?.name??"blank"])},[M,m]),d(()=>{O||_("blank")},[O]);let B=e=>!!e&&(e?.inventoryQuantity&&e.inventoryQuantity>0||!e?.manageInventory||"CONTINUE"===e.inventoryPolicy),E=g(()=>h?l("w",i(b,N)):l("w",i(C?.width,C?.fullWidth)),[C?.width,C?.fullWidth,h,b,N]);return e("div",{className:"gp-grid gp-w-full gp-gap-y-[9px] gp-leading-[1.3]",style:{...E},children:p("div",{className:"gp-relative",children:[e("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:e("span",{className:"gp-max-w-full",children:e("span",{className:"gp-block gp-overflow-hidden",children:y})})}),e("select",{autoComplete:"off",name:m?.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:W??k,onChange:e=>{h?V(e.target?.value):D(m?.name,e.target?.value,Q?.id)},children:p(t,{children:[!O&&e("option",{value:"blank",children:w??"Please select an option"}),m?.values?.map(p=>e(o,{value:p,optionName:m.name,optionPosition:u,optionNumber:x,isSoldOutMark:S},p?.id)),h&&f?.map(p=>e(c,{disabled:!B(p)&&S,value:p?.id,variant:p,includePrice:v},p?.id))]})}),e("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:e("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:e("path",{d:"M0 5h20L10 15"})})})]})})};export{m as default};
