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