class Ticker{constructor(t,e,s,i){this.tickerUuid=t,this.origin=e,this.lang=s,this.showIcon=Boolean(i),this.feed=null,this.aggregated=null,this.tickerData={},this.icons=[],this.shadow=null,this.tickers=document.createElement("div"),this.timeInterval=1e4,this.assignEvents()}async assignEvents(){await this.getFeed(),(this.aggregated.length||this.feed.length)&&this.appendTickers()}async getFeed(){const t=await fetch(`${this.origin}/api/tickers/${this.tickerUuid}/get-easy-cart-feed?lang=${this.lang}`,{method:"GET",headers:{"Content-Type":"application/json"}}),{events:e,aggregated:s,icons:i,tickerData:n}=await t.json();this.aggregated=s,this.feed=e,this.tickerData=n,this.icons=i}appendTickers(){let t=!1,e=!1,s=!1,i=!1;const n=document.createElement("div");n.id="easy-ticker",document.body.appendChild(n),this.shadow=n.attachShadow({mode:"closed"});const a=document.createElement("style");a.textContent=`\n            :host {\n                all: initial;\n            }\n            * {\n                box-sizing: border-box;\n            }\n            .easy-ticker,\n            .easy-ticker * {\n                line-height: 1.2 !important;\n                letter-spacing: normal !important;\n                word-spacing: normal !important;\n                text-transform: none !important;\n                font-size: 16px;\n                font-family: '${this.tickerData.fontName}', sans-serif;\n            }\n        `,this.shadow.appendChild(a);const r=document.createElement("link");r.setAttribute("rel","stylesheet"),r.setAttribute("href",`https://fonts.googleapis.com/css?family=${this.tickerData.fontName.replaceAll(" ","+")}:300,400,500,600,700,800`),this.shadow.appendChild(r),r.onload=()=>{t=!0,this.whenLinksReady(t&&e&&s&&i)};const o=document.createElement("link");o.setAttribute("rel","stylesheet"),o.setAttribute("href","https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.0.0/css/flag-icons.min.css"),this.shadow.appendChild(o),o.onload=()=>{i=!0,this.whenLinksReady(t&&e&&s&&i)};const c=document.createElement("link");c.setAttribute("rel","stylesheet"),c.setAttribute("href","https://app.easy.tools/front/css/style.css"),this.shadow.appendChild(c),c.onload=()=>{e=!0,this.whenLinksReady(t&&e&&s&&i)};const d=document.createElement("script");d.src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment-with-locales.min.js",document.head.appendChild(d),d.onload=()=>{s=!0,this.whenLinksReady(t&&e&&s&&i)}}whenLinksReady(t){if(!t)return;const e=this.tickerData.corner.includes("top")?"top-0":"bottom-0",s=this.tickerData.corner.includes("left")?"left-0":"right-0";this.tickers.classList.add("transition-popup","fixed","transform","sm:m-8","sm:max-w-md","sm:w-full","font-normal",s,e),this.tickers.classList.add("easy-ticker"),this.tickers.classList.add("hide"),this.shadow.appendChild(this.tickers),setTimeout(()=>{this.tickers.classList.remove("hide"),this.appendAggregates()},100)}async appendAggregates(){if(!this.aggregated.length)return void this.appendEvents();let t=0;const e=this.prepareAggregate(this.aggregated[t]);this.appendEvent(e),t++;const s=setInterval(()=>{if(t>=this.aggregated.length)return clearInterval(s),void this.appendEvents();const e=this.prepareAggregate(this.aggregated[t]);this.appendEvent(e),t++},this.timeInterval+500)}async appendEvents(){if(!this.feed.length)return;let t=0;const e=this.prepareEvent(this.feed[t]);this.appendEvent(e),t++;const s=setInterval(()=>{if(t>=this.feed.length)return void clearInterval(s);const e=this.prepareEvent(this.feed[t]);this.appendEvent(e),t++},this.timeInterval+500)}async appendEvent(t){const e=document.createElement("div");e.classList.add("hide");const s=await this.getTickerTemplate(t);e.innerHTML=s,this.tickers.appendChild(e),setTimeout(()=>{e.classList.remove("hide")},100),setTimeout(()=>{e.classList.add("hide"),setTimeout(()=>{this.tickers.removeChild(e)},300)},this.timeInterval)}prepareAggregate(t){const e=this.tickerData.events.find(e=>e.code===t.type);return{text:this.replaceAggregateTextWithDynamicData(e.aggregate,t.count,t.product_name),icon:e.image?` <img src="${this.origin}${e.image}" class="w-full h-full object-cover" />`:this.getIcon(e.icon),link:t.url,date:""}}prepareEvent(t){const e=this.tickerData.events.find(e=>e.code===t.type);return{text:this.replaceTextWithDynamicData(e.text,t.variables),icon:e.image?` <img src="${this.origin}${e.image}" class="w-full h-full object-cover" />`:this.getIcon(e.icon),link:t.url,date:window.moment(t.date).locale(this.lang).fromNow()}}replaceAggregateTextWithDynamicData(t,e,s){return t=(t=t.replace("{count}",e)).replace("{product_name}",s)}replaceTextWithDynamicData(t,e){return["product_name","price","customer_name","city"].forEach(s=>{t.includes(`{${s}}`)&&(t=t.replace(`{${s}}`,e[s]||"")),t.includes("{country_code}")&&(t=t.replace("{country_code}",`<span class="inline-block fi fi-${e.country_code.toLowerCase()}"></span>`))}),t}async getTickerTemplate(t){return`<a href="${this.tickerData.link||t.link}" class="flex items-center space-x-2.5 sm:rounded-lg px-3.5 py-2.5 text-left overflow-hidden shadow-sm border sm:max-w-md sm:w-full mb-2 transform transition-ticker" style="background-color: ${this.tickerData.colors.background}; border-color: ${this.tickerData.colors.border};">\n\n            ${this.showIcon?`<div class="flex-shrink-0 relative flex items-center justify-center h-10 w-10 rounded-lg overflow-hidden border" style="color: ${this.tickerData.colors.cardText}; border-color: ${this.tickerData.colors.border}; background-color: ${this.tickerData.colors.cardBackground};">${t.icon}</div>`:""}\n\n\n            <div>\n                <span class="text-base font-medium" style="color: ${this.tickerData.colors.text};">\n                    ${t.text}\n                </span>\n                <div class="mt-0.5 text-sm font-regular opacity-80">\n                    <span style="color: ${this.tickerData.colors.text}"\n                    >\n                        ${t.date} ${t.date?"|":""} ${"en"===this.lang?"verified by":"zweryfikowane przez"} ${this.getIcon("StripeLogoIcon")}\n                    </span>\n                </div>\n            </div>\n        </a>`}getIcon(t){return this.icons.find(e=>e.name===t).code}}function startEasyticker(){new Ticker("wyzwanie-planowanie","https://app.easy.tools","pl",!0,{fontFamily:"Inter",colors:{text:"#101828",brand:"#FF0000",border:"#d0d5dd",cardText:"#101828",background:"#f9fafb",cardBackground:"#ffffff"}})}"loading"!==document.readyState?startEasyticker():document.addEventListener("DOMContentLoaded",startEasyticker);