import{d as P,s as R,r as m,a,b as C,u as c,e as d,F as b,A as T,f as y,o as s,L as E,c as Y,X as z,j as F}from"./m2W8DxR4.js";import{_ as G}from"./DTaLP_i_.js";import{_ as M,a as O}from"./CioX7pik.js";const X={key:0,dir:"rtl",class:"relative w-full overflow-hidden",role:"region","aria-label":"Video gallery"},D={class:"gallery-container"},H={class:"relative z-10 h-full w-full overflow-hidden rounded-2xl"},Z=["src"],q=["src"],J=["onClick"],K={class:"relative z-[10] mt-6 flex items-center justify-center gap-6"},Q=["disabled"],W={class:"custom-pagination-container"},ee=["onClick"],te=["disabled"],oe=P({__name:"SocialVideosSlider",props:{projects:{}},setup(I){const p=I,r=R(()=>Array.isArray(p.projects)?p.projects:p.projects.value),l=m(0),_=m([]),v=m(null),k=m(new Map),S=/(?:youtube\.com\/(?:.*v=|embed\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,w=e=>e.includes("youtube")||e.includes("youtu.be"),V=e=>{const t=e.match(S);return t?t[1]:null},$=e=>{const t=V(e);return t?`https://img.youtube.com/vi/${t}/maxresdefault.jpg`:""},N=(e,t=!1)=>{const o=V(e);if(!o)return"";const u=new URLSearchParams({mute:"1",...t&&{autoplay:"1"}});return`https://www.youtube.com/embed/${o}?${u.toString()}`},j=e=>{const t=r.value.length;if(t===0)return"hidden";const o=(l.value-1+t)%t,u=(l.value+1)%t,f=(l.value-2+t)%t,g=(l.value+2)%t;return e===o?"left":e===l.value?"center":e===u?"right":e===f||e===g?"preload":"hidden"},x=()=>{r.value.length!==0&&(l.value=(l.value-1+r.value.length)%r.value.length)},A=()=>{r.value.length!==0&&(l.value=(l.value+1)%r.value.length)},B=e=>{e>=0&&e<r.value.length&&(l.value=e)},U=(e,t)=>{if(!(t<0)){for(;_.value.length<=t;)_.value.push(null);_.value[t]=e instanceof HTMLVideoElement?e:null}},L=e=>{const t=r.value[e];if(!t||e<0||e>=r.value.length){console.warn(`Invalid video index: ${e}`);return}v.value=e;try{if(w(t.video_url)){const o=N(t.video_url,!0);k.value.set(e,o)}else{const o=_.value[e];(o==null?void 0:o.tagName)==="VIDEO"&&o.play().catch(u=>{console.warn("Could not play video:",u),v.value=null})}}catch(o){console.error("Error playing video:",o),v.value=null}};return(e,t)=>{const o=z,u=G,f=M,g=O;return c(r).length>0?(s(),a("div",X,[d("div",D,[(s(!0),a(b,null,T(c(r),(i,n)=>(s(),a("div",{key:i.id,class:E(["gallery-slide",j(n)])},[d("div",H,[w(i.video_url)?(s(),a(b,{key:0},[c(v)!==n?(s(),Y(o,{key:0,src:$(i.video_url),class:"gallery-media",alt:i.title},null,8,["src","alt"])):(s(),a("iframe",{key:1,class:"gallery-media aspect-video",src:c(k).get(n)||"",frameborder:"0",allowfullscreen:"",allow:"autoplay; encrypted-media"},null,8,Z))],64)):(s(),a("video",{key:1,ref_for:!0,ref:h=>U(h,n),src:i.video_url,class:"gallery-media aspect-video",controls:"",muted:"",loop:""},null,8,q)),c(v)!==n?(s(),a("div",{key:2,class:"absolute inset-0 flex cursor-pointer items-center justify-center rounded-2xl bg-[rgba(0,0,0,0.5)]",onClick:h=>L(n)},[y(u,{class:"h-[40px] w-[40px]"})],8,J)):C("",!0)])],2))),128))]),d("div",K,[d("button",{class:"bg-surface-background border-surface-border rounded-ws-rounded flex-shrink-0 cursor-pointer border p-3",disabled:c(r).length===0,"aria-label":"Previous video",onClick:x},[y(f,{class:"rtl:scale-x-[-1]"})],8,Q),d("div",W,[(s(!0),a(b,null,T(c(r),(i,n)=>(s(),a("div",{key:`pagination-${i.id}`,class:E(["pagination-dot",{active:c(l)===n}]),onClick:h=>B(n)},null,10,ee))),128))]),d("button",{class:"bg-surface-background border-surface-border rounded-ws-rounded flex-shrink-0 cursor-pointer border p-3",disabled:c(r).length===0,"aria-label":"Next video",onClick:A},[y(g,{class:"rtl:scale-x-[-1]"})],8,te)])])):C("",!0)}}}),ne=F(oe,[["__scopeId","data-v-ee987975"]]);export{ne as default};
