import{getResponsiveValueByScreen as e,cloneDeep as t}from"@gem-sdk/core";import{getDynamicSourceLocales as o,createSettingId as i}from"../../helpers.js";import{Video as l}from"../settings/configs/translate.js";let getAspectRatioSettings=(t,o)=>{let i={desktop:t?.desktop?.width,tablet:t?.tablet?.width,mobile:t?.mobile?.width},l={desktop:t?.desktop?.height,tablet:t?.tablet?.height,mobile:t?.mobile?.height},s={desktop:o?.desktop==="custom"?`${e(i,"desktop")}/${e(l,"desktop")}`:o?.desktop==="cover"?"unset":o?.desktop,tablet:o?.tablet==="custom"?`${e(i,"tablet")}/${e(l,"tablet")}`:o?.tablet==="cover"?"unset":o?.tablet,mobile:o?.mobile==="custom"?`${e(i,"mobile")}/${e(l,"mobile")}`:o?.mobile==="cover"?"unset":o?.mobile};return s},getSettingTranslatedVideoAndThumbnail=({setting:e,uid:s,pageContext:r})=>{if(!e||!s)return{};if(r?.isPreviewing)return e;let a=t(e);if(a.youtubeUrl&&"youtube"===a.type){let e=o({val:a.youtubeUrl,uid:s,settingId:i({id:l?.youtubeUrl?.id}),pageContext:r});a.youtubeUrlTranslated=String(e)}if(a.vimeoUrl&&"vimeo"===a.type){let e=o({val:a.vimeoUrl,uid:s,settingId:i({id:l?.vimeoUrl?.id}),pageContext:r});a.vimeoUrlTranslated=String(e)}if(a.html5Url&&"html5"===a.type){let e=o({val:a.html5Url,uid:s,settingId:i({id:l?.html5Url?.id}),pageContext:r});a.html5Url=String(e)}if(a.poster){let e=o({val:a.poster?.src,uid:s,settingId:l?.poster?.id?`${l.poster.id}_src`:"",pageContext:r});a.poster.src=String(e)}return a},getYoutubeParams=e=>{let{id:t,params:o,muted:i,webp:l,controls:s,adNetwork:r,autoplay:a,lazy:m,thumbnail:d}=e,p=encodeURIComponent(t),u="hqdefault",n=`${o}`||"",b=i?"&mute=1":"",g=l?"webp":"jpg",c=l?"vi_webp":"vi",h=e.thumbnail||`https://i.ytimg.com/${c}/${p}/${u}.${g}`,v=e.noCookie?"https://www.youtube-nocookie.com":"https://www.youtube.com",$=`${v}/embed/${p}?autoplay=${!!m||!!d&&!a||a}&state=1${b}${n}&controls=${s?1:0}`,y=r||!1;return{videoId:p,posterImp:u,paramsImp:n,mutedImp:b,format:g,vi:c,posterUrl:h,ytUrl:v,iframeSrc:$,adNetworkImp:y}},getVimeoParams=e=>{let{id:t,autoplay:o,muted:i,controls:l,loop:s,lazy:r}=e,a=encodeURIComponent(t),m=`?&autoplay=${r?1:o?1:0}&muted=${i?1:0}&loop=${s?1:0}&controls=${l}&autopause=false`,d=`https://player.vimeo.com/video/${a}${m}`;return{videoId:a,params:m,iframeSrc:d}},makeStyleResponsiveRatio=(e,t)=>({[`--${e}`]:t?.desktop,[`--${e}-tablet`]:t?.tablet,[`--${e}-mobile`]:t?.mobile}),fallbackImageVideoUrl="https://cdn.shopify.com/s/files/1/0703/5214/2562/files/gempages_518090459516502570-3d3a4631-1d7d-4a2f-9ef0-9bbe7220e02d.jpg",youtubeVideoRegex=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=|shorts\/)|youtu\.be\/)([^"&?/\s]{11})/i,vimeoVideoRegex=/^(?:http:\/\/|https:\/\/)vimeo\.com\/[\w/]+(?:\?.*)?$/im,getYoutubeVideoId=e=>{let t=e.match(youtubeVideoRegex);return t?.[1]??void 0},getVimeoVideoId=e=>{let t=/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|album\/(\d+)\/video\/|video\/)?(\d+)(?:$|\/|\?)/,o=e.match(t);return o?.[3]},parseTimeVideo=e=>{let t=e.split(":",2);return t.length<=1?parseInt(t[0]||"0"):60*parseInt(t[0]||"0")+parseInt(t[1]||"0")},covertStrParamsToObj=e=>{let t=e.split("&");return t.shift(),t.reduce((e,t)=>{let[o,i]=t.split("=");return"loop"!==o?{...e,[o]:i}:e},{})},isSettingLoop=e=>e.includes("loop=1");export{covertStrParamsToObj,fallbackImageVideoUrl,getAspectRatioSettings,getSettingTranslatedVideoAndThumbnail,getVimeoParams,getVimeoVideoId,getYoutubeParams,getYoutubeVideoId,isSettingLoop,makeStyleResponsiveRatio,parseTimeVideo,vimeoVideoRegex,youtubeVideoRegex};
