"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),O=require("@spark-ui/hooks/use-combined-state"),o=require("../index-DnaHaH_0.js"),p=require("react"),P=require("@spark-ui/icons/StarFill"),D=require("@spark-ui/icons/StarOutline"),S=require("../Icon-Bf0XrmiR.js"),_=o.cx("[&_>_div]:peer-hover:w-0!"),F=o.cva(["peer","after:inset-0","group","relative","after:block after:absolute"],{variants:{disabled:{true:"opacity-dim-3",false:""},readOnly:{true:"",false:""},gap:{sm:["after:w-[calc(100%+(var(--spacing-sm)))]","last-of-type:after:content-none"],md:["after:w-[calc(100%+(var(--spacing-md)))]","last-of-type:after:content-none"]}},compoundVariants:[{readOnly:!1,disabled:!1,className:o.cx(_,"cursor-pointer")}],defaultVariants:{disabled:!1,readOnly:!1,gap:"sm"}}),y=o.cva("",{variants:{size:{sm:"text-caption-link",md:"text-body-1",lg:"text-display-1"},design:{filled:["text-main-variant","group-[[data-part=star][data-hovered]]:text-main-variant-hovered"],outlined:["text-on-surface/dim-3"]}}}),H=({value:e,size:a,disabled:s,readOnly:n,onClick:c,onMouseEnter:i,ref:m})=>r.jsxs("div",{"data-spark-component":"rating-star",ref:m,onMouseEnter:i,className:F({gap:a==="lg"?"md":"sm",disabled:s,readOnly:n}),"data-part":"star",onClick:c,children:[r.jsx("div",{className:o.cx("z-raised absolute overflow-hidden","group-[[data-part=star][data-hovered]]:overflow-visible"),style:{width:e*100+"%"},children:r.jsx(S.Icon,{className:y({size:a,design:"filled"}),children:r.jsx(P.StarFill,{})})}),r.jsx(S.Icon,{className:y({size:a,design:"outlined"}),children:r.jsx(D.StarOutline,{})})]});function R(e){return Math.round(e/.5)*.5}function L({value:e,index:a}){if(e===void 0)return 0;const s=a+1,n=R(e);return Math.ceil(n)<s?0:n>=s?1:.5}function B(e,a){const s=e.slice(0,a),n=e.slice(a);return[s,n]}const T=({defaultValue:e,value:a,onValueChange:s,size:n="md",disabled:c,readOnly:i,name:m,id:N,"aria-label":j,ref:k,...A})=>{const u=p.useRef(null),f=p.useRef([]),[v,b]=O.useCombinedState(a,e,s),g=p.useRef(v),h=!(c||i);function I(t){u.current&&(b(t+1),g.current=t+1,u.current.focus(),u.current.setAttribute("data-clicked",""))}function w(t){g.current===Number(t.target.value)||Number(t.target.value)===0||(g.current=Number(t.target.value),b(Number(t.target.value)))}function C({currentTarget:t}){const l=f.current.findIndex(d=>d===t),[x,V]=B(f.current,l+1);x.forEach(d=>d.setAttribute("data-hovered","")),V.forEach(d=>d.removeAttribute("data-hovered"))}const q=p.useCallback(t=>{t&&f.current.push(t)},[]);function M(){u.current?.removeAttribute("data-clicked")}function E(){f.current.forEach(t=>t.removeAttribute("data-hovered"))}return r.jsxs("div",{className:"relative inline-flex",ref:k,"data-spark-component":"rating",...A,onMouseLeave:E,children:[r.jsx("input",{name:m,id:N,"aria-label":j,ref:u,"data-part":"input",className:"peer absolute inset-0 opacity-0",type:"range",min:"0",max:"5",step:i?.5:1,disabled:c,readOnly:i,value:R(v??0),onChange:t=>h&&w(t),onBlur:M}),r.jsx("div",{className:o.cx(n==="lg"?"gap-x-md":"gap-x-sm","flex","peer-focus-visible:u-outline peer-[[data-part=input][data-clicked]]:shadow-none"),children:Array.from({length:5}).map((t,l)=>r.jsx(H,{disabled:c,readOnly:i,size:n,onClick:()=>h&&I(l),onMouseEnter:x=>h&&C(x),ref:q,value:L({index:l,value:v})},l))})]})};exports.Rating=T;
//# sourceMappingURL=index.js.map
