import{withInstall as e}from"../_util/type.mjs";import t from"../_util/classNames.mjs";import n from"../_util/props-util/initDefaultProps.mjs";import{findDOMNode as r}from"../_util/props-util/index.mjs";import i from"../config-provider/hooks/useConfigInject.mjs";import a from"../_util/vue-types/index.mjs";import{useInjectFormItemContext as o}from"../form/FormItemContext.mjs";import s from"../_util/KeyCode.mjs";import c from"../tooltip/index.mjs";import l from"../_util/hooks/useRefs.mjs";import u from"./Star.mjs";import d from"./style/index.mjs";import{getOffsetLeft as f}from"./util.mjs";import{createVNode as p,defineComponent as m,onMounted as h,reactive as g,ref as _,watch as v}from"vue";import{StarFilled as y}from"@antsoo-lib/icons";var b=()=>({prefixCls:String,count:Number,value:Number,allowHalf:{type:Boolean,default:void 0},allowClear:{type:Boolean,default:void 0},tooltips:Array,disabled:{type:Boolean,default:void 0},character:a.any,autofocus:{type:Boolean,default:void 0},tabindex:a.oneOfType([a.number,a.string]),direction:String,id:String,onChange:Function,onHoverChange:Function,"onUpdate:value":Function,onFocus:Function,onBlur:Function,onKeydown:Function}),x=e(m({compatConfig:{MODE:3},name:`ARate`,inheritAttrs:!1,props:n(b(),{value:0,count:5,allowHalf:!1,allowClear:!0,tabindex:0,direction:`ltr`}),setup(e,{slots:n,attrs:a,emit:m,expose:b}){let{prefixCls:x,direction:S}=i(`rate`,e),[C,w]=d(x),T=o(),E=_(),[D,O]=l(),k=g({value:e.value,focused:!1,cleanedValue:null,hoverValue:void 0});v(()=>e.value,()=>{k.value=e.value});let A=e=>r(O.value.get(e)),j=(t,n)=>{let r=S.value===`rtl`,i=t+1;if(e.allowHalf){let e=A(t),a=f(e),o=e.clientWidth;(r&&n-a>o/2||!r&&n-a<o/2)&&(i-=.5)}return i},M=t=>{e.value===void 0&&(k.value=t),m(`update:value`,t),m(`change`,t),T.onFieldChange()},N=(e,t)=>{let n=j(t,e.pageX);n!==k.cleanedValue&&(k.hoverValue=n,k.cleanedValue=null),m(`hoverChange`,n)},P=()=>{k.hoverValue=void 0,k.cleanedValue=null,m(`hoverChange`,void 0)},F=(t,n)=>{let{allowClear:r}=e,i=j(n,t.pageX),a=!1;r&&(a=i===k.value),P(),M(a?0:i),k.cleanedValue=a?i:null},I=e=>{k.focused=!0,m(`focus`,e)},L=e=>{k.focused=!1,m(`blur`,e),T.onFieldBlur()},R=t=>{let{keyCode:n}=t,{count:r,allowHalf:i}=e,a=S.value===`rtl`;n===s.RIGHT&&k.value<r&&!a?(i?k.value+=.5:k.value+=1,M(k.value),t.preventDefault()):n===s.LEFT&&k.value>0&&!a||n===s.RIGHT&&k.value>0&&a?(i?k.value-=.5:--k.value,M(k.value),t.preventDefault()):n===s.LEFT&&k.value<r&&a&&(i?k.value+=.5:k.value+=1,M(k.value),t.preventDefault()),m(`keydown`,t)},z=()=>{e.disabled||E.value.focus()};b({focus:z,blur:()=>{e.disabled||E.value.blur()}}),h(()=>{let{autofocus:t,disabled:n}=e;t&&!n&&z()});let B=(t,{index:n})=>{let{tooltips:r}=e;return r?p(c,{title:r[n]},{default:()=>[t]}):t};return()=>{let{count:r,allowHalf:i,disabled:o,tabindex:s,id:c=T.id.value}=e,{class:l,style:d}=a,f=[],m=o?`${x.value}-disabled`:``,h=e.character||n.character||(()=>p(y,null,null));for(let e=0;e<r;e++)f.push(p(u,{ref:D(e),key:e,index:e,count:r,disabled:o,prefixCls:`${x.value}-star`,allowHalf:i,value:k.hoverValue===void 0?k.value:k.hoverValue,onClick:F,onHover:N,character:h,characterRender:B,focused:k.focused},null));let g=t(x.value,m,l,{[w.value]:!0,[`${x.value}-rtl`]:S.value===`rtl`});return C(p(`ul`,{...a,id:c,class:g,style:d,onMouseleave:o?null:P,tabindex:o?-1:s,onFocus:o?null:I,onBlur:o?null:L,onKeydown:o?null:R,ref:E,role:`radiogroup`},[f]))}}}));export{x as default,b as rateProps};