import{r as g,a as N,c as $,n as F,o as J,b as c,d as k,w as B,e as L,v as T,f as m,g as w,l as U,h as b,i as v,s as S,j as I,x as E}from"./index-DNcc_XYj.js";import{_ as M}from"./_plugin-vue_export-helper-DlAUqK2U.js";const z=["src","alt"],R={__name:"ImageContainer",props:{id:String,layoutId:String,partner:String},setup(_){const h="https://display24.ru",i=g(null),r=g(!1);let u=null;const d=_,e=N({id:null,layoutId:null,content:null}),x=$(()=>{var n,o,t,a,s,l,p,y,f;return{top:e.top+"px",left:e.left+"px",width:e.width+"px",height:e.height+"px",backgroundColor:F((n=e.background)==null?void 0:n.color)||"#000",zIndex:e.zIndex||0,borderColor:((o=e.border)==null?void 0:o.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((p=e.shadow)==null?void 0:p.y,"px ").concat((y=e.shadow)==null?void 0:y.b,"px ").concat((f=e.shadow)==null?void 0:f.color)}}),C=async(n,o)=>{const t="https://cdn.display24.ru/partners/".concat(d.partner,"/").concat(n);return await E(t,o)},O=n=>{switch(n){case 1:return{objectFit:"fill",width:"100%",height:"100%"};case 2:return{objectFit:"cover",width:"100%",height:"100%"};default:return{objectFit:"none"}}};async function j(){var n;try{const t=(await v.get("".concat(h,"/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=((n=t.data)==null?void 0:n[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),S("layouts",e.layoutId,a).then(l=>l&&console.info("ImageContainer (layouts): Сохранение данных в кэш")).catch(console.error)}else console.warn("ImageContainer (layouts): Нет данных")}catch(o){let t=await I("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("ImageContainer (layouts): Данные загружены из кэша"),!0}else return console.error("ImageContainer (layouts): Нет данных в кэше."),!1}}async function D(){var n;if(e.schedule)try{const t=(await v.get("".concat(h,"/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=((n=t.data)==null?void 0:n[0])||{};a=JSON.parse(JSON.stringify(a));let s=(a==null?void 0:a.content)||null;Object.assign(e,{scheduleData:s}),r.value=c(e==null?void 0:e.scheduleData),S("schedule",e.schedule,a).then(l=>l&&console.info("ImageContainer (schedules): Сохранение данных в кэш")).catch(console.error)}else console.warn("ImageContainer (schedules): Нет данных")}catch(o){let t=await I("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}),r.value=c(e==null?void 0:e.scheduleData),console.warn("ImageContainer (schedules): Данные загружены из кэша"),!0}else return console.error("ImageContainer (schedules): Нет данных в кэше"),!1}}return J(async()=>{var n;e.id=d.id,e.layoutId=d.layoutId,await j(),await D(),(n=e.content)!=null&&n.filename&&(i.value=await C(e.content.filename,e.content.type)),u=setInterval(()=>{r.value=c(e==null?void 0:e.scheduleData)},1e3)}),k(()=>{u&&clearInterval(u)}),B(()=>e.scheduleData,n=>{r.value=c(n)}),(n,o)=>{var t,a;return L((w(),m("div",{class:"container",style:b(x.value)},[i.value?(w(),m("img",{key:0,src:i.value,alt:(t=e.content)==null?void 0:t.name,class:"content-image",style:b(O((a=e.content)==null?void 0:a.mediaMode))},null,12,z)):U("",!0)],4)),[[T,r.value]])}}},V=M(R,[["__scopeId","data-v-b9fa847b"]]);export{V as default};
