import{r as m,j as l,F as g,a as t}from"./index.9be5fb1a.js";import"./ecb79917.js";import{A as L}from"./03bd6320.js";import{u as C}from"./d6f9a9e9.js";import"./d060b8a3.js";import"./f84d33f8.js";import"./a36cb30c.js";import{u as P}from"./4a28fcdf.js";import"./097174ad.js";import"./1cfd448b.js";import"./a5033887.js";import"./119338b3.js";import{u as I,H as U,b as k,c as D}from"./c215153d.js";import"./3245d962.js";import{C as R}from"./2df72d26.js";import{T as A}from"./ddcb701d.js";import"./0ddb42b7.js";/* empty css */import{P as f}from"./8c18c7d5.js";import"./ac04e32d.js";import"./3fd5546a.js";import"./30205710.js";import"./0f2fb15a.js";import"./133c3a40.js";import"./88f224b7.js";import"./cb49fc6a.js";import"./92add5bc.js";import"./8bc5270c.js";import"./2e4f433f.js";import"./31dfd9ab.js";import"./a5164085.js";import"./391fa51f.js";import"./66d5f687.js";import"./fc0e79f7.js";import"./c05ec191.js";import"./fd5caeb3.js";function F(){return typeof document!="undefined"}function xt(){var x,O;const{pathname:n,search:r}=P(),[e,u]=m.exports.useState(new URLSearchParams(r)),{options:s,setSelectedOption:a,selectedOptions:p,selectedVariant:o}=C(),d=!(o!=null&&o.availableForSale)||!1;((x=o==null?void 0:o.priceV2)==null?void 0:x.amount)<((O=o==null?void 0:o.compareAtPriceV2)==null?void 0:O.amount),m.exports.useEffect(()=>{e||!r||u(new URLSearchParams(r))},[e,r]),m.exports.useEffect(()=>{s.map(({name:i,values:c})=>{if(!e)return;const y=e.get(i.toLowerCase())||null;if(y){const S=c.filter($=>encodeURIComponent($.toLowerCase())===y);a(i,S[0])}else e.set(encodeURIComponent(i.toLowerCase()),encodeURIComponent(p[i].toLowerCase())),window.history.replaceState(null,"",`${n}?${e.toString()}`)})},[]);const h=m.exports.useCallback((i,c)=>{a(i,c),e&&(e.set(encodeURIComponent(i.toLowerCase()),encodeURIComponent(c.toLowerCase())),F()&&window.history.replaceState(null,"",`${n}?${e.toString()}`))},[a,e,n]),{isOpen:b,openDrawer:w,closeDrawer:N}=I();return l(g,{children:[l("form",{className:"grid md:gap-10",children:[t("div",{className:"grid gap-4",children:s.map(({name:i,values:c})=>c.length===1?null:l("div",{className:"flex flex-col flex-wrap mb-4 gap-y-2 last:mb-0",children:[t(U,{as:"legend",size:"lead",className:"min-w-[4rem]",children:i}),t("div",{className:"flex flex-wrap items-baseline gap-4",children:t(T,{name:i,handleChange:h,values:c})})]},i))}),t("div",{className:"grid items-stretch gap-4",children:t(L,{variantId:o==null?void 0:o.id,quantity:1,accessibleAddingToCartLabel:"Adding item to your cart",disabled:d,type:"button",onClick:w,children:t("span",{className:`${d?"btn btn-sec":"btn btn-prim"} w-full`,children:d?t("span",{className:"btn-padding disabled:cursor-not-allowed",disabled:!0,children:"Sold out"}):t("span",{className:"btn-padding",children:"Add to bag"})})})})]}),t(R,{isOpen:b,onClose:N})]})}function T({values:n,...r}){return n.length>7?t(B,{values:n,...r}):t(j,{values:n,...r})}function j({values:n,name:r,handleChange:e}){const{selectedOptions:u}=C();return t(g,{children:n.map(s=>{const a=u[r]===s,p=`option-${r}-${s}`;return l(A,{as:"label",htmlFor:p,children:[t("input",{className:"sr-only",type:"radio",id:p,name:`option[${r}]`,value:s,checked:a,onChange:()=>e(r,s)}),t("div",{className:`leading-none py-1 border-b-[1px] cursor-pointer transition-all duration-200 ${a?"border-primary/50":"border-primary/0"}`,children:s})]},p)})})}function B({values:n,name:r,handleChange:e}){const[u,s]=m.exports.useState(!1),{selectedOptions:a}=C(),p=m.exports.useCallback(o=>{e(r,o)},[r,e]);return t("div",{className:"relative w-full",children:t(f,{onChange:p,value:"",children:({open:o})=>(setTimeout(()=>s(o)),l(g,{children:[l(f.Button,{className:`${o?"rounded-b md:rounded-t md:rounded-b-none":"rounded"}`,children:[t("span",{children:a[r]}),t(k,{direction:o?"up":"down"})]}),t(f.Options,{className:`border-primary bg-contrast absolute bottom-12 z-30 grid h-48 w-full overflow-y-scroll rounded-t border px-2 py-2 transition-[max-height] duration-150 sm:bottom-auto md:rounded-b md:rounded-t-none md:border-t-0 md:border-b ${u?"max-h-48":"max-h-0"}`,children:n.map(d=>{const h=a[r]===d,b=`option-${r}-${d}`;return t(f.Option,{value:d,children:({active:w})=>l("div",{className:`text-black w-full p-2 transition rounded flex justify-start items-center text-left cursor-pointer ${w?"bg-primary/10":null}`,children:[d,h?t("span",{className:"ml-2",children:t(D,{})}):null]})},b)})})]}))})})}export{xt as ProductForm}; //# sourceMappingURL=32a43f70.js.map