import{proxyCustomElement,HTMLElement,createEvent,h}from"@stencil/core/internal/client";import{t as timePassed}from"./util.js";import{d as defineCustomElement$2}from"./presto-cta-overlay-ui2.js";import{d as defineCustomElement$1}from"./presto-player-button2.js";const prestoCtaOverlayControllerCss=":host{display:block}",PrestoCtaOverlayControllerStyle0=":host{display:block}",PrestoCtaOverlayController=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.playVideo=createEvent(this,"playVideo",7),this.pauseVideo=createEvent(this,"pauseVideo",7),this.restartVideo=createEvent(this,"restartVideo",7),this.ctaStateChange=createEvent(this,"ctaStateChange",7),this.ended=void 0,this.currentTime=void 0,this.duration=void 0,this.direction=void 0,this.cta=void 0,this.i18n=void 0,this.provider=void 0,this.enabled=void 0,this.show=void 0,this.loading=void 0,this.error=void 0,this.skipped=void 0,this.percentagePassed=0}componentWillLoad(){this.handleDuration()}handleEnded(t){var e;if(t){if(100!==(null===(e=null==this?void 0:this.cta)||void 0===e?void 0:e.percentage))return;this.show=!0}}handleDuration(){var t;this.enabled=!this.skipped&&(null===(t=null==this?void 0:this.cta)||void 0===t?void 0:t.enabled),this.handleTime()}handlePercentagePassed(){this.percentagePassed=this.currentTime/this.duration*100}handleEnabled(){this.show&&(this.skipped||this.pauseVideo.emit(!0))}handleTime(){var t;this.enabled&&(this.skipped||100!==(null===(t=null==this?void 0:this.cta)||void 0===t?void 0:t.percentage)&&this.checkTime())}checkTime(){var t;this.show=timePassed({current:this.currentTime,duration:this.duration,showAfter:(null===(t=null==this?void 0:this.cta)||void 0===t?void 0:t.percentage)||0})}skip(){this.skipped=!0,this.show=!1,this.playVideo.emit()}rewatch(){this.ended=!1,this.show=!1,this.restartVideo.emit()}handleCtaStateChange(t){this.ctaStateChange.emit(t)}render(){var t,e,i,o,s,n,a,l,d,r,c,u,v,p;if(this.show)return h("presto-cta-overlay-ui",{style:Object.assign(Object.assign(Object.assign({"--presto-player-button-border-radius":`${null===(t=null==this?void 0:this.cta)||void 0===t?void 0:t.button_radius}px`},(null===(e=null==this?void 0:this.cta)||void 0===e?void 0:e.background_opacity)?{"--presto-player-cta-background-opacity":""+(null===(i=null==this?void 0:this.cta)||void 0===i?void 0:i.background_opacity)/100}:{}),(null===(o=null==this?void 0:this.cta)||void 0===o?void 0:o.button_color)?{"--presto-player-button-color":`${null===(s=null==this?void 0:this.cta)||void 0===s?void 0:s.button_color}`}:{}),(null===(n=null==this?void 0:this.cta)||void 0===n?void 0:n.button_text_color)?{"--presto-player-button-text":`${null===(a=null==this?void 0:this.cta)||void 0===a?void 0:a.button_text_color}`}:{}),direction:this.direction,class:"cta-overlay",i18n:this.i18n,headline:null===(l=null==this?void 0:this.cta)||void 0===l?void 0:l.headline,"bottom-text":null===(d=null==this?void 0:this.cta)||void 0===d?void 0:d.bottom_text,"show-button":null===(r=null==this?void 0:this.cta)||void 0===r?void 0:r.show_button,buttonLink:null===(c=null==this?void 0:this.cta)||void 0===c?void 0:c.button_link,allowSkip:!this.ended&&(null===(u=null==this?void 0:this.cta)||void 0===u?void 0:u.show_skip),allowRewatch:this.ended&&(null===(v=null==this?void 0:this.cta)||void 0===v?void 0:v.show_rewatch),"button-text":null===(p=null==this?void 0:this.cta)||void 0===p?void 0:p.button_text,onSkip:()=>this.skip(),onRewatch:()=>this.rewatch(),provider:this.provider})}static get watchers(){return{ended:["handleEnded"],duration:["handleDuration","handlePercentagePassed"],currentTime:["handlePercentagePassed","handleEnabled","handleTime"],show:["handleCtaStateChange"]}}static get style(){return":host{display:block}"}},[0,"presto-cta-overlay-controller",{ended:[4],currentTime:[514,"current-time"],duration:[514],direction:[1],cta:[16],i18n:[16],provider:[1],enabled:[32],show:[32],loading:[32],error:[32],skipped:[32],percentagePassed:[32]},void 0,{ended:["handleEnded"],duration:["handleDuration","handlePercentagePassed"],currentTime:["handlePercentagePassed","handleEnabled","handleTime"],show:["handleCtaStateChange"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["presto-cta-overlay-controller","presto-cta-overlay-ui","presto-player-button"].forEach((t=>{switch(t){case"presto-cta-overlay-controller":customElements.get(t)||customElements.define(t,PrestoCtaOverlayController);break;case"presto-cta-overlay-ui":customElements.get(t)||defineCustomElement$2();break;case"presto-player-button":customElements.get(t)||defineCustomElement$1()}}))}export{PrestoCtaOverlayController as P,defineCustomElement as d};