'use client';
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useEditorMode as o}from"@gem-sdk/core";import m from"next/dynamic";import{useMemo as s}from"react";import{getAspectRatioSettings as r,fallbackImageVideoUrl as a,getVimeoVideoId as i,getYoutubeVideoId as l,youtubeVideoRegex as d,parseTimeVideo as p}from"../common/helpers.js";import{createAttr as c,createStyle as n,createClass as u}from"@gem-sdk/system";import{getAttr as y}from"../common/attrs.js";import{getStyle as b,getYoutubeStyle as f,getVimeoStyle as j,getHtml5Style as E,getFallBackImageStyle as L}from"../common/styles.js";import{getFallbackImageClasses as V,getClasses as h}from"../common/classes.js";import k from"../../image/components/NextImage.js";let HTML5Embed=m(()=>import("./HTML5Embed.js")),LiteVimeoEmbed=m(()=>import("./LiteVimeoEmbed.js")),LiteYouTubeEmbed=m(()=>import("./LiteYouTubeEmbed.js")),Video=({className:m,setting:z,style:v,builderAttrs:N,builderProps:T,advanced:g,children:x})=>{let C=o(),{youtubeUrl:F="",vimeoUrl:H="",html5Url:M,autoplay:R=!1,loopVideo:Y=!1,controls:$=!1,mute:w,poster:I,startTime:O,endTime:S}=z??{},{cssClass:q}=g??{},A=I?.src,B="edit"!==C,D=r(z?.ratioOptions,z?.aspectRatio),G=c({...y({uid:T?.uid||""})}),J=n({...b(z,v)}),K=n({...f(D)}),P=n({...j(D)}),Q=n({...E(D)}),U=n({...L(z?.aspectRatio)}),W=u({...V()}),X=u({...h({className:m,builderProps:T,isInstantLP:B,advancedCssClass:q})}),Z=s(()=>{switch(z?.type){case"youtube":{let t=l(F);if(!d.test(F)||!t)return e(k,{src:a,alt:"Fallback video",className:W,style:U});let o="";return Y&&(o+=`&loop=1&playlist=${t}`),O&&(o+=`&start=${p(O)}`),S&&(o+=`&end=${p(S)}`),e(LiteYouTubeEmbed,{id:t,autoplay:R,title:"Video",controls:$,params:o,adNetwork:!1,noCookie:!0,muted:!w,thumbnail:A,lazy:z.lazy??!0,poster:I,preload:I?.preload,style:K})}case"vimeo":{let t=i(H);if(!t)return e(k,{src:a,alt:"Fallback video",className:W,style:U});return e(LiteVimeoEmbed,{muted:!w,loop:Y,controls:$,thumbnail:A,autoplay:R,lazy:z.lazy??!0,id:t,title:"Video",aspectRatio:D,poster:I,vimeoStyleIframe:P})}case"html5":if(!M)return e(k,{src:a,alt:"Fallback video",className:W,style:U});return e(HTML5Embed,{muted:!w,loop:Y,controls:$,autoplay:R,src:M,thumbnail:A,title:"Video",lazy:z.lazy??!0,isVideoComponent:!0,style:Q,poster:I})}},[D,R,Y,w,$,H,F,M,S,O,z?.type,z?.lazy,A,P,K,Q,U,W,I]);return t("div",{...N,...G,className:X,style:J,children:[Z,x]})};export{Video as default};
