@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: " . __("Menus Reutilizáveis"))
@section('content')
    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
            <h5 class="my-2">{{ __('Menus Reutilizáveis') }}</h5>
        </div>
        <div class="card-body">
            @if (session('success'))
                <div class="alert alert-success">{{ session('success') }}</div>
            @endif

            @if (session('error'))
                <div class="alert alert-danger">{{ session('error') }}</div>
            @endif

            <h6 class="card-subtitle mb-2 text-body-secondary">
                @if (auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MENUS_REUTILIZAVEIS')['adicionar'])
                    @include('components.buttons._newButton', ['url' => 'admin.menusReutilizaveis.create', 'text' => __('Novo Menu')])
                @endif
            </h6>

            <div class="mb-4 bg-gray border-0 rounded-4 shadow-sm p-3">
                <form class="d-flex gap-2" method="get" action="{{ route('admin.menusReutilizaveis.index') }}" aria-label="{{ __('Buscar') }}">
                    <input
                        type="text"
                        class="form-control border-0"
                        name="q"
                        value="{{ request()->input('q') }}"
                        placeholder="{{ __('Buscar no menu') }}"
                        aria-label="{{ __('Pesquisar') }}"
                    >
                    <button class="btn btn-success text-secondary fw-bold px-4 py-2 rounded-4 flex-shrink-0" type="submit">
                        {{ __('Buscar') }}
                    </button>
                </form>
            </div>

            <div class="table-responsive">
                <table class="table table-bordered table-hover table-striped align-middle text-center">
                    @include('components.tables._thead', ['thead' => [__('Data de criação'), __('Título'), __('Status'), __('Ações')]])
                    <tbody>
                        @forelse($menus as $menu)
                            <tr>
                                <td>{{ date("d/m/Y H:i:s", strtotime($menu->created_at)) }}</td>
                                <td>
                                    <div class="d-flex flex-column align-items-center">
                                        @if (auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MENUS_REUTILIZAVEIS')['editar'])
                                            <a href="{{ route('admin.menusReutilizaveis.edit', $menu->id) }}" class="text-decoration-none fw-bold text-dark d-block">
                                                {{ $menu->title }}
                                            </a>
                                        @else
                                            <div class="fw-bold d-block">{{ $menu->title }}</div>
                                        @endif
                                        @if(!empty($menu->summary))
                                            <div class="text-muted small text-truncate w-75 mx-auto" title="{{ $menu->summary }}">
                                                {{ $menu->summary }}
                                            </div>
                                        @endif
                                    </div>
                                </td>
                                <td>
                                    @include('components.buttons._status', [
                                        'permission' => 'GERENCIADOR_DE_MENUS_REUTILIZAVEIS',
                                        'route' => 'admin.menusReutilizaveis.status',
                                        'id' => $menu->id,
                                        'status' => $menu->status,
                                        'index' => $loop->index ?? 0,
                                    ])
                                    @if (!auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MENUS_REUTILIZAVEIS')['editar'])
                                        <div class="d-flex justify-content-center align-items-center">
                                            @if ($menu->status === 'ATIVADO')
                                                <span class="badge bg-success">{{ __('Ativado') }}</span>
                                            @else
                                                <span class="badge bg-secondary">{{ __('Desativado') }}</span>
                                            @endif
                                        </div>
                                    @endif
                                </td>
                                <td>
                                    <div class="d-flex gap-2 justify-content-center align-items-center mt-2">
                                        @include('components.buttons._editButton', [
                                            'route' => 'admin.menusReutilizaveis.edit',
                                            'id' => $menu->id,
                                            'title' => __('Editar'),
                                            'permission' => 'GERENCIADOR_DE_MENUS_REUTILIZAVEIS',
                                            'fontawesome' => null,
                                        ])

                                        @include('components.buttons._deleteButton', [
                                            'route' => 'admin.menusReutilizaveis.destroy',
                                            'id' => $menu->id,
                                            'title' => __('Excluir'),
                                            'permission' => 'GERENCIADOR_DE_MENUS_REUTILIZAVEIS',
                                            'message' => __("* Este menu será excluído e esta ação não poderá ser desfeita, deseja continuar?"),
                                            'fontawesome' => null,
                                        ])
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="4">
                                    <p class="mb-0">{{ __('Nenhum menu encontrado.') }}</p>
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="row">
                <div class="col-12 my-3">
                    <div class="d-flex justify-content-center">{!! $menus->links() !!}</div>
                </div>
            </div>
        </div>
    </div>
@endsection

