@extends('layout.layout')

@php
    $title = 'Tambah Role';
    $subTitle = 'Manajemen Roles Akses';
@endphp

@section('content')

    <div class="card basic-data-table">
        <div class="card-body">
            <div class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center mb-3 gap-3">
                <div>
                    <h5 class="mb-0">Tambah Role</h5>
                </div>
                <div class="d-flex gap-2">
                    <a href="{{ route('admin.roles.index') }}" class="btn btn-secondary btn-sm d-flex align-items-center gap-2">
                        <iconify-icon icon="iconoir:arrow-left"></iconify-icon>
                        <span>Kembali</span>
                    </a>
                </div>
            </div>

            @if ($errors->any())
                <div class="alert alert-danger"><ul class="mb-0">@foreach ($errors->all() as $error)<li>{{ $error }}</li>@endforeach</ul></div>
            @endif

            <form method="POST" action="{{ route('admin.roles.store') }}">
                @csrf
                <div class="row g-3">
                    <div class="col-12 col-md-6">
                        <label class="form-label">Nama Role</label>
                        <input type="text" name="name" class="form-control" required value="{{ old('name') }}" placeholder="Contoh: Kadis, PPKL, DLH">
                    </div>
                </div>

                <div class="mt-4">
                    <label class="form-label">Permissions</label>
                    <div class="row g-2">
                        @foreach($permissions as $perm)
                            <div class="col-12 col-md-4">
                                <div class="form-check style-check d-flex align-items-center">
                                    <input class="form-check-input border border-neutral-300 me-8" type="checkbox" name="permissions[]" value="{{ $perm->name }}" id="perm_{{ $perm->id }}">
                                    <label class="form-check-label" for="perm_{{ $perm->id }}">{{ $perm->name }}</label>
                                </div>
                            </div>
                        @endforeach
                    </div>
                </div>

                <div class="mt-4 d-flex gap-2">
                    <button class="btn btn-primary d-flex align-items-center gap-2">
                        <iconify-icon icon="material-symbols:save"></iconify-icon>
                        <span>Simpan</span>
                    </button>
                    <a href="{{ route('admin.roles.index') }}" class="btn btn-light">Batal</a>
                </div>
            </form>
        </div>
    </div>

@endsection
