<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/page_background"
        android:fillViewport="true">

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

            <!-- Menu Button (Top Right) to Open Drawer -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="end"
                android:layout_marginBottom="16dp">
                
                <ImageButton
                    android:id="@+id/btnMenu"
                    android:layout_width="48dp"
                    android:layout_height="48dp"
                    android:src="@android:drawable/ic_menu_sort_by_size"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:backgroundTint="@color/icon_tint_primary"
                    android:contentDescription="Settings"
                    app:tint="@color/icon_tint_primary"/>
            </LinearLayout>

            <!-- Cow Illustration - Circular Logo -->
            <androidx.cardview.widget.CardView
                android:layout_width="180dp"
                android:layout_height="180dp"
                app:cardCornerRadius="90dp"
                app:cardElevation="8dp"
                app:cardBackgroundColor="@color/surface_background"
                android:layout_marginBottom="24dp">
                
                <ImageView
                    android:id="@+id/ivCowIllustration"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/cow_illustration_0"
                    android:scaleType="centerCrop"
                    android:contentDescription="Cow Illustration"/>
            </androidx.cardview.widget.CardView>

            <!-- Title -->
            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cow Data Collector"
                android:textSize="28sp"
                android:textStyle="bold"
                android:textColor="@color/text_primary"
                android:textAlignment="center"
                android:layout_marginBottom="8dp"/>

            <!-- Subtitle -->
            <TextView
                android:id="@+id/tvSubtitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Record and manage cow information easily."
                android:textSize="16sp"
                android:textColor="@color/text_tertiary"
                android:textAlignment="center"
                android:layout_marginBottom="40dp"/>

            <!-- Main Buttons Container -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginBottom="32dp">

                <!-- Add New Cow Profile Button -->
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnSelectCow"
                    android:layout_width="match_parent"
                    android:layout_height="72dp"
                    android:text="Add New Cow Profile"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:textColor="@color/white"
                    app:cornerRadius="16dp"
                    app:backgroundTint="@color/earthy"
                    app:icon="@android:drawable/ic_input_add"
                    app:iconGravity="textStart"
                    app:iconPadding="12dp"
                    app:iconTint="@color/white"
                    android:layout_marginBottom="16dp"
                    android:elevation="4dp"/>

                <!-- View Saved Profiles Button -->
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnViewGallery"
                    android:layout_width="match_parent"
                    android:layout_height="72dp"
                    android:text="View Saved Profiles"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:textColor="@color/icon_tint_primary"
                    app:cornerRadius="16dp"
                    app:backgroundTint="@color/input_background"
                    app:strokeColor="@color/icon_tint_primary"
                    app:strokeWidth="1dp"
                    app:icon="@android:drawable/ic_menu_gallery"
                    app:iconTint="@color/icon_tint_primary"
                    app:iconGravity="textStart"
                    app:iconPadding="12dp"
                    android:elevation="4dp"/>
            </LinearLayout>

            <!-- Settings Card -->
            <androidx.cardview.widget.CardView
                android:id="@+id/viewSettings"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cardCornerRadius="16dp"
                app:cardElevation="2dp"
                app:cardBackgroundColor="@color/surface_background"
                android:layout_marginBottom="24dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="20dp">

                    <TextView
                        android:id="@+id/tvHeaderSettings"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Debug Configs"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:textColor="@color/text_primary"
                        android:layout_marginBottom="16dp"/>

                    <!-- Algorithm Selection -->
                    <TextView
                        android:id="@+id/tvAlgorithmLabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Algorithm"
                        android:textSize="14sp"
                        android:textColor="@color/text_secondary"
                        android:layout_marginBottom="8dp"/>

                    <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/bg_spinner_rounded"
                        android:backgroundTint="@color/input_background"
                        android:padding="4dp"
                        android:layout_marginBottom="20dp">
                        <Spinner
                            android:id="@+id/spinnerAlgorithm"
                            android:layout_width="match_parent"
                            android:layout_height="48dp"
                            android:backgroundTint="@color/text_primary"/>
                    </FrameLayout>

                    <!-- Threshold Slider -->
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        android:layout_marginBottom="8dp">
                        
                        <TextView
                            android:id="@+id/tvThresholdLabel"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Match Threshold"
                            android:textSize="14sp"
                            android:textColor="@color/text_secondary"/>
                        
                        <TextView
                            android:id="@+id/tvThresholdValue"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="75%"
                            android:textStyle="bold"
                            android:textColor="@color/text_primary"/>
                    </LinearLayout>

                    <SeekBar
                        android:id="@+id/seekBarThreshold"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:max="100"
                        android:progressTint="@color/earthy"
                        android:thumbTint="@color/earthy"
                        android:layout_marginBottom="16dp"/>
                        
                    <!-- Mask Display Toggle -->
                    <com.google.android.material.switchmaterial.SwitchMaterial
                        android:id="@+id/switchMaskDisplay"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Show Segmentation Mask"
                        android:textColor="@color/text_primary"
                        android:textSize="14sp"
                        app:thumbTint="@color/earthy"
                        app:trackTint="@color/input_background"/>
                        
                </LinearLayout>
            </androidx.cardview.widget.CardView>

        </LinearLayout>
    </ScrollView>

    <!-- Navigation Drawer Content (Direct LinearLayout) -->
    <LinearLayout
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/surface_background"
        android:orientation="vertical"
        android:padding="16dp"
        android:clickable="true"
        android:focusable="true"
        android:elevation="16dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Menu"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="@color/text_primary"
            android:layout_marginBottom="24dp"/>

        <!-- Language Selection -->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Language"
            android:textColor="@color/text_secondary"
            android:layout_marginBottom="8dp"/>
        
        <Spinner
            android:id="@+id/spinnerLanguage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:background="@drawable/bg_spinner_rounded"
            android:backgroundTint="@color/input_background"
            android:layout_marginBottom="24dp"/>

        <!-- Auto Capture Toggle -->
        <com.google.android.material.switchmaterial.SwitchMaterial
            android:id="@+id/switchAutoCapture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Auto Capture"
            android:textColor="@color/text_primary"
            android:textSize="14sp"
            app:thumbTint="@color/earthy"
            app:trackTint="@color/input_background"
            android:layout_marginBottom="16dp"/>

        <!-- Enable Debug Toggle -->
        <com.google.android.material.switchmaterial.SwitchMaterial
            android:id="@+id/switchEnableDebug"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Enable Debug"
            android:textColor="@color/text_primary"
            android:textSize="14sp"
            app:thumbTint="@color/earthy"
            app:trackTint="@color/input_background"
            android:layout_marginBottom="16dp"/>

    </LinearLayout>

</androidx.drawerlayout.widget.DrawerLayout>