<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-white py-3">
                    <h5 class="mb-0">{{ if .IsEdit }}Kullanıcı Düzenle{{ else }}Yeni Kullanıcı Oluştur{{ end }}</h5>
                </div>
                <div class="card-body p-4">
                    <form
                        action="{{ if .IsEdit }}/admin/users/{{ .User.ID }}/update{{ else }}/admin/users/create{{ end }}"
                        method="POST" enctype="multipart/form-data">
                        <div class="mb-3">
                            <label for="username" class="form-label">Kullanıcı Adı</label>
                            <input type="text" class="form-control" id="username" name="username"
                                value="{{ if .IsEdit }}{{ .User.UserName }}{{ end }}" required>
                        </div>
                        <div class="mb-3">
                            <label for="email" class="form-label">E-posta</label>
                            <input type="email" class="form-control" id="email" name="email"
                                value="{{ if .IsEdit }}{{ .User.Email }}{{ end }}" required>
                        </div>
                        <div class="mb-3">
                            <label for="password" class="form-label">Şifre {{ if .IsEdit }}<small
                                    class="text-muted">(Boş bırakılırsa değişmez)</small>{{ end }}</label>
                            <input type="password" class="form-control" id="password" name="password" {{ if not .IsEdit
                                }}required{{ end }}>
                        </div>
                        <div class="form-check mb-3">
                            <input class="form-check-input" type="checkbox" id="is_admin" name="is_admin" {{ if .IsEdit
                                }}{{ if isTrue .User.IsAdmin }}checked{{ end }}{{ end }}>
                            <label class="form-check-label" for="is_admin">
                                Yönetici (Admin)
                            </label>
                        </div>
                        <div class="form-check mb-3">
                            <input class="form-check-input" type="checkbox" id="email_verified" name="email_verified" {{
                                if .IsEdit }}{{ if isTrue .User.EmailVerified }}checked{{ end }}{{ end }}>
                            <label class="form-check-label" for="email_verified">
                                E-posta Doğrulanmış
                            </label>
                        </div>

                        <!-- Profile fields -->
                        <div class="mb-3">
                            <label for="first_name" class="form-label">İsim</label>
                            <input type="text" class="form-control" id="first_name" name="first_name"
                                value="{{ if .IsEdit }}{{ if .User.Profile }}{{ range .User.Profile }}{{ .FirstName }}{{ end }}{{ end }}{{ end }}">
                        </div>
                        <div class="mb-3">
                            <label for="last_name" class="form-label">Soyisim</label>
                            <input type="text" class="form-control" id="last_name" name="last_name"
                                value="{{ if .IsEdit }}{{ if .User.Profile }}{{ range .User.Profile }}{{ .LastName }}{{ end }}{{ end }}{{ end }}">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Avatar</label>
                            <input type="file" class="form-control" name="avatar" accept="image/*">
                            {{ if .IsEdit }}
                            {{ if .User.Profile }}
                            {{ range .User.Profile }}
                            {{ if .AvatarURL }}
                            <div class="mt-2">
                                <img src="{{ .AvatarURL }}" width="64" height="64" class="rounded-circle">
                            </div>
                            {{ end }}
                            {{ end }}
                            {{ end }}
                            {{ end }}
                        </div>

                        <div class="d-flex justify-content-end gap-2">
                            <a href="/admin/content/users" class="btn btn-secondary">İptal</a>
                            <button type="submit" class="btn btn-primary">Kaydet</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>