<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/av_background"
    android:fitsSystemWindows="true">

    <!-- Main content -->
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="24dp"
            android:paddingBottom="80dp">

            <!-- Logo -->
            <ImageView
                android:id="@+id/logoImage"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="12dp"
                android:src="@drawable/av_logo"
                android:contentDescription="@string/app_name" />

            <!-- Header -->
            <TextView
                android:id="@+id/headerTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/passkey_registration_title"
                android:textSize="24sp"
                android:textStyle="bold"
                android:textColor="@color/av_text"
                android:gravity="center"
                android:layout_marginBottom="8dp" />

            <TextView
                android:id="@+id/headerSubtitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textColor="@color/av_text_muted"
                android:gravity="center"
                android:layout_marginBottom="24dp" />

            <!-- Create new button -->
            <com.google.android.material.button.MaterialButton
                android:id="@+id/createNewButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/passkey_create_new_button"
                android:textColor="#FFFFFF"
                android:backgroundTint="@color/av_primary"
                android:layout_marginBottom="24dp"
                app:cornerRadius="8dp"
                app:icon="@android:drawable/ic_lock_lock"
                app:iconTint="#FFFFFF"
                app:iconGravity="textStart"
                android:paddingVertical="14dp"
                android:textSize="16sp" />

            <!-- Section: Add to existing credential (no passkey yet) -->
            <LinearLayout
                android:id="@+id/existingItemsSection"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginBottom="24dp"
                android:visibility="gone">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/passkey_add_to_existing"
                    android:textSize="14sp"
                    android:textColor="@color/av_text"
                    android:textStyle="bold"
                    android:layout_marginBottom="12dp"
                    android:paddingStart="4dp"
                    android:paddingEnd="4dp" />

                <LinearLayout
                    android:id="@+id/existingItemsContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <!-- Items without passkeys will be added programmatically -->
                </LinearLayout>
            </LinearLayout>

            <!-- Section: Replace existing passkey -->
            <LinearLayout
                android:id="@+id/existingPasskeysSection"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="gone">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/passkey_select_to_replace"
                    android:textSize="14sp"
                    android:textColor="@color/av_text"
                    android:textStyle="bold"
                    android:layout_marginBottom="12dp"
                    android:paddingStart="4dp"
                    android:paddingEnd="4dp" />

                <LinearLayout
                    android:id="@+id/existingPasskeysContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <!-- Passkey items will be added programmatically -->
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <!-- Cancel button -->
            <com.google.android.material.button.MaterialButton
                android:id="@+id/cancelButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/common_cancel"
                android:textColor="@color/av_primary"
                style="@style/Widget.Material3.Button.TextButton"
                android:paddingVertical="14dp"
                android:textSize="16sp" />
        </LinearLayout>
    </ScrollView>

    <!-- Loading overlay -->
    <FrameLayout
        android:id="@+id/loadingOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#B3000000"
        android:visibility="gone"
        android:clickable="true"
        android:focusable="true">

        <net.aliasvault.app.components.LoadingIndicator
            android:id="@+id/loadingIndicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </FrameLayout>
</FrameLayout>
