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