var __awaiter=this&&this.__awaiter||function(t,a,e,n){function i(t){return t instanceof e?t:new e((function(a){a(t)}))}return new(e||(e=Promise))((function(e,r){function o(t){try{c(n.next(t))}catch(t){r(t)}}function s(t){try{c(n["throw"](t))}catch(t){r(t)}}function c(t){t.done?e(t.value):i(t.value).then(o,s)}c((n=n.apply(t,a||[])).next())}))};var __generator=this&&this.__generator||function(t,a){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,i,r,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(t){return function(a){return c([t,a])}}function c(o){if(n)throw new TypeError("Generator is already executing.");while(e)try{if(n=1,i&&(r=o[0]&2?i["return"]:o[0]?i["throw"]||((r=i["return"])&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;if(i=0,r)o=[o[0]&2,r.value];switch(o[0]){case 0:case 1:r=o;break;case 4:e.label++;return{value:o[1],done:false};case 5:e.label++;i=o[1];o=[0];continue;case 7:o=e.ops.pop();e.trys.pop();continue;default:if(!(r=e.trys,r=r.length>0&&r[r.length-1])&&(o[0]===6||o[0]===2)){e=0;continue}if(o[0]===3&&(!r||o[1]>r[0]&&o[1]=a;var n=t.average&&!t.value&&a<=t.average;var i=a<=t.hoverValue;var r=t.average&&t.average+1-a;var o=!t.value&&!i&&r>0&&r<1;var s=t.hasFocus&&t.focusValue===a;return h("span",{class:{wrapper:true}},h("label",{class:{star:true,focused:s,selected:e,average:n,hovered:i,partial:o},htmlFor:"".concat(t.guid,"-").concat(a),onMouseOver:function(){t.hoverValue=a}},h("calcite-icon",{"aria-hidden":"true",class:"icon",icon:e||n||t.readOnly?"star-f":"star",scale:t.scale}),o&&h("div",{class:"fraction",style:{width:"".concat(r*100,"%")}},h("calcite-icon",{icon:"star-f",scale:t.scale})),h("span",{class:"visually-hidden"},t.intlStars.replace("${num}","".concat(a)))),h("input",{checked:a===t.value,class:"visually-hidden",disabled:t.disabled||t.readOnly,id:"".concat(t.guid,"-").concat(a),name:t.guid,onChange:function(){return t.updateValue(a)},onClick:function(t){return t.stopPropagation()},onFocus:function(){t.hasFocus=true;t.focusValue=a},ref:function(e){return(a===1||a===t.value)&&(t.inputFocusRef=e)},type:"radio",value:a}))}))};t.prototype.render=function(){var t=this;var a=this,e=a.disabled,n=a.intlRating,i=a.showChip,r=a.scale,o=a.count,s=a.average;return h(Fragment,null,h("fieldset",{class:"fieldset",disabled:e,onBlur:function(){return t.hoverValue=null},onMouseLeave:function(){return t.hoverValue=null},onTouchEnd:function(){return t.hoverValue=null}},h("legend",{class:"visually-hidden"},n),this.renderStars()),(o||s)&&i?h("calcite-chip",{scale:r,value:o===null||o===void 0?void 0:o.toString()},!!s&&h("span",{class:"number--average"},s.toString()),!!o&&h("span",{class:"number--count"},"(",o===null||o===void 0?void 0:o.toString(),")")):null,h(HiddenFormInputSlot,{component:this}))};t.prototype.onLabelClick=function(){this.setFocus()};t.prototype.updateValue=function(t){this.value=t;this.calciteRatingChange.emit({value:t})};t.prototype.setFocus=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.inputFocusRef.focus();return[2]}))}))};Object.defineProperty(t.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();Rating.style=ratingCss;export{Rating as calcite_rating};