":parseFloat(d)")),t[i]&&(t[i].innerHTML=o),p[i]&&(null!==a&&o?(p[i].textContent=`${a>0?"+":""}${a}%`,p[i].classList.add("hidden")):(p[i].textContent="",p[i].classList.add("hidden"))),r[i]){const e=r[i],t=p[i];e.onmouseenter=e.onmouseleave=e.ontouchstart=e.onclick=null,e.onmouseenter=function(){t&&t.classList.remove("hidden")},e.onmouseleave=function(){t&&t.classList.add("hidden")},e.ontouchstart=function(e){e.stopPropagation(),t&&t.classList.toggle("hidden")},e.onclick=function(e){window.matchMedia("(pointer: coarse)").matches&&(e.stopPropagation(),t&&t.classList.toggle("hidden"))}}}})),document.addEventListener("click",(function(){document.querySelectorAll(".price-popover").forEach((e=>e.classList.add("hidden")))}))}function createChart(){if(!window.fuelHistory||!Array.isArray(window.fuelHistory))return;const e=document.querySelector(".chart-container");e.innerHTML="";const t=document.createElement("canvas");t.id="priceChart",t.style.width="100% !important",e.appendChild(t);const p=window.innerWidth<768,r={};window.fuelHistory.forEach((e=>{let t;r[e.type]||(r[e.type]=[]),t="Ropa Brent"===e.type||"USD/PLN"===e.type?parseFloat(e.price):showVatPrices?1.23*parseFloat(e.price):parseFloat(e.price),r[e.type].push({x:new Date(e.timestamp),y:t})})),Object.keys(r).forEach((e=>{r[e].sort(((e,t)=>e.x-t.x))}));const m=Object.entries(r).map((([e,t])=>{const r=fuelStyles[e]||defaultStyle,m="Ropa Brent"===e;return{label:e,data:t,borderColor:r.color,backgroundColor:hexToRgba(r.color,.15),borderWidth:p?3:2,borderDash:r.borderDash,pointRadius:0,pointHoverRadius:6,pointBackgroundColor:r.color,pointBorderColor:"#fff",pointBorderWidth:2,tension:.1,fill:!1,yAxisID:m?"y1":"y"}})),i=document.getElementById("priceChart").getContext("2d");let d=-1;const c=new Chart(i,{type:"line",data:{datasets:m},options:{responsive:!0,maintainAspectRatio:!0,animation:!1,plugins:{legend:{display:!0,position:"top"},tooltip:{mode:"index",intersect:!1,callbacks:{label:function(e){const t=e.dataset.label||"",p=e.parsed.y,r=t.includes("Ropa")?"USD":"zł/l";return`${t}: ${p.toFixed(2)} ${r}`}}},zoom:{pan:{enabled:!0,mode:"x",modifierKey:"ctrl"},zoom:{wheel:{enabled:!0},pinch:{enabled:!0},mode:"x",drag:{enabled:!0,backgroundColor:"rgba(59, 130, 246, 0.2)",borderColor:"rgba(59, 130, 246, 0.4)",borderWidth:1}}}},scales:{x:{type:"time",time:{unit:"month",displayFormats:{month:"yyyy-MM"}},title:{display:window.innerWidth>768,text:"Data"},grid:{display:!1},ticks:{maxRotation:window.innerWidth<768?45:0,autoSkip:!0,autoSkipPadding:window.innerWidth<768?15:10}},y:{type:"linear",position:"left",title:{display:!0,text:"Cena paliw (PLN/l) "+(showVatPrices?"(z VAT)":"(bez VAT)")},grid:{display:!0,color:"#eee"},min:0},y1:{type:"linear",position:"right",title:{display:!0,text:"Cena ropy (USD/barrel)"},grid:{drawOnChartArea:!1},min:0}}}}),o=document.createElement("button");o.textContent="Resetuj widok",o.className="border border-orlen-red text-orlen-red hover:bg-orlen-red hover:text-white px-3 py-1 rounded text-sm transition mt-2 ml-2",o.style.display="none",o.addEventListener("click",(()=>{c.resetZoom()})),document.querySelector(".chart-description").appendChild(o),c.options.plugins.zoom.zoom.onZoom=()=>{o.style.display="inline-block"},c.options.plugins.zoom.zoom.onZoomComplete=()=>{o.style.display="inline-block"},c.options.plugins.zoom.zoom.onResetZoom=()=>{o.style.display="none"},c.canvas.addEventListener("mousemove",(e=>{const t=c.getElementsAtEventForMode(e,"index",{intersect:!1});if(t.length){(e=>{-1!==e&&(d=e,c.data.datasets.forEach((t=>{Array.isArray(t.pointRadius)||(t.pointRadius=new Array(t.data.length).fill(0)),t.pointRadius=t.pointRadius.map(((t,p)=>p===e?6:0))})),c.update())})(t[0].index)}})),c.canvas.addEventListener("mouseout",(()=>{d=-1,c.data.datasets.forEach((e=>{e.pointRadius=0})),c.update()}));const a=new Date,s={week:new Date(a.getTime()-6048e5),month:new Date(a.getFullYear(),a.getMonth()-1,a.getDate()),year:new Date(a.getFullYear()-1,a.getMonth(),a.getDate()),all:new Date(2020,0,1)};function u(e){c.options.scales.x.min=e,c.options.scales.x.max=new Date,c.update(),o.style.display="none"}document.getElementById("btn-week").addEventListener("click",(()=>u(s.week))),document.getElementById("btn-month").addEventListener("click",(()=>u(s.month))),document.getElementById("btn-year").addEventListener("click",(()=>u(s.year))),document.getElementById("btn-all").addEventListener("click",(()=>u(s.all))),u(s.year)}document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("toggleVat");e&&(e.addEventListener("change",(()=>{showVatPrices=e.checked,updatePriceDisplay(),createChart()})),e.checked=showVatPrices),createChart(),updatePriceDisplay()}))