'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 d,useEffect as s}from"react";import c from"./VariantOption.js";let DropdownVariant=({option:m,optionPosition:u,optionNumber:x,variantGroup:h,variants:w,price:f,blankText:v,combineWidth:b,combineFullWidth:N,label:y,initValue:k,hasPreSelected:O,soldOutStyle:j,soldOutMark:D,preset:P})=>{let{setSelectedOption:C,forceSelectedOption:V,selectedOptions:I}=a(),M=n(),Q=g(()=>"Disable"===j&&D,[j,D]),S=e=>{let p=w?.find(p=>p?.id===e);if(p&&p.selectedOptions){let e=r(p.selectedOptions);e&&V(e,M?.id)}},[W,_]=d(O?k:"blank");s(()=>{_(I?.[m?.name??"blank"])},[I,m]),s(()=>{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(P?.width,P?.fullWidth)),[P?.width,P?.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?S(e.target?.value):C(m?.name,e.target?.value,M?.id)},children:p(t,{children:[!O&&e("option",{value:"blank",children:v??"Please select an option"}),m?.values?.map(p=>e(o,{value:p,optionName:m.name,optionPosition:u,optionNumber:x,isSoldOutMark:Q},p?.id)),h&&w?.map(p=>e(c,{disabled:!B(p)&&Q,value:p?.id,variant:p,includePrice:f},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{DropdownVariant as default};
