"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("../index-DnaHaH_0.js"),d=require("react"),C=d.createContext(null),I=()=>{const e=d.useContext(C);if(!e)throw new Error("useSegmentedGaugeContext must be used within a SegmentedGauge provider");return e},G=({className:e,children:a,ref:t,id:r,...c})=>{const{labelId:n}=I();return s.jsx("span",{"data-spark-component":"segmented-gauge-label","data-testid":"segmented-gauge-label",ref:t,id:r||n,className:x.cx("default:text-on-surface default:text-body-2",e),...c,children:a})};G.displayName="SegmentedGauge.Label";const h=({index:e=0,className:a,children:t,ref:r,...c})=>{const{size:n,intent:g,customColor:o,currentIndex:m}=I(),i=m!==-1&&e<=m,p=m!==-1&&e===m,S=d.useMemo(()=>{if(o)return o;switch(g){case"main":return"var(--color-main)";case"support":return"var(--color-support)";case"basic":return"var(--color-basic)";case"accent":return"var(--color-accent)";case"success":return"var(--color-success)";case"alert":return"var(--color-alert)";case"danger":return"var(--color-error)";case"info":return"var(--color-info)";case"neutral":return"var(--color-neutral)";default:return"var(--color-neutral)"}},[g,o]),j=x.cx("border-outline relative rounded-full",{"h-sz-8 w-sz-24":n==="sm","h-sz-12 w-sz-36":n==="md","default:bg-[var(--gauge-color)]":i,"border-sm bg-surface":!i},a),u=x.cx("absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2","default:bg-surface default:rounded-full","border-[var(--gauge-color)]",{"size-sz-12 border-md":n==="sm","size-sz-20 border-lg":n==="md"});return s.jsxs("div",{"data-spark-component":"segmented-gauge-segment","data-testid":"segmented-gauge-segment","data-active":i,"data-current":p,ref:r,style:{"--gauge-color":S},className:j,...c,children:[t,p&&s.jsx("div",{className:u,"aria-hidden":"true"})]})};h.displayName="SegmentedGauge.Segment";const y=({className:e,children:a,ref:t,...r})=>s.jsx("div",{"data-spark-component":"segmented-gauge-track",ref:t,className:x.cx("gap-sm relative flex rounded-full",e),...r,children:a});y.displayName="SegmentedGauge.Track";const q=(e,a,t,r)=>{if(e==null)return-1;const c=Math.max(a,Math.min(t,e)),g=(t-a)/(r-1),o=(c-a)/g;return Math.max(0,Math.min(r-1,Math.round(o)))},z=({value:e,min:a,max:t,description:r,size:c="md",intent:n="neutral",customColor:g,id:o,"aria-label":m,className:i,ref:p,children:S,...j})=>{const u=t-a+1,l=d.useMemo(()=>q(e,a,t,u),[e,a,t,u]),v=d.useId(),k=d.useId(),f=o||k,N=d.useMemo(()=>Array.from({length:u},(T,b)=>({isActive:l!==-1&&b<=l,isCurrent:l!==-1&&b===l})),[u,l]),w=d.useMemo(()=>({value:e,min:a,max:t,segments:u,currentIndex:l,size:c,intent:n,customColor:g,labelId:v,gaugeId:f}),[e,a,t,u,l,c,n,g,v,f]),L=e!=null?{role:"meter","aria-valuenow":e,"aria-valuemin":a,"aria-valuemax":t}:{role:"status"};return s.jsx(C.Provider,{value:w,children:s.jsx("div",{id:f,"data-spark-component":"segmented-gauge",ref:p,className:x.cx("gap-md flex flex-wrap items-center",i),...L,"aria-labelledby":o?`${f}-label`:void 0,"aria-label":o?void 0:m,"aria-describedby":v,...j,children:S?S({segments:N,currentIndex:l}):s.jsxs(s.Fragment,{children:[s.jsx(y,{children:N.map((T,b)=>s.jsx(h,{index:b},b))}),r&&s.jsx(G,{id:v,children:r})]})})})};z.displayName="SegmentedGauge";const M=Object.assign(z,{Track:y,Segment:h,Label:G});M.displayName="SegmentedGauge";y.displayName="SegmentedGauge.Track";h.displayName="SegmentedGauge.Segment";G.displayName="SegmentedGauge.Label";exports.SegmentedGauge=M;
//# sourceMappingURL=index.js.map
