"use strict";var core=require("@gem-sdk/core"),helpers=require("../../helpers.js"),translate=require("../settings/configs/translate.js");const getAspectRatioSettings=(e,t)=>{let o={desktop:e?.desktop?.width,tablet:e?.tablet?.width,mobile:e?.mobile?.width},i={desktop:e?.desktop?.height,tablet:e?.tablet?.height,mobile:e?.mobile?.height},s={desktop:t?.desktop==="custom"?`${core.getResponsiveValueByScreen(o,"desktop")}/${core.getResponsiveValueByScreen(i,"desktop")}`:t?.desktop==="cover"?"unset":t?.desktop,tablet:t?.tablet==="custom"?`${core.getResponsiveValueByScreen(o,"tablet")}/${core.getResponsiveValueByScreen(i,"tablet")}`:t?.tablet==="cover"?"unset":t?.tablet,mobile:t?.mobile==="custom"?`${core.getResponsiveValueByScreen(o,"mobile")}/${core.getResponsiveValueByScreen(i,"mobile")}`:t?.mobile==="cover"?"unset":t?.mobile};return s},getSettingTranslatedVideoAndThumbnail=({setting:e,uid:t,pageContext:o})=>{if(!e||!t)return{};if(o?.isPreviewing)return e;let i=core.cloneDeep(e);if(i.youtubeUrl&&"youtube"===i.type){let e=helpers.getDynamicSourceLocales({val:i.youtubeUrl,uid:t,settingId:helpers.createSettingId({id:translate.Video?.youtubeUrl?.id}),pageContext:o});i.youtubeUrlTranslated=String(e)}if(i.vimeoUrl&&"vimeo"===i.type){let e=helpers.getDynamicSourceLocales({val:i.vimeoUrl,uid:t,settingId:helpers.createSettingId({id:translate.Video?.vimeoUrl?.id}),pageContext:o});i.vimeoUrlTranslated=String(e)}if(i.html5Url&&"html5"===i.type){let e=helpers.getDynamicSourceLocales({val:i.html5Url,uid:t,settingId:helpers.createSettingId({id:translate.Video?.html5Url?.id}),pageContext:o});i.html5Url=String(e)}if(i.poster){let e=helpers.getDynamicSourceLocales({val:i.poster?.src,uid:t,settingId:translate.Video?.poster?.id?`${translate.Video.poster.id}_src`:"",pageContext:o});i.poster.src=String(e)}return i},getYoutubeParams=e=>{let{id:t,params:o,muted:i,webp:s,controls:r,adNetwork:l,autoplay:a,lazy:n,thumbnail:p}=e,d=encodeURIComponent(t),m="hqdefault",u=`${o}`||"",g=i?"&mute=1":"",c=s?"webp":"jpg",b=s?"vi_webp":"vi",h=e.thumbnail||`https://i.ytimg.com/${b}/${d}/${m}.${c}`,v=e.noCookie?"https://www.youtube-nocookie.com":"https://www.youtube.com",V=`${v}/embed/${d}?autoplay=${!!n||!!p&&!a||a}&state=1${g}${u}&controls=${r?1:0}`,y=l||!1;return{videoId:d,posterImp:m,paramsImp:u,mutedImp:g,format:c,vi:b,posterUrl:h,ytUrl:v,iframeSrc:V,adNetworkImp:y}},getVimeoParams=e=>{let{id:t,autoplay:o,muted:i,controls:s,loop:r,lazy:l}=e,a=encodeURIComponent(t),n=`?&autoplay=${l?1:o?1:0}&muted=${i?1:0}&loop=${r?1:0}&controls=${s}&autopause=false`,p=`https://player.vimeo.com/video/${a}${n}`;return{videoId:a,params:n,iframeSrc:p}},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");exports.covertStrParamsToObj=covertStrParamsToObj,exports.fallbackImageVideoUrl="https://cdn.shopify.com/s/files/1/0703/5214/2562/files/gempages_518090459516502570-3d3a4631-1d7d-4a2f-9ef0-9bbe7220e02d.jpg",exports.getAspectRatioSettings=getAspectRatioSettings,exports.getSettingTranslatedVideoAndThumbnail=getSettingTranslatedVideoAndThumbnail,exports.getVimeoParams=getVimeoParams,exports.getVimeoVideoId=getVimeoVideoId,exports.getYoutubeParams=getYoutubeParams,exports.getYoutubeVideoId=getYoutubeVideoId,exports.isSettingLoop=isSettingLoop,exports.makeStyleResponsiveRatio=makeStyleResponsiveRatio,exports.parseTimeVideo=parseTimeVideo,exports.vimeoVideoRegex=vimeoVideoRegex,exports.youtubeVideoRegex=youtubeVideoRegex;
