@extends('base')
@section('main')
<article class="header">
    <header>
        <h2>
            Anzahl jemals gefundene Kurzzeitmietobjekte pro Region
        </h2>
    </header>
    <div id="chart-props-per-region"></div>
</article>
<article class="header">
    <header>
        <h2>
            Entwicklung der Anzahl jemals gefunden Kurzzeitmietobjekte
        </h2>
    </header>
    <div id="extractions"></div>
</article>
<article>
    <div id="leaflet"></div>
</article>

<script type="module">
const chartPropsPerRegion = document.getElementById('chart-props-per-region');
const cPropsPerRegion = echarts.init(chartPropsPerRegion);
const cPropsPerRegionOptions = {
    grid: {
        top: 20,
        left: 30,
        right: 0,
        bottom: 20

    },
  xAxis: {
    type: 'category',
    data: {!! $propsPerRegion[0] !!}
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: {!! $propsPerRegion[1] !!},
      type: 'bar'
    }
  ]
};

cPropsPerRegion.setOption(cPropsPerRegionOptions);

const chartExtractions = document.getElementById('extractions');
const cExtractions = echarts.init(chartExtractions);

const filters = {
  regions: ["Alle", "Davos", "Engadin", "Heidiland", "St. Moritz"]
}

const cExtractionsOptions = {
  tooltip: {
    trigger: 'axis'
  },
  legend: {
    data: filters.regions
  },
  grid: {
    left: '0',
    right: 10,
    bottom: '0',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: {!! json_encode($growth['dates']) !!}
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      name: 'Alle',
      type: 'line',
      stack: 'Total',
      data: {!! json_encode($growth['total_all']) !!}
    },
    {
      name: 'Heidiland',
      type: 'line',
      stack: 'Heidiland',
      data: {!! json_encode($growth['total_heidiland']) !!}
    },
    {
      name: 'Davos',
      type: 'line',
      stack: 'Davos',
      data: {!! json_encode($growth['total_davos']) !!}
    },
    {
      name: 'Engadin',
      type: 'line',
      stack: 'Engadin',
      data: {!! json_encode($growth['total_engadin']) !!}
    },
    {
      name: 'St. Moritz',
      type: 'line',
      stack: 'St. Moritz',
      data: {!! json_encode($growth['total_stmoritz']) !!}
    },
  ]
};

cExtractions.setOption(cExtractionsOptions);

const map = L.map('leaflet').setView([46.862962, 9.535296], 9);

L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

const properties = {!! json_encode($geo) !!}
properties.forEach( prop => {
    console.log(prop);
    let coords = prop.coordinates.split(',');
    L.marker(coords).addTo(map).bindPopup('<a href="/prop/'+prop.id+'">'+prop.coordinates+'</a>');
})


</script>
@endsection