import Control from"./Control.js";import EventType from"../events/EventType.js";import{CLASS_CONTROL,CLASS_HIDDEN,CLASS_UNSELECTABLE}from"../css.js";import{easeOut}from"../easing.js";class Rotate extends Control{constructor(t){t=t||{},super({element:document.createElement("div"),render:t.render,target:t.target});var e=void 0!==t.className?t.className:"ol-rotate",s=void 0!==t.label?t.label:"⇧",a=void 0!==t.compassClassName?t.compassClassName:"ol-compass",s=(this.label_=null,"string"==typeof s?(this.label_=document.createElement("span"),this.label_.className=a,this.label_.textContent=s):(this.label_=s,this.label_.classList.add(a)),t.tipLabel||"Reset rotation");const i=document.createElement("button"),o=(i.className=e+"-reset",i.setAttribute("type","button"),i.title=s,i.appendChild(this.label_),i.addEventListener(EventType.CLICK,this.handleClick_.bind(this),!1),this.element);o.className=e+" "+CLASS_UNSELECTABLE+" "+CLASS_CONTROL,o.appendChild(i),this.callResetNorth_=t.resetNorth||void 0,this.duration_=void 0!==t.duration?t.duration:250,this.autoHide_=void 0===t.autoHide||t.autoHide,this.rotation_=void 0,this.autoHide_&&this.element.classList.add(CLASS_HIDDEN)}handleClick_(t){t.preventDefault(),void 0!==this.callResetNorth_?this.callResetNorth_():this.resetNorth_()}resetNorth_(){const t=this.getMap(),e=t.getView();var s;!e||void 0!==(s=e.getRotation())&&(0<this.duration_&&s%(2*Math.PI)!=0?e.animate({rotation:0,duration:this.duration_,easing:easeOut}):e.setRotation(0))}render(t){var e,s,t=t.frameState;t&&((t=t.viewState.rotation)!=this.rotation_&&(e="rotate("+t+"rad)",this.autoHide_&&((s=this.element.classList.contains(CLASS_HIDDEN))||0!==t?s&&0!==t&&this.element.classList.remove(CLASS_HIDDEN):this.element.classList.add(CLASS_HIDDEN)),this.label_.style.transform=e),this.rotation_=t)}}export default Rotate;