@extends('layouts.yellow')

@push('plugin-styles')
<link href="{{ asset('assets/plugins/datatables-net-bs5/dataTables.bootstrap5.css') }}" rel="stylesheet" />
@endpush

@section('content')
<nav class="page-breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{{route('dashboard')}}">Dashboard</a></li>
        <li class="breadcrumb-item active" aria-current="page">{{ __('common.route-permissions') }}</li>
    </ol>
</nav>

<div class="row">
    <div class="col-md-12 grid-margin stretch-card">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h6 class="card-title">{{ __('common.route-management') }}</h6>
                    <div>
                        <a href="{{ route('routes.create') }}" class="btn btn-primary btn-sm">
                            <i data-feather="plus"></i> {{ __('common.add-route') }}
                        </a>
                        <a href="{{ route('routes.detect') }}" class="btn btn-info btn-sm">
                            <i data-feather="search"></i> {{ __('common.detect-routes') }}
                        </a>
                    </div>
                </div>
                
                @if(session()->has('success'))
                <div class="alert alert-success">
                    {{ session()->get('success') }}
                </div>
                @endif

                <div class="table-responsive">
                    <table id="dataTableExample" class="table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>{{ __('common.path') }}</th>
                                <th>{{ __('common.description') }}</th>
                                <th>{{ __('common.is-public') }}</th>
                                <th>{{ __('common.roles') }}</th>
                                <th>{{ __('common.actions') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($routes as $route)
                            <tr>
                                <td>{{ $route->id }}</td>
                                <td>{{ $route->path }}</td>
                                <td>{{ $route->description }}</td>
                                <td>
                                    @if($route->is_public)
                                    <span class="badge bg-success">{{ __('common.yes') }}</span>
                                    @else
                                    <span class="badge bg-danger">{{ __('common.no') }}</span>
                                    @endif
                                </td>
                                <td>
                                    @foreach($route->roles as $role)
                                    <span class="badge bg-primary">{{ $role->display_name }}</span>
                                    @endforeach
                                </td>
                                <td>
                                    <a href="{{ route('routes.edit', $route->id) }}" class="btn btn-sm btn-outline-primary">
                                        <i data-feather="edit"></i>
                                    </a>
                                    <form action="{{ route('routes.destroy', $route->id) }}" method="POST" class="d-inline">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('{{ __('common.are-you-sure') }}')">
                                            <i data-feather="trash"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                
                <div class="mt-3">
                    {{ $routes->links() }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('plugin-scripts')
<script src="{{ asset('assets/plugins/datatables-net/jquery.dataTables.js') }}"></script>
<script src="{{ asset('assets/plugins/datatables-net-bs5/dataTables.bootstrap5.js') }}"></script>
@endpush

@push('custom-scripts')
<script src="{{ asset('assets/js/data-table.js') }}"></script>
@endpush
