const t=W.broadcast,e=W.http,a=W.rootScope,r=W.storage,s=W.store,i=W.promo,{tsHour:o,$:n}=(W.utils,W.utils),{t:c}=W.trans,{Drag:l}=W.Drag;import{I as p}from"./_shared/definitions.js";var d="articleDeleteButtonPromo";class u extends l{constructor(t){super(t),this.threshold=t.threshold,this.width=t.width,this.ondelete=t.ondelete}startDrag(t){super.startDrag(t),this.el.style.transition="none"}ondrag(t){t<0&&(t<this.width&&(this.deleteElement(),t=this.width),this.el.style.transform="translate(".concat(Math.floor(t),"px,0px)"))}deleteElement(){this.el.style.transition="",setTimeout((()=>{this.el.style.transition=""}),1e3),this.ondelete(),i.neverSee(d)}ondragend(){this.el.style.transition="",this.el.style.transform=""}}var g=!1,h=r.get("articles")||{},v=24*o*30,m=12*o,k=()=>t.emit("rqstClose","startup-articles"),f=()=>r.put("articles",h),y=(e,r)=>{var{coverPhoto:s,slug:i,title:o,id:n,subtitle:l,key:p,importance:d}=r,u=h[p],g=Date.now();u?(u.checked=g,g-u.seen>m&&(u.seen=g,u.count++)):h[p]={seen:g,checked:g,count:1};var v=/extreme|severe|moderate/.test(d)&&'<div class="badge size-xs article__warning"\n              style="background: var(--color-warning-'.concat(d,');">').concat(d," warning</div>"),k=s.src&&s.src.replace(/\?w=\d+/,"");e.innerHTML="<span style=\"background-image: url('".concat(k,"?w=200');\"></span>\n        ").concat(v||"","\n        ").concat(l&&!v?'<div class="article__subtitle size-s">'.concat(l,"</div>"):"",'\n        <a href="https://www.windy.com/articles/').concat(i,"-").concat(n,'" class="nomouse">').concat(o,"</a>\n        ").concat(a.isMobile?'<div class="article__delete bg-error clickable">'.concat(c.FAVS_DELETE,"</div>"):'<div class="closing-x article__closing" data-ref="delete"></div>'),e.onclick=()=>t.emit("rqstOpen","articles",{id:n}),e.classList.add("article--show")},b=t=>{h[t].count=100,f(),k()},w=t=>{g=!1;var r={homepage:1,language:s.get("usedLang"),country:s.get("country"),target:a.target,device:a.device,version:a.version,platform:a.platform};e.get("/articles/related",{qs:r}).then((e=>{var{data:r}=e;!g&&r&&r.length?((t,e)=>{if(e.forEach((t=>{var e="".concat(t.id,"-").concat(t.updated),a=h[e];a?(t.count=a.count,t.checked=a.checked):t.count=t.checked=0,t.key=e})),(e=e.filter((t=>t.count<3))).length>=2&&e[0].ranking-e[1].ranking>=3){var r=e.shift();(e=e.sort(((t,e)=>t.checked-e.checked))).unshift(r)}else e=e.sort(((t,e)=>t.checked-e.checked));if(e.length){var{key:s}=e[0];y(t,e[0]);var c=Date.now();if(Object.keys(h).forEach((t=>{c-h[t].seen>v&&delete h[t]})),f(),a.isMobile){new u({el:t,threshold:-80,width:-120,preventDefault:!1,ondelete:()=>{b(s)}});var{ts:l,displayed:p}=i.getCounter2(d);p<4&&Date.now()-l>24*o&&(i.hitCounter(d),setTimeout((()=>{t.classList.add("article__promo-delete-button"),setTimeout((()=>{t.classList.remove("article__promo-delete-button")}),2e3)}),500))}else{var g=n('[data-ref="delete"]',t);g&&(g.onclick=t=>{t.stopPropagation(),b(s)})}}else k()})(t,r):k()})).catch((t=>{console.error(t),k()}))},x=()=>{g=!0};const _="#plugin-startup-articles {  background-color: var(--color-transparent);  color: var(--color-white);  transition: opacity 0.5s, transform 0.5s;  opacity: 0;  padding: 5px 10px 5px 110px;  font-size: 18px;  line-height: 1.4;  letter-spacing: 0.02em;  margin-bottom: 5px;  position: relative;}#plugin-startup-articles.article--show {  opacity: 1;}#plugin-startup-articles span {  width: 100px;  height: 100%;  display: block;  position: absolute;  left: 0;  top: 0;  background-size: cover;  background-repeat: no-repeat;  background-position-x: center;  background-position-y: center;}#plugin-startup-articles a {  display: block;}#plugin-startup-articles .article__warning {  top: -3px;  letter-spacing: 0.05em;  text-transform: uppercase;}#plugin-startup-articles .article__delete {  display: flex;  align-items: center;  justify-content: center;  text-align: center;  position: absolute;  left: 100%;  height: 100%;  top: 0;  width: 120px;}#plugin-startup-articles .article__closing {  color: var(--color-yellow);  display: block;  background: none;  top: -10px;  right: -8px;  font-size: 20px;  transition: opacity 0.3s;}#plugin-startup-articles .article__closing:hover {  opacity: 0.7;}#device-mobile #plugin-startup-articles {  width: 100vw;}#plugin-startup-articles.article__promo-delete-button {  transform: translate(-100px, 0px);}";export{_ as __css,h as articles,x as ondestroy,w as onmount,y as renderArticle,f as saveArticles};
