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