<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class PropertyController extends Controller
{
    public function show($id)
    {
        //$json = Storage::get('app/properties.json');
        $json = '[
    {
        "id": 1,
        "title": "42 Ward, North Dagon Township",
        "bedroom": "2 Bedrooms",
        "area": "42×60 ft",
        "price": "5300 Lakhs (PKR)",
        "imagePaths": [
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.pexels.com/photos/1475938/pexels-photo-1475938.jpeg",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "id": 2,
        "title": "South/North Junction ,North Dagon",
        "bedroom": "1 Bedroom",
        "area": "40×60 ft",
        "price": "5000 Lakhs (PKR)",
        "imagePaths": [
            "https://images.pexels.com/photos/1475938/pexels-photo-1475938.jpeg",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "id": 3,
        "title": "29 Ward, North Dagon Township",
        "bedroom": "3 Bedrooms",
        "area": "20×60 ft",
        "price": "5000 Lakhs (PKR)",
        "imagePaths": [
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "title": "44 Ward, North Dagon Township",
        "bedroom": "4 Bedrooms",
        "area": "40×60 ft",
        "price": "6000 Lakhs (PKR)",
        "imagePaths": [
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.pexels.com/photos/1475938/pexels-photo-1475938.jpeg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "id": 4,
        "title": "48 Ward, North Dagon Township",
        "bedroom": "2 Bedrooms",
        "area": "42×60 ft",
        "price": "5300 Lakhs (PKR)",
        "imagePaths": [
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.pexels.com/photos/1475938/pexels-photo-1475938.jpeg",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "id": 5,
        "title": "22 Ward, North Dagon Township",
        "bedroom": "1 Bedroom",
        "area": "40×60 ft",
        "price": "5000 Lakhs (PKR)",
        "imagePaths": [
            "https://images.pexels.com/photos/1475938/pexels-photo-1475938.jpeg",
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    },
    {
        "id": 6,
        "title": "33 Ward, North Dagon Township",
        "bedroom": "3 Bedrooms",
        "area": "20×60 ft",
        "price": "5000 Lakhs (PKR)",
        "imagePaths": [
            "https://thumbs.dreamstime.com/b/new-homes-2797965.jpg",
            "https://images.unsplash.com/photo-1600585154340-be6161a56a0c",
            "https://images.pexels.com/photos/1396122/pexels-photo-1396122.jpeg"
        ],
        "logo": "https://marketplace.canva.com/EAF0Hq4UHjM/1/0/1600w/canva-orange-phoenix-animal-gaming-logo-WIPEOAyYPIs.jpg"
    }
]';
        $properties = json_decode($json, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            dd(json_last_error_msg()); // shows the exact problem
        }
        $property = collect($properties)->firstWhere('id', (int) $id);

        if (!$property) {
            abort(404);
        }


        return view('property.show', ['property' => $property]);
    }
}