<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div class="row">
	<div class="col-md-4 ads_col_4">
		<?php echo Wo_LoadPage('ads/includes/header'); ?>
	</div>
	<div class="col-md-8 ads_col_8">
		<div class="page-margin wowonder-well">
			<div class="wo_page_hdng pag_neg_padd pag_alone">
				<div class="wo_page_hdng_innr">
					<span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M3,14L3.5,14.07L8.07,9.5C7.89,8.85 8.06,8.11 8.59,7.59C9.37,6.8 10.63,6.8 11.41,7.59C11.94,8.11 12.11,8.85 11.93,9.5L14.5,12.07L15,12C15.18,12 15.35,12 15.5,12.07L19.07,8.5C19,8.35 19,8.18 19,8A2,2 0 0,1 21,6A2,2 0 0,1 23,8A2,2 0 0,1 21,10C20.82,10 20.65,10 20.5,9.93L16.93,13.5C17,13.65 17,13.82 17,14A2,2 0 0,1 15,16A2,2 0 0,1 13,14L13.07,13.5L10.5,10.93C10.18,11 9.82,11 9.5,10.93L4.93,15.5L5,16A2,2 0 0,1 3,18A2,2 0 0,1 1,16A2,2 0 0,1 3,14Z"></path></svg></span> <?php echo $wo['ad_data']['name']; ?> <?php echo $wo['lang']['stats']; ?>
				</div>
			</div>
		</div>

		<div class="page-margin wowonder-well">
			<!-- Bar Chart -->
			<div id="admin-chart-container" style="min-width: 100%; height: 400px; margin: 0 auto;"></div>
			<!-- #END# Bar Chart -->
		</div>
	</div>
</div>

<?php 

$categories = "";
$views = "";
$spend = "";

if( $wo['ad_data']['bidding'] == "views" ){
    foreach ($wo["views"] as $key => $value) {
        $categories .= '"' . $value["DateOnly"] . '", ';
        $views .= $value["ADviews"] . ', ';
        $spend .= number_format($value["Spend"], 2) . ', ';
    }
}

if( $wo['ad_data']['bidding'] == "clicks" ){
    foreach ($wo["clicks"] as $key => $value) {
        $categories .= '"' . $value["DateOnly"] . '", ';
        $views .= $value["ADClicks"] . ', ';
        $spend .= number_format($value["Spend"], 2) . ', ';
    }
}


$title = "";
?>

<?php if( $wo['ad_data']['bidding'] == "views" ){ $title = "Views"; }else{ $title = "Clicks"; }?>

<script>
   $(function () {
    Highcharts.setOptions({
      colors: ['#4c75a3', '#ce3d3d', '#f2b92b', '#6abd46']
    });
    $('#admin-chart-container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Monthly <?php echo $title;?>'
        },
        xAxis: {
            categories: [ <?php echo $categories; ?> ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Last 30 Days'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y}</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            series: {
                minPointLength: 10
            },
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: '<?php echo $title;?>',
            data: [ <?php echo $views; ?> ]
        },
        {
            name: 'Spent',
            data: [ <?php echo $spend; ?> ]
        }]
    });
});
</script>