var GSloadedChart=!1;const onGSChartInteraction=()=>{if(!0===GSloadedChart)return;GSloadedChart=!0;let e=document.createElement("script");e.src=gspb_chart_params.pluginURL+"/libs/apexchart/apexchart.min.js",e.id="gs-chart-loaded",document.body.appendChild(e),e.addEventListener("load",function(){GSChartRun()})},sanitizeChartData=e=>{if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(e=>sanitizeChartData(e));let a={};for(let t in e)if(e.hasOwnProperty(t)){let r=e[t];"name"===t||"categories"===t||"labels"===t||Array.isArray(r)&&"data"!==t&&"series"!==t?"string"==typeof r?a[t]=r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;"):Array.isArray(r)?a[t]=r.map(e=>"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;"):e):a[t]=r:"series"===t&&Array.isArray(r)?a[t]=r.map(e=>"object"==typeof e&&null!==e?sanitizeChartData(e):e):a[t]=sanitizeChartData(r)}return a},GSChartRun=e=>{let a=e||window.document,t=a.querySelectorAll("[data-chart-data]");for(let r=0;r<t.length;r++){let l=t[r],n=l.getAttribute("data-chart-data"),i;try{if(i=JSON.parse(n),"string"==typeof i&&(i=JSON.parse(i)),"object"!=typeof i)throw Error("Chart data is not an object after parsing");i=sanitizeChartData(i)}catch(s){console.error("Error parsing chart data:",s);continue}function o(e){if(!e||""===e.trim())return[];try{return JSON.parse(e)}catch(a){let t=e.split(",").map(e=>{let a=e.trim();return""===a||isNaN(a)?a||null:parseFloat(a)}).filter(e=>null!==e&&""!==e);return t.length?t:[]}}Array.from(l.attributes).forEach(e=>{if("data-xaxis-categories"===e.name){let a=o(e.value);i.xaxis&&a&&a.length>0&&(console.log(a),i.xaxis.categories=a.map(e=>"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;"):e))}else if("data-yaxis-categories"===e.name){let t=o(e.value);i.yaxis&&t&&t.length>0&&(i.yaxis.categories=t.map(e=>"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;"):e))}else if("data-labels"===e.name){let r=o(e.value);r&&r.length>0&&(i.labels=r.map(e=>"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;"):e))}else if(e.name.startsWith("data-series-")){let l=e.name.replace("data-series-",""),n=o(e.value);if(i.series&&n&&n.length>0){if(!isNaN(l)&&i.series[parseInt(l)])i.series[parseInt(l)].data=n;else{let s=i.series.find(e=>e.name===l);s&&(s.data=n)}}}else if("data-series"==e.name){let c=o(e.value);i.series&&c&&c.length>0&&(i.series=sanitizeChartData(c))}else if("data-series-numbers"===e.name){let d=o(e.value);i.series&&d&&d.length>0&&(i.series=sanitizeChartData(d))}else if("data-extra-json"==e.name){let p;try{p=JSON.parse(e.value),p=sanitizeChartData(p),i={...i,...p}}catch(g){console.error("Error parsing extra JSON data:",g)}}});let c=new ApexCharts(l,i);c.render();let d=l.getAttribute("data-chart-id");if(d){window[d]=c;let p=(e,t)=>{var r=a.createElement("a");r.href=e,r.download=t,a.body.appendChild(r),r.click(),a.body.removeChild(r)};a.querySelector(".download-chart-"+d)&&a.querySelector(".download-chart-"+d).addEventListener("click",function(){c.dataURI({width:1200}).then(function(e){p(e.imgURI,"chart.png")})})}}};document.body.addEventListener("mouseover",onGSChartInteraction,{once:!0}),document.body.addEventListener("touchmove",onGSChartInteraction,{once:!0}),window.addEventListener("scroll",onGSChartInteraction,{once:!0}),document.body.addEventListener("keydown",onGSChartInteraction,{once:!0});let GSChartImmediateLoading=document.querySelector("[data-immediate-loading]");GSChartImmediateLoading&&onGSChartInteraction();