'use client';
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useEditorMode as r}from"@gem-sdk/core";import a from"react-youtube";import{getYoutubeParams as o,isSettingLoop as i,covertStrParamsToObj as l}from"../common/helpers.js";import s from"../../image/components/NextImage.js";import{createClass as m,createStyle as n}from"@gem-sdk/system";import{getButtonYoutubeClasses as c,getImageYoutubeClasses as u,getArticleYoutubeClasses as d,getIframeYoutubeClasses as p,getYoutubeContentClasses as f}from"../common/classes.js";import{getIframeYoutubeStyle as y,getArticleYoutubeStyle as b}from"../common/styles.js";import{useLiteYoutubeEmbed as h}from"../hooks/useLiteYoutubeEmbed.js";let LiteYouTubeEmbed=g=>{let C=r(),v="edit"!==C,{style:w,poster:N,iframeClass:j,wrapperClass:k,title:x}=g,{preload:B}=N||{},{videoId:E,paramsImp:L,posterUrl:S,iframeSrc:T}=o(g),{iframe:I,intervalPlay:V,warmConnections:H,isVideoStarted:M,videoDuration:Y,addIframe:z}=h(g,L,E),D=B&&v,P=m({...c(I)}),A=m({...u()}),F=m({...d(D||!1,k)}),O=m({...p(j)}),R=n({...y(w)}),q=n({...b(w,S)}),G=m({...f()}),J=()=>{if(g.isHeroBanner&&i(L))return t(a,{videoId:E,title:x,iframeClassName:O,style:R,className:G,opts:{host:"https://www.youtube-nocookie.com",playerVars:{autoplay:1,state:1,controls:0,mute:1,...l(L)}},onReady:e=>{if(e.target.playVideo(),Y.current=Math.floor(e.target.getDuration()),g.isHeroBanner){let t=e.target.getIframe();if(t){let e=t.closest("div.hero-banner-container");if(e){let r=new CustomEvent("youtube-iframe-ready",{detail:{iframe:t},bubbles:!0,cancelable:!0});e.dispatchEvent(r)}}}},onStateChange:e=>{let t=e.target;M.current||(t.playVideo(),M.current=!0,V(e)),0===e.data&&(Y.current=t.getCurrentTime(),t.playVideo(),V(e))}});let e=t("iframe",{className:O,style:R,title:x,frameBorder:"0",allow:"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,src:T});return g.isHeroBanner?t("div",{className:G,children:e}):e};return e("article",{"aria-hidden":!0,className:F,"data-title":x,style:q,onPointerOver:H,onClick:z,children:[t(s,{src:S,alt:N?.altText,title:N?.imageTitle,priority:v&&B,enableLazyLoadImage:!0,className:A,isDisableAspectStyle:!0}),t("button",{type:"button","aria-label":"Play",className:P,children:e("svg",{height:"100%",version:"1.1",viewBox:"0 0 68 48",width:"100%",children:[t("path",{d:"M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z",fill:"#f00"}),t("path",{d:"M 45,24 27,14 27,34",fill:"#fff"})]})}),I&&J()]})};export{LiteYouTubeEmbed as default};
