@extends('dashboard') {{-- Apnar layout onujayi change kore nin --}}
@section('title','Admin Settings')
@section('page_content')
<div class="container mt-5">
    <div class="card shadow">
        <div class="card-header bg-primary text-white">
            <h4 class="mb-0">Assign Routes for {{ $user->name }}</h4>
        </div>
        <div class="card-body">
            @if(session('success'))
                <div class="alert alert-success">{{ session('success') }}</div>
            @endif

            <form action="{{ route('permissions.update', $user->id) }}" method="POST">
                @csrf
                
                <div class="row">
                    @foreach($routes as $route)
                        <div class="col-md-4 mb-2">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" name="routes[]" value="{{ $route }}" id="route_{{ $loop->index }}" 
                                    {{ in_array($route, $userPermissions) ? 'checked' : '' }}>
                                <label class="form-check-label text-break" for="route_{{ $loop->index }}">
                                    {{ $route }}
                                </label>
                            </div>
                        </div>
                    @endforeach
                </div>

                <div class="mt-4">
                    <button type="submit" class="btn btn-success px-4">Save Permissions</button>
                    <a href="{{ url('/') }}" class="btn btn-secondary">Back</a>
                </div>
            </form>
        </div>
    </div>
</div>

@endsection