import{x as E,y as T,W as B,a6 as J,z as K,aX as Q,d as U,ad as W,Q as j,aY as q,i as u,al as x,Y as G,J as N,T as L,K as O}from"./index.afa1b71c.js";import{u as Z}from"./use-refs.fee02e7b.js";const[$,d]=E("rate");function p(a,l,o,i){return a>=l?{status:"full",value:1}:a+.5>=l&&o&&!i?{status:"half",value:.5}:a+1>=l&&o&&i?{status:"half",value:Math.round((a-l+1)*1e10)/1e10}:{status:"void",value:0}}const aa={size:T,icon:B("star"),color:String,count:J(5),gutter:T,readonly:Boolean,disabled:Boolean,voidIcon:B("star-o"),allowHalf:Boolean,voidColor:String,touchable:K,iconPrefix:String,modelValue:Q(0),disabledColor:String};var ea=U({name:$,props:aa,emits:["change","update:modelValue"],setup(a,{emit:l}){const o=W(),[i,h]=Z(),v=()=>a.readonly||a.disabled||!a.touchable,X=j(()=>Array(+a.count).fill("").map((e,t)=>p(a.modelValue,t+1,a.allowHalf,a.readonly)));let s;const b=()=>{const e=i.value.map(L);s=[],e.forEach((t,n)=>{a.allowHalf?s.push({score:n+.5,left:t.left},{score:n+1,left:t.left+t.width/2}):s.push({score:n+1,left:t.left})})},g=e=>{for(let t=s.length-1;t>0;t--)if(e>s[t].left)return s[t].score;return a.allowHalf?.5:1},y=e=>{!a.disabled&&!a.readonly&&e!==a.modelValue&&(l("update:modelValue",e),l("change",e))},F=e=>{v()||(o.start(e),b())},M=e=>{if(!v()&&(o.move(e),o.isHorizontal())){const{clientX:t}=e.touches[0];x(e),y(g(t))}},Y=(e,t)=>{const{icon:n,size:P,color:R,count:S,gutter:V,voidIcon:C,disabled:r,voidColor:k,allowHalf:w,iconPrefix:z,disabledColor:H}=a,f=t+1,m=e.status==="full",c=e.status==="void",_=w&&e.value>0&&e.value<1;let I;V&&f!==+S&&(I={paddingRight:G(V)});const A=D=>{b(),y(w?g(D.clientX):f)};return u("div",{key:t,ref:h(t),role:"radio",style:I,class:d("item"),tabindex:r?void 0:0,"aria-setsize":S,"aria-posinset":f,"aria-checked":!c,onClick:A},[u(N,{size:P,name:m?n:C,class:d("icon",{disabled:r,full:m}),color:r?H:m?R:k,classPrefix:z},null),_&&u(N,{size:P,style:{width:e.value+"em"},name:c?C:n,class:d("icon",["half",{disabled:r,full:!c}]),color:r?H:c?k:R,classPrefix:z},null)])};return q(()=>a.modelValue),()=>u("div",{role:"radiogroup",class:d({readonly:a.readonly,disabled:a.disabled}),tabindex:a.disabled?void 0:0,"aria-disabled":a.disabled,"aria-readonly":a.readonly,onTouchstart:F,onTouchmove:M},[X.value.map(Y)])}});const oa=O(ea);export{oa as R};
