@extends('admin.template')

@section('title', 'Profil Admin')

@endsection

@section('content')
<div class="content-wrapper">
    <div class="row justify-content-center">
        <div class="col-md-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">

                    <h4 class="mb-4 card-title">Profil Admin</h4>

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

                    <form action="{{ route('admin.profil.update') }}" method="POST" enctype="multipart/form-data">
                        @csrf

                        <div class="row">

                            {{-- KIRI : FOTO --}}
                            <div class="text-center col-md-4 border-right">

                                <img
                                    src="{{ $admin->foto
                                        ? asset('assets/admin/foto-admin/' . $admin->foto)
                                        : asset('assets/admin/images/user.jpg') }}"
                                    class="mb-3 rounded-circle"
                                    width="160"
                                    height="160"
                                    style="object-fit: cover;"
                                >

                                <div class="form-group">
                                    <input type="file"
                                           name="foto"
                                           class="form-control-file @error('foto') is-invalid @enderror">

                                    @error('foto')
                                        <div class="mt-1 text-danger">
                                            {{ $message }}
                                        </div>
                                    @enderror

                                    <small class="mt-2 text-muted d-block">
                                        JPG / PNG, maksimal 2MB
                                    </small>
                                </div>

                            </div>

                            {{-- KANAN : FORM --}}
                            <div class="col-md-8">

                                {{-- NAMA --}}
                                <div class="form-group">
                                    <label>Nama</label>
                                    <input type="text"
                                           name="name"
                                           class="form-control @error('name') is-invalid @enderror"
                                           value="{{ old('name', $admin->name) }}">

                                    @error('name')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>

                                {{-- USERNAME --}}
                                <div class="form-group">
                                    <label>Username</label>
                                    <input type="text"
                                           name="username"
                                           class="form-control @error('username') is-invalid @enderror"
                                           value="{{ old('username', $admin->username) }}">

                                    @error('username')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>

                                {{-- ROLE --}}
                                <div class="form-group">
                                    <label>Role</label>
                                    <input type="text"
                                           class="form-control"
                                           value="{{ $admin->role }}"
                                           disabled>
                                </div>

                                <hr>

                                {{-- PASSWORD --}}
                                <div class="form-group">
                                    <label>Password Baru (opsional)</label>
                                    <input type="password"
                                           name="password"
                                           class="form-control @error('password') is-invalid @enderror"
                                           placeholder="Kosongkan jika tidak diganti">

                                    @error('password')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>

                                {{-- KONFIRMASI PASSWORD --}}
                                <div class="form-group">
                                    <label>Konfirmasi Password</label>
                                    <input type="password"
                                           name="password_confirmation"
                                           class="form-control">
                                </div>

                                {{-- BUTTON --}}
                                <div class="mt-4">
                                    <button type="submit" class="btn btn-primary">
                                        Simpan
                                    </button>

                                    <a href="{{ url()->previous() }}"
                                       class="ml-2 btn btn-light">
                                        Batal
                                    </a>
                                </div>

                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection
