@extends('backend.admin.layouts.app')
@section('content')
    <div class="pagetitle">
        <h1>Dashboard</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item">Dashboard</li>
                <li class="breadcrumb-item active">{{ $PageTitle }}</li>
            </ol>
        </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">

        <div class="row">
            <div class="col-lg-12">

                <div class="card">
                    <div class="card-body mt-3">
                        <a href="{{ route('admin.menu-item.create') }}">
                            <button type="button" class="btn btn-primary">
                                Add Category
                            </button>
                        </a>

                        <!-- Table with stripped rows -->
                        <table class="table table-striped mt-4">
                            <thead>
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col">Category</th>
                                    <th scope="col">Order</th>
                                    <th scope="col">Slug</th>
                                    <th scope="col">SubCategory</th>
                                    <th scope="col">Image</th>
                                    <th scope="col">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($menus as $menu)
                                    <tr>
                                        <th scope="row">{{ $loop->iteration }}</th>
                                        <td>{{ ucfirst($menu->name) }}</td>
                                        <td>{{ $menu->order }}</td>
                                        <td>{{ $menu->slug }}</td>
                                        <td>
                                            @if ($menu->submenus->count() > 0)
                                                @foreach ($menu->submenus as $submenu)
                                                    <li class="submenu">{{ ucfirst($submenu->name) }}</li>
                                                @endforeach
                                            @endif
                                        </td>
                                        <td class="meimge">
                                            @if($menu->image)
                                                <img src="{{ asset('storage/' . $menu->image) }}" alt="{{ $menu->name }}">
                                            @endif
                                        </td>

                                        <td>
                                            <a href="{{ route('admin.menu-item.edit', $menu->id) }}"
                                               class="mr-1 edit" title="Edit">
                                                <i class="fa-solid fa-pen"></i>
                                            </a>

                                            <a href="#" class="ms-2 deleteItem"
                                               data-formid="delete_row_form_{{ $menu->id }}">
                                                <i class="fa-solid fa-trash"></i>
                                            </a>
                                            <form action="{{ route('admin.menu-item-delete', $menu->id) }}"
                                                  method="post"
                                                  id="delete_row_form_{{ $menu->id }}">
                                                @csrf
                                                {{ method_field('DELETE') }}
                                                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                            </form>
                                        </td>
                                    </tr>
                                @endforeach

                            </tbody>
                        </table>
                        <!-- End Table with stripped rows -->

                    </div>
                </div>
            </div>
        </div>

    </section>
@endsection

@push('style')
    <style>
        .edit {
            text-decoration: none;
            color: rgb(63, 62, 62);
        }

        .deleteItem {
            color: rgb(201, 4, 4);
            text-decoration: none;
        }

        .submenu {
            list-style-type: none;
        }

        .meimge img {
            width: 100px;
            height: 100px;
            object-fit: cover;
        }
    </style>
@endpush
