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