import{r as $,a as j,c as g,n as I,o as k,b as i,d as J,w as L,e as B,v as M,f as w,g as S,l as F,u,p as z,h as E,i as v,s as b,j as _,q as H}from"./index-DNcc_XYj.js";import{m as R}from"./mustache-DUHPq_Lx.js";import{_ as U}from"./_plugin-vue_export-helper-DlAUqK2U.js";const W=["innerHTML"],q={__name:"TemplateContainer",props:{id:String,layoutId:String,partner:String},setup(C){const h="https://display24.ru",r=$(!1);let d=null;const p=C;let e=j({id:null,layoutId:null,content:[],html:"",templateString:""});const x=g(()=>{var n,l,t,a,s,o,c,f,m;return{top:e.top+"px",left:e.left+"px",width:e.width+"px",height:e.height+"px",backgroundColor:I((n=e.background)==null?void 0:n.color)||"#000",zIndex:e.zIndex||0,borderColor:((l=e.border)==null?void 0:l.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((o=e.shadow)==null?void 0:o.x,"px ").concat((c=e.shadow)==null?void 0:c.y,"px ").concat((f=e.shadow)==null?void 0:f.b,"px ").concat((m=e.shadow)==null?void 0:m.color)}}),T=g(()=>{if(!e.content)return"";switch(e.content.mediaMode){case 1:return"stretch";case 2:return"crop";default:return"original"}});async function D(){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(o=>o.id==e.id);s&&Object.assign(e,s),b("layouts",e.layoutId,a).then(o=>o&&console.info("TemplateContainer (layouts): Сохранение данных в кэш")).catch(console.error)}else console.warn("TemplateContainer (layouts): Нет данных")}catch(l){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("TemplateContainer (layouts): Данные загружены из кэша"),!0}else return console.error("TemplateContainer (layouts): Нет данных в кэше."),!1}}async function O(){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=i(e==null?void 0:e.scheduleData),b("schedule",e.schedule,a).then(o=>o&&console.info("TemplateContainer (schedules): Сохранение данных в кэш")).catch(console.error)}else console.warn("TemplateContainer (schedules): Нет данных")}catch(l){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}),r.value=i(e==null?void 0:e.scheduleData),console.warn("TemplateContainer (schedules): Данные загружены из кэша"),!0}else return console.error("TemplateContainer (schedules): Нет данных в кэше"),!1}}function N(){const n=new Date,l=String(n.getDate()).padStart(2,"0"),t=String(n.getMonth()+1).padStart(2,"0"),a=n.getFullYear();return"".concat(l,".").concat(t,".").concat(a)}async function y(){var c;const n=["Понедельник","Вторник","Среда","Четверг","Пятница","Суббота","Воскресенье"],t=(new Date().getDay()+6)%7,a=n[t],s=N();e.templateString=H((c=e.content)==null?void 0:c.html)||"";const o=R.render(e.templateString,{todayDate:s,todayWeekday:a});e.html!=o&&(e.html=o.length?o:'<div style="display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; color: #fff; background-color: #000;">No template data</div>')}return k(async()=>{e.id=p.id,e.layoutId=p.layoutId,await D(),await O(),await y(),d=setInterval(()=>{r.value=i(e==null?void 0:e.scheduleData),y()},1e3)}),J(()=>{d&&clearInterval(d)}),L(()=>e.scheduleData,n=>{r.value=i(n)}),(n,l)=>{var t,a;return B((S(),w("div",{class:"container",style:E(x.value)},[u(e).content&&((a=(t=u(e).content)==null?void 0:t.html)!=null&&a.length)?(S(),w("div",{key:0,class:z(["content",T.value]),innerHTML:u(e).html},null,10,W)):F("",!0)],4)),[[M,r.value]])}}},G=U(q,[["__scopeId","data-v-136f2209"]]);export{G as default};
