import t,{Component as o}from"react";import{classNames as e,IconUtils as n}from"primereact/utils";import{tip as r}from"primereact/tooltip";import{Ripple as i}from"primereact/ripple";function p(t,o){if(!(t instanceof o))throw new TypeError("Cannot call a class as a function")}function s(t,o){for(var e=0;e0&&this.props.offLabel&&this.props.offLabel.length>0}},{key:"hasIcon",value:function(){return this.props.onIcon&&this.props.onIcon.length>0&&this.props.offIcon&&this.props.offIcon.length>0}},{key:"getLabel",value:function(){return this.hasLabel()?this.props.checked?this.props.onLabel:this.props.offLabel:" "}},{key:"componentDidMount",value:function(){this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(t){t.tooltip===this.props.tooltip&&t.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(d({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip())}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"renderTooltip",value:function(){this.tooltip=r({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"render",value:function(){var o=this,r=e("p-button p-togglebutton p-component",{"p-button-icon-only":this.hasIcon()&&!this.hasLabel(),"p-highlight":this.props.checked,"p-disabled":this.props.disabled},this.props.className),p=null,s=this.hasIcon(),l=this.getLabel(),c=this.props.checked?this.props.onIcon:this.props.offIcon;return s&&(p=e("p-button-icon p-c",{"p-button-icon-left":"left"===this.props.iconPos&&l,"p-button-icon-right":"right"===this.props.iconPos&&l})),t.createElement("div",{ref:function(t){return o.container=t},id:this.props.id,className:r,style:this.props.style,onClick:this.toggle,onFocus:this.props.onFocus,onBlur:this.props.onBlur,onKeyDown:this.onKeyDown,tabIndex:!this.props.disabled&&this.props.tabIndex,"aria-labelledby":this.props.ariaLabelledBy},s&&n.getJSXIcon(c,{className:p},{props:this.props}),t.createElement("span",{className:"p-button-label"},l),t.createElement(i,null))}}])&&s(y.prototype,m),O&&s(y,O),Object.defineProperty(y,"prototype",{writable:!1}),w}();b(m,"defaultProps",{id:null,onIcon:null,offIcon:null,onLabel:"Yes",offLabel:"No",iconPos:"left",style:null,className:null,checked:!1,tabIndex:0,tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onChange:null,onFocus:null,onBlur:null});export{m as ToggleButton};