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