<?php

namespace App\Controllers\User;

use App\Controllers\BaseController;
use App\Models\StrategiMitigasiModel;
use App\Models\WilayahMitigasiModel;
use App\Models\PetaKerawananModel;

class Mitigasi extends BaseController
{
    protected $strategi;
    protected $wilayah;
    protected $peta;

    public function __construct()
    {
        $this->strategi = new StrategiMitigasiModel();
        $this->wilayah = new WilayahMitigasiModel();
        $this->peta = new PetaKerawananModel();
    }

    public function index()
    {

        $data = [
            'title' => 'Strategi Mitigasi',
            'strategi' => $this->strategi->findAll(),
            'wilayah' => $this->wilayah->getData(),
            'peta' => $this->peta->find(29)
        ];

        return view('user/mitigasi', $data);
    }

    public function simpan_polygon($id)
    {
        $geojson = $this->request->getJSON(true);

        $this->wilayah->update($id, [
            'polygon' => json_encode($geojson)
        ]);

        return $this->response->setJSON([
            'status' => true
        ]);
    }
}
