import{r as $,a as I,c as u,n as j,o as J,b as c,d as B,w as T,e as z,v as E,f as w,g as m,l as F,p as M,k as R,h as U,i as b,s as g,j as v}from"./index-DNcc_XYj.js";import{_ as H}from"./_plugin-vue_export-helper-DlAUqK2U.js";const V=["src"],W={__name:"LinkContainer",props:{id:String,layoutId:String,partner:String,code:String},emits:["context"],setup(C,{emit:x}){const h="https://display24.ru",r=$(!1);let i=null;const S=x;function _(o){o.preventDefault(),S("context")}const d=C,e=I({id:null,layoutId:null,content:null,code:null}),k=u(()=>{var o,a,t,n,s,l,p,f,y;return{top:e.top+"px",left:e.left+"px",width:e.width+"px",height:e.height+"px",backgroundColor:j((o=e.background)==null?void 0:o.color)||"#000",zIndex:e.zIndex||0,borderColor:((a=e.border)==null?void 0:a.color)||"#fff",borderStyle:((t=e.border)==null?void 0:t.style)||"solid",borderWidth:(((n=e.border)==null?void 0:n.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((f=e.shadow)==null?void 0:f.b,"px ").concat((y=e.shadow)==null?void 0:y.color)}}),L=u(()=>{const o=e.content.link||"",a=e.code||"",t=o.includes("?")?"&":"?";return"".concat(o).concat(t,"code=").concat(encodeURIComponent(a))}),O=u(()=>{if(!e.content)return"";switch(e.content.mediaMode){case 1:return"stretch";case 2:return"crop";default:return"original"}});async function D(){var o;try{const t=(await b.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 n=((o=t.data)==null?void 0:o[0])||{};n=JSON.parse(JSON.stringify(n));let s=n==null?void 0:n.content.find(l=>l.id==e.id);s&&Object.assign(e,s),g("layouts",e.layoutId,n).then(l=>l&&console.info("LinkContainer (layouts): Сохранение данных в кэш")).catch(console.error)}else console.warn("LinkContainer (layouts): Нет данных")}catch(a){let t=await v("layouts",e.layoutId)||{};if(t=JSON.parse(JSON.stringify(t)),t){let n=t==null?void 0:t.content.find(s=>s.id==e.id);return n&&Object.assign(e,n),console.warn("LinkContainer (layouts): Данные загружены из кэша"),!0}else return console.error("LinkContainer (layouts): Нет данных в кэше."),!1}}async function N(){var o;if(e.schedule)try{const t=(await b.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 n=((o=t.data)==null?void 0:o[0])||{};n=JSON.parse(JSON.stringify(n));let s=(n==null?void 0:n.content)||null;Object.assign(e,{scheduleData:s}),r.value=c(e==null?void 0:e.scheduleData),g("schedule",e.schedule,n).then(l=>l&&console.info("LinkContainer (schedules): Сохранение данных в кэш")).catch(console.error)}else console.warn("LinkContainer (schedules): Нет данных")}catch(a){let t=await v("schedule",e.schedule)||{};if(t=JSON.parse(JSON.stringify(t)),t){let n=(t==null?void 0:t.content)||null;return Object.assign(e,{scheduleData:n}),r.value=c(e==null?void 0:e.scheduleData),console.warn("LinkContainer (schedules): Данные загружены из кэша"),!0}else return console.error("LinkContainer (schedules): Нет данных в кэше"),!1}}return J(async()=>{e.id=d.id,e.layoutId=d.layoutId,e.code=d.code,await D(),await N(),i=setInterval(()=>{r.value=c(e==null?void 0:e.scheduleData)},1e3)}),B(()=>{i&&clearInterval(i)}),T(()=>e.scheduleData,o=>{r.value=c(o)}),(o,a)=>z((m(),w("div",{class:"container",onContextmenu:_,style:U(k.value)},[e.content&&e.content.link?(m(),w("div",{key:0,class:M(["content",O.value])},[R("iframe",{src:L.value,frameborder:"0",style:{width:"100%",height:"100%","pointer-events":"none"},sandbox:"allow-same-origin allow-scripts allow-popups",allow:"encrypted-media",scrolling:"no"},null,8,V)],2)):F("",!0)],36)),[[E,r.value]])}},G=H(W,[["__scopeId","data-v-0b180b91"]]);export{G as default};
