using Microsoft.AspNetCore.Mvc;
using kehati.Models.View;
using kehati.Database;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;

namespace kehati.Controllers
{
    public class FaunaController : Controller
    {
        private readonly ApplicationDbContext db;
        public FaunaController(ApplicationDbContext context)
        {
            db = context;
        }
        
        public async Task<IActionResult> Index(int page = 1)
        {
            ViewBag.faunaHome = await Pagination.PaginateAsync(
                    db.Fauna.OrderByDescending(l => l.MsFaunaId),
                    page,12);

            var model = new HomeViewModel
            {
        
                FeaturedLocations = new List<LokasiModel>
                {
                    new()
                    {
                        Slug = "tebet-eco-park",
                        Name = "Tebet Eco Park"
                    },
                    new()
                    {
                        Slug = "hutan-kota-srengseng",
                        Name = "Hutan Kota Srengseng",
                        Image = "loc-srengseng.jpg"
                    },
                    new()
                    {
                        Slug = "mangrove-angke",
                        Name = "Hutan Mangrove Angke"
                    }
                },
            };
            return View(model);
        }

        public IActionResult Detail(string slug)
        {
            ViewBag.Slug = slug;

            var sp = new SpesiesModel
            {
                Slug= "elang-bondol",
                Type= "fauna",
                CommonName= "Elang Bondol",
                ScientificName= "Haliastur indus",
                Description=
                "Elang berkepala putih dengan tubuh coklat kemerahan. Maskot Provinsi DKI Jakarta dan simbol kekayaan hayati pesisir.",
                Habitat= "Pesisir, mangrove, muara sungai.",
                ConservationStatus= "Dilindungi",
                Image= "sp-elang-bondol.jpg",
                LocationSlugs = new List<string> 
                {"muara-angke", "mangrove-pik"}
            };

            var model = new HomeViewModel
            {
                Spesies = sp,
                FeaturedLocations = new List<LokasiModel>
                {
                    new()
                    {
                        Slug = "tebet-eco-park",
                        Name = "Tebet Eco Park",
                        Region = "Jakarta Selatan",
                        Area = "15.3 Ha",
                        FloraCount = 45,
                        FaunaCount = 20,
                        Image = "loc-tebet.jpg"
                    },
                    new()
                    {
                        Slug = "hutan-kota-srengseng",
                        Name = "Hutan Kota Srengseng",
                        Image = "loc-srengseng.jpg",
                        Region = "Jakarta Barat",
                        Area = "15.3 Ha",
                        FloraCount = 45,
                        FaunaCount = 20
                    },

                    new()
                    {
                        Slug = "mangrove-angke",
                        Name = "Hutan Mangrove Angke",
                        Region = "Jakarta Barat",
                        Area = "15.3 Ha",
                        FloraCount = 45,
                        FaunaCount = 20,
                        Image = "loc-mangrove-pik.jpg"
                    }
                }
            };

            return View(model);
        }
    }
}