@extends('layout.layout')

@php
    $title = 'Tambah Pengguna';
    $subTitle = 'Manajemen Pengguna';
@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 Pengguna</h5>
                </div>
                <div class="d-flex gap-2">
                    <a href="{{ route('admin.users.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.users.store') }}">
                @csrf
                <div class="row g-3">
                    <div class="col-12 col-md-6">
                        <label class="form-label">Nama Lengkap</label>
                        <input type="text" name="name" class="form-control" required value="{{ old('name') }}"
                            placeholder="Masukkan nama lengkap">
                    </div>
                    <div class="col-12 col-md-6">
                        <label class="form-label">Email</label>
                        <input type="email" name="email" class="form-control" required value="{{ old('email') }}"
                            placeholder="Masukkan email">
                    </div>
                    <div class="col-12 col-md-6">
                        <label class="form-label">Username</label>
                        <input type="text" name="username" class="form-control" required value="{{ old('username') }}"
                            placeholder="Masukkan username">
                    </div>
                    <div class="col-12 col-md-6">
                        <label class="form-label">Password</label>
                        <input type="password" name="password" class="form-control" required
                            placeholder="Masukkan password">
                        <div class="form-text">Password harus minimal 8 karakter, mengandung huruf besar, huruf kecil,
                            angka, dan simbol khusus.</div>
                    </div>
                    <div class="col-12 col-md-6">
                        <label class="form-label">Konfirmasi Password</label>
                        <input type="password" name="password_confirmation" class="form-control" required
                            placeholder="Konfirmasi password">
                    </div>
                </div>

                <div class="mt-4">
                    <label class="form-label">Roles</label>
                    <div class="row g-2">
                        @foreach ($roles as $role)
                            <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="roles[]" value="{{ $role->name }}" id="role_{{ $role->id }}"
                                        {{ in_array($role->name, old('roles', [])) ? 'checked' : '' }}>
                                    <label class="form-check-label"
                                        for="role_{{ $role->id }}">{{ $role->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.users.index') }}" class="btn btn-light">Batal</a>
                </div>
            </form>
        </div>
    </div>

@endsection
