<?php

namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\MapPoint;

class MapController extends Controller
{
    public function index()
    {
        // Remove Dusun I - Dusun III points
        MapPoint::where('nama', 'LIKE', '%Dusun I Suka Baru%')
                ->orWhere('nama', 'LIKE', '%Dusun II Suka Baru%')
                ->orWhere('nama', 'LIKE', '%Dusun III Suka Baru%')
                ->orWhere('jenis', 'dusun')
                ->delete();

        $points = MapPoint::all();
        return view('public.peta', compact('points'));
    }

    public function data()
    {
        $points = MapPoint::where('jenis', '!=', 'dusun')->get()->map(function ($p) {
            return [
                'id'         => $p->id,
                'nama'       => $p->nama,
                'jenis'      => $p->jenis,
                'jenis_label'=> $p->jenis_label,
                'deskripsi'  => $p->deskripsi,
                'latitude'   => $p->latitude,
                'longitude'  => $p->longitude,
            ];
        });

        return response()->json($points);
    }
}
