<!-- resources/views/blogs/index.blade.php -->
@extends('layouts.header')

@section('content')
    <div class="container">
        <h1>Blogs</h1>
        @foreach ($blogs as $blog)
            <div class="card mb-5">
                <div class="card-body text-center">
                    <h5 class="card-title">{{ $blog->title }}</h5>
                    <p class="card-text">{{ $blog->content }}</p>
                     @if ($blog->images)
            <div class="row justify-content-center mb-3">
                @if (is_string($blog->images))
                    @foreach (json_decode($blog->images) as $image)
                    <div class="col-md-4 mb-3">
                        <img src="{{ asset($image) }}" alt="Blog Image" class="img-fluid">
                    </div>
                    @endforeach
                @else
                    @foreach ($blog->images as $image)
                    <div class="col-md-4 mb-3">
                        <img src="{{ asset($image) }}" alt="Blog Image" class="img-fluid">
                    </div>
                    @endforeach
                @endif
            </div>
            @endif
                    <div class="row justify-content-center">
                        <div class="col-md-3">
                            <a href="{{ route('blogs.edit', $blog->id) }}" class="btn btn-primary btn-block">Edit</a>
                        </div>
                        <div class="col-md-3">
                            <form action="{{ route('blogs.destroy', $blog->id) }}" method="POST">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-danger btn-block" onclick="return confirm('Are you sure you want to delete this blog?')">Delete</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
    </div>
@endsection
