import{h}from"@stencil/core";import{timePassed}from"../../../../../util";export class PrestoActionBar{constructor(){this.ended=void 0,this.config=void 0,this.currentTime=void 0,this.duration=void 0,this.direction=void 0,this.youtube=void 0,this.show=!1,this.youtubeRenderKey=1,this.percentagePassed=0}componentWillLoad(){this.handleDuration()}handleDuration(){this.handleTime()}handleEnded(e){var t;if(e){if(100!==(null===(t=null==this?void 0:this.config)||void 0===t?void 0:t.percentage_start))return;this.show=!0}}handlePercentagePassed(){this.percentagePassed=this.currentTime/this.duration*100}handleTime(){this.checkTime()}checkTime(){var e,t;(null===(e=null===window||void 0===window?void 0:window.wp)||void 0===e?void 0:e.blocks)?this.show=!0:this.show=timePassed({current:this.currentTime,duration:this.duration,showAfter:null===(t=this.config)||void 0===t?void 0:t.percentage_start})}handleButtonCountChange(e,t){(null==e?void 0:e.button_count)!==(null==t?void 0:t.button_count)&&this.youtubeRenderKey++,(null==e?void 0:e.enabled)&&this.handleDuration()}youtubeButton(){var e,t,o,n;if("youtube"===(null===(e=this.config)||void 0===e?void 0:e.button_type)&&(null===(t=this.youtube)||void 0===t?void 0:t.channelId))return h("presto-youtube-subscribe-button",{key:this.youtubeRenderKey,channel:null===(o=this.youtube)||void 0===o?void 0:o.channelId,showCount:null===(n=this.config)||void 0===n?void 0:n.button_count})}customButton(){var e,t,o,n,i,r,a,s,l,u,d;if("custom"===(null===(e=this.config)||void 0===e?void 0:e.button_type))return h("presto-player-button",{type:"primary",size:"small",href:null===(o=null===(t=this.config)||void 0===t?void 0:t.button_link)||void 0===o?void 0:o.url,target:(null===(i=null===(n=this.config)||void 0===n?void 0:n.button_link)||void 0===i?void 0:i.opensInNewTab)?"_blank":"_self",style:Object.assign(Object.assign({"--presto-player-button-border-radius":`${null===(r=this.config)||void 0===r?void 0:r.button_radius}px`},(null===(a=this.config)||void 0===a?void 0:a.button_color)?{"--presto-player-button-color":`${null===(s=this.config)||void 0===s?void 0:s.button_color}`}:{}),(null===(l=this.config)||void 0===l?void 0:l.button_text_color)?{"--presto-player-button-text":`${null===(u=this.config)||void 0===u?void 0:u.button_text_color}`}:{})},null===(d=this.config)||void 0===d?void 0:d.button_text)}handleCtaStateChange(e){this.actionBarStateChange.emit(e)}render(){var e,t;return h("presto-action-bar-ui",{open:this.show,style:{"--presto-action-bar-background":(null===(e=this.config)||void 0===e?void 0:e.background_color)||"#1d1d1d"}},null===(t=this.config)||void 0===t?void 0:t.text,h("div",{slot:"button"},this.youtubeButton(),this.customButton()))}static get is(){return"presto-action-bar-controller"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["presto-action-bar-controller.scss"]}}static get styleUrls(){return{$:["presto-action-bar-controller.css"]}}static get properties(){return{ended:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"ended",reflect:!1},config:{type:"unknown",mutable:!1,complexType:{original:"ActionBarConfig",resolved:"ActionBarConfig",references:{ActionBarConfig:{location:"import",path:"../../../../../interfaces"}}},required:!1,optional:!1,docs:{tags:[],text:""}},currentTime:{type:"number",mutable:!1,complexType:{original:"number",resolved:"number",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"current-time",reflect:!0},duration:{type:"number",mutable:!1,complexType:{original:"number",resolved:"number",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"duration",reflect:!0},direction:{type:"string",mutable:!1,complexType:{original:"'rtl'",resolved:'"rtl"',references:{}},required:!1,optional:!0,docs:{tags:[],text:""},attribute:"direction",reflect:!1},youtube:{type:"unknown",mutable:!1,complexType:{original:"YoutubeConfig",resolved:"YoutubeConfig",references:{YoutubeConfig:{location:"import",path:"../../../../../interfaces"}}},required:!1,optional:!0,docs:{tags:[],text:""}}}}static get states(){return{show:{},youtubeRenderKey:{},percentagePassed:{}}}static get events(){return[{method:"actionBarStateChange",name:"actionBarStateChange",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"boolean",resolved:"boolean",references:{}}}]}static get elementRef(){return"el"}static get watchers(){return[{propName:"duration",methodName:"handleDuration"},{propName:"ended",methodName:"handleEnded"},{propName:"currentTime",methodName:"handlePercentagePassed"},{propName:"duration",methodName:"handlePercentagePassed"},{propName:"currentTime",methodName:"handleTime"},{propName:"config",methodName:"handleButtonCountChange"},{propName:"show",methodName:"handleCtaStateChange"}]}}