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