import{r as y,a as $,y as M,c as V,n as F,o as k,b as u,w as m,d as J,e as L,v as B,f as S,g as b,h as x,p as R,i as O,s as C,j as _,x as z}from"./index-DNcc_XYj.js";import{e as c}from"./artplayer-ueyOVO3X.js";const H={__name:"VideoContainer",props:{id:String,layoutId:String,partner:String},setup(N){c.CONTEXTMENU=!1,c.NOTICE_TIME=0,c.CONTROL_HIDE_TIME=0,c.RECONNECT_TIME_MAX=10;const f="https://display24.ru",i=y(!1);let d=null;const h=N,e=$({id:null,layoutId:null}),r=y(null),p=y(M(32)),I=V(()=>{var o,n,t,a,s,l,w,v,g;return{top:e.top+"px",left:e.left+"px",width:e.width+"px",height:e.height+"px",backgroundColor:F((o=e.background)==null?void 0:o.color)||"#000",zIndex:e.zIndex||0,borderColor:((n=e.border)==null?void 0:n.color)||"#fff",borderStyle:((t=e.border)==null?void 0:t.style)||"solid",borderWidth:(((a=e.border)==null?void 0:a.width)||0)+"px",borderRadius:((s=e.border)==null?void 0:s.radius)+"px",boxShadow:"".concat((l=e.shadow)==null?void 0:l.x,"px ").concat((w=e.shadow)==null?void 0:w.y,"px ").concat((v=e.shadow)==null?void 0:v.b,"px ").concat((g=e.shadow)==null?void 0:g.color)}}),T=o=>{var n,t;switch(o){case 1:return{objectFit:"fill",width:e.width+"px",height:e.height+"px"};case 2:return{objectFit:"cover",width:"100%",height:"100%"};default:return{objectFit:"none",width:((n=e.content)==null?void 0:n.width)+"px",height:((t=e.content)==null?void 0:t.height)+"px"}}};async function E(){var o;try{const t=(await O.get("".concat(f,"/api/v1/player/layouts/").concat(e.layoutId,"?v=")+Date.now(),{headers:{"Content-Type":"application/json"},timeout:5e3})).data;if(!t||typeof t!="object"||t.online!==!0)throw new Error("OFFLINE_OR_HTML_STUB_200");if((t==null?void 0:t.code)==200){let a=((o=t.data)==null?void 0:o[0])||{};a=JSON.parse(JSON.stringify(a));let s=a==null?void 0:a.content.find(l=>l.id==e.id);s&&Object.assign(e,s),C("layouts",e.layoutId,a).then(l=>l&&console.info("VideoContainer (layouts): Сохранение данных в кэш")).catch(console.error)}else console.warn("VideoContainer (layouts): Нет данных")}catch(n){let t=await _("layouts",e.layoutId)||{};if(t=JSON.parse(JSON.stringify(t)),t){let a=t==null?void 0:t.content.find(s=>s.id==e.id);return a&&Object.assign(e,a),console.warn("VideoContainer (layouts): Данные загружены из кэша"),!0}else return console.error("VideoContainer (layouts): Нет данных в кэше"),!1}}async function D(){var o;if(e.schedule)try{const t=(await O.get("".concat(f,"/api/v1/player/schedules/").concat(e.schedule,"?v=")+Date.now(),{headers:{"Content-Type":"application/json"},timeout:5e3})).data;if(!t||typeof t!="object"||t.online!==!0)throw new Error("OFFLINE_OR_HTML_STUB_200");if((t==null?void 0:t.code)==200){let a=((o=t.data)==null?void 0:o[0])||{};a=JSON.parse(JSON.stringify(a));let s=(a==null?void 0:a.content)||null;Object.assign(e,{scheduleData:s}),i.value=u(e==null?void 0:e.scheduleData),C("schedule",e.schedule,a).then(l=>l&&console.info("VideoContainer (schedule): Сохранение данных в кэш")).catch(console.error)}else console.warn("VideoContainer (schedule): Нет данных")}catch(n){let t=await _("schedule",e.schedule)||{};if(t=JSON.parse(JSON.stringify(t)),t){let a=(t==null?void 0:t.content)||null;return Object.assign(e,{scheduleData:a}),i.value=u(e==null?void 0:e.scheduleData),console.warn("VideoContainer (schedule): Данные загружены из кэша"),!0}else return console.error("VideoContainer (schedule): Нет данных в кэше"),!1}}async function j(o,n){const t="https://cdn.display24.ru/partners/".concat(h.partner,"/").concat(o);return await z(t,n)}return k(async()=>{e.id=h.id,e.layoutId=h.layoutId,await E(),await D(),d=setInterval(()=>{i.value=u(e==null?void 0:e.scheduleData)},1e3)}),m(()=>e.content,async o=>{if(!o||!o.filename)return;const n=document.querySelector(".video-"+p.value);if(n){const t=await j(o.filename,o.type);r.value&&r.value.destroy(!0),r.value=new c({container:n,url:t,poster:"/poster.png",autoSize:!0,miniProgressBar:!1,loop:!0,muted:!1,autoplay:!1,aspectRatio:!0,controls:[],volume:1,playsInline:!0,isLive:!0,mutex:!1,setting:!1,preload:"auto",clickToPlay:!1,show:!1,icons:{state:""}}),r.value&&r.value.play().catch(a=>{console.warn("Автозапуск заблокирован, ждем взаимодействия",a)})}else console.error("Контейнер для плеера не найден")}),J(()=>{d&&clearInterval(d),r.value&&r.value.destroy(!1)}),m(()=>e.scheduleData,o=>{i.value=u(o)}),(o,n)=>{var t;return L((b(),S("div",{class:"container",style:x(I.value)},[(b(),S("div",{class:R("video-"+p.value),style:x(T((t=e.content)==null?void 0:t.mediaMode)),key:p.value},null,6))],4)),[[B,i.value]])}}};export{H as default};
