<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_primary"
    tools:context=".activities.MainActivity">

    <!-- Sticky Header Section -->
    <LinearLayout
        android:id="@+id/stickyHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- Header Section -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:orientation="vertical"
            android:padding="28dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="16dp">

                <ImageView
                    android:layout_width="48dp"
                    android:layout_height="48dp"
                    android:layout_marginEnd="12dp"
                    android:src="@mipmap/ic_launcher"
                    android:contentDescription="App Icon" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="textbee.dev - sms gateway"
                        android:textColor="@color/white"
                        android:textSize="24sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.02"
                        android:shadowColor="#80000000"
                        android:shadowDx="0"
                        android:shadowDy="2"
                        android:shadowRadius="4" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4dp"
                        android:text="Streamline your SMS workflows"
                        android:textColor="@color/white"
                        android:textSize="13sp"
                        android:letterSpacing="0.01"
                        android:alpha="0.95" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <!-- Device Info Card -->
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="16dp"
            android:layout_marginTop="-24dp"
            android:layout_marginBottom="16dp"
            app:cardBackgroundColor="@color/background_secondary"
            app:cardCornerRadius="12dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:padding="12dp">

                <ImageView
                    android:layout_width="52dp"
                    android:layout_height="52dp"
                    android:layout_gravity="center"
                    android:padding="6dp"
                    android:src="@drawable/ic_baseline_phone_android_24"
                    android:tint="?attr/colorPrimary" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginStart="8dp"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/deviceBrandAndModelTxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Device Brand, Model"
                        android:textColor="@color/text_primary"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Device ID:"
                            android:textColor="@color/text_secondary"
                            android:textSize="12sp" />

                        <TextView
                            android:id="@+id/deviceIdTxt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="2dp"
                            android:text="ae5ce05c05cde3"
                            android:textColor="@color/text_primary"
                            android:textSize="12sp" />

                        <ImageButton
                            android:id="@+id/copyDeviceIdImgBtn"
                            android:layout_width="26dp"
                            android:layout_height="26dp"
                            android:layout_marginStart="4dp"
                            android:background="?attr/selectableItemBackgroundBorderless"
                            android:padding="4dp"
                            android:src="@drawable/ic_baseline_content_copy_24"
                            android:tint="?attr/colorPrimary" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:orientation="vertical">

                    <Switch
                        android:id="@+id/gatewaySwitch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minHeight="32dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Status"
                        android:textColor="@color/text_primary"
                        android:textSize="14sp"
                        android:textStyle="bold" />
                </LinearLayout>
            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </LinearLayout>

    <!-- Scrollable Content -->
    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/stickyHeader">

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

            <!-- API Key Registration Card -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:layout_marginBottom="16dp"
                app:cardBackgroundColor="@color/background_secondary"
                app:cardCornerRadius="12dp"
                app:cardElevation="4dp">

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

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="18dp"
                        android:text="Account Information"
                        android:textColor="@color/text_primary"
                        android:textSize="19sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.01" />

                    <!-- Device ID Input Field -->
                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="16dp"
                        android:hint="Device ID (optional)"
                        app:boxBackgroundColor="@android:color/transparent"
                        app:boxStrokeColor="?attr/colorPrimary"
                        app:hintTextColor="?attr/colorPrimary"
                        app:endIconMode="custom"
                        app:endIconDrawable="@drawable/ic_baseline_edit_24"
                        app:endIconTint="?attr/colorPrimary"
                        app:helperText="Leaving this field blank will register your device as new. If you have already registered this device previously, please enter the id here."
                        app:helperTextTextColor="@color/text_secondary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/deviceIdEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="text"
                            android:textColor="@color/text_primary"
                            android:textIsSelectable="true" />
                    </com.google.android.material.textfield.TextInputLayout>

                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="16dp"
                        android:hint="API Key"
                        app:boxBackgroundColor="@android:color/transparent"
                        app:boxStrokeColor="?attr/colorPrimary"
                        app:hintTextColor="?attr/colorPrimary"
                        app:endIconMode="password_toggle"
                        app:endIconTint="?attr/colorPrimary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/apiKeyEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="textPassword"
                            android:textColor="@color/text_primary"
                            android:textIsSelectable="true" />
                    </com.google.android.material.textfield.TextInputLayout>

                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="16dp"
                        android:hint="Device name (optional)"
                        app:boxBackgroundColor="@android:color/transparent"
                        app:boxStrokeColor="?attr/colorPrimary"
                        app:hintTextColor="?attr/colorPrimary"
                        app:endIconTint="?attr/colorPrimary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/deviceNameEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="text"
                            android:textColor="@color/text_primary"
                            android:textIsSelectable="true" />
                    </com.google.android.material.textfield.TextInputLayout>

                    <EditText
                        android:id="@+id/fcmTokenEditText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:enabled="false"
                        android:gravity="start|top"
                        android:hint="FCM Token"
                        android:inputType="textMultiLine"
                        android:textColor="@color/text_primary"
                        android:textColorHint="@color/text_secondary"
                        android:visibility="gone" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <Button
                            android:id="@+id/registerDeviceBtn"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:backgroundTint="@color/button_background_tint"
                            android:paddingHorizontal="28dp"
                            android:paddingVertical="12dp"
                            android:text="Connect"
                            android:textColor="@color/button_text_color"
                            android:textSize="15sp"
                            android:letterSpacing="0.01"
                            style="@style/Widget.MaterialComponents.Button"
                            app:cornerRadius="8dp" />

                        <View
                            android:layout_width="0dp"
                            android:layout_height="1dp"
                            android:layout_weight="1" />
                        <Button
                            android:id="@+id/scanQRButton"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:drawableLeft="@drawable/ic_baseline_qr_code_24"
                            android:drawablePadding="6dp"
                            android:paddingHorizontal="20dp"
                            android:paddingVertical="12dp"
                            android:text="Scan QR"
                            android:textColor="?attr/colorPrimary"
                            android:textSize="15sp"
                            android:letterSpacing="0.01"
                            android:backgroundTint="@android:color/transparent"
                            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
                            app:cornerRadius="8dp"
                            app:strokeColor="?attr/colorPrimary"
                            app:strokeWidth="1.5dp" />

                    </LinearLayout>
                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <!-- Configuration Card -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:layout_marginBottom="16dp"
                app:cardBackgroundColor="@color/background_secondary"
                app:cardCornerRadius="12dp"
                app:cardElevation="4dp">

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

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="18dp"
                        android:text="Configuration"
                        android:textColor="@color/text_primary"
                        android:textSize="19sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.01" />

                    <!-- Permissions Section -->
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginBottom="16dp">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="SMS Permissions"
                            android:textColor="@color/text_primary"
                            android:textSize="16sp"
                            android:textStyle="bold" />

                        <Button
                            android:id="@+id/grantSMSPermissionBtn"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:backgroundTint="@color/button_background_tint"
                            android:paddingHorizontal="24dp"
                            android:paddingVertical="12dp"
                            android:text="Grant SMS Permissions"
                            android:textColor="@color/button_text_color"
                            android:textSize="15sp"
                            android:letterSpacing="0.01"
                            android:visibility="visible"
                            style="@style/Widget.MaterialComponents.Button"
                            app:cornerRadius="8dp" />
                    </LinearLayout>

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1.5dp"
                        android:background="@color/divider"
                        android:alpha="0.6"
                        android:layout_marginBottom="18dp" />

                    <!-- Receive SMS Toggle -->
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        android:layout_marginBottom="16dp">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:orientation="vertical">

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Receive SMS"
                                android:textColor="@color/text_primary"
                                android:textSize="16sp"
                                android:textStyle="bold" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Toggle to enable SMS receiving"
                                android:textColor="@color/text_secondary"
                                android:textSize="14sp" />
                        </LinearLayout>

                        <Switch
                            android:id="@+id/receiveSMSSwitch"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:minHeight="32dp" />
                    </LinearLayout>

                    <!-- Filter Configuration Link -->
                    <Button
                        android:id="@+id/configureFilterBtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="16dp"
                        android:text="Configure Filter"
                        android:textColor="?attr/colorPrimary"
                        android:textSize="15sp"
                        android:letterSpacing="0.01"
                        android:backgroundTint="@android:color/transparent"
                        android:drawableStart="@android:drawable/ic_menu_manage"
                        android:drawablePadding="6dp"
                        android:paddingHorizontal="0dp"
                        style="@style/Widget.MaterialComponents.Button.TextButton" />

                    <!-- Sticky Notification Setting -->
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        android:layout_marginBottom="16dp">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:orientation="vertical">

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Sticky Notification"
                                android:textColor="@color/text_primary"
                                android:textSize="16sp"
                                android:textStyle="bold" />

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:gravity="center_vertical">
                                
                                <ImageView
                                    android:layout_width="18dp"
                                    android:layout_height="18dp"
                                    android:src="@android:drawable/ic_dialog_info"
                                    android:tint="?attr/colorPrimary"
                                    android:layout_marginEnd="6dp" />
                                
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Prevents app from being killed by the system (optional, but recommended for reliability)"
                                    android:textColor="@color/text_secondary"
                                    android:textSize="14sp" />
                            </LinearLayout>
                        </LinearLayout>

                        <Switch
                            android:id="@+id/stickyNotificationSwitch"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:minHeight="32dp" />
                    </LinearLayout>

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1.5dp"
                        android:background="@color/divider"
                        android:alpha="0.6"
                        android:layout_marginBottom="18dp" />

                    <!-- Default SIM Selection -->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Default SIM"
                        android:textColor="@color/text_primary"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="12dp"
                        android:text="This is the default SIM that will be used for sending SMS. You can override for individual SMS by providing the specific simSubscriptionId in your API request."
                        android:textColor="@color/text_secondary"
                        android:textSize="14sp"
                        android:lineSpacingMultiplier="1.2" />

                    <RadioGroup
                        android:id="@+id/defaultSimSlotRadioGroup"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginStart="8dp" />
                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <!-- How To Use Card -->
            <androidx.cardview.widget.CardView
                android:id="@+id/bottom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:layout_marginBottom="16dp"
                app:cardBackgroundColor="@color/background_secondary"
                app:cardCornerRadius="12dp"
                app:cardElevation="4dp">

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

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="12dp"
                        android:text="How To Use"
                        android:textColor="@color/text_primary"
                        android:textSize="19sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.01" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical">

                        <TextView
                            android:layout_width="28dp"
                            android:layout_height="28dp"
                            android:layout_marginEnd="12dp"
                            android:background="?attr/colorPrimary"
                            android:gravity="center"
                            android:text="1"
                            android:textColor="@color/white"
                            android:textSize="14sp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/dashboardLinkText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Go to https://textbee.dev/dashboard"
                            android:textColor="?attr/colorPrimary"
                            android:autoLink="web"
                            android:linksClickable="true"
                            android:clickable="true"
                            android:focusable="true" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical">

                        <TextView
                            android:layout_width="28dp"
                            android:layout_height="28dp"
                            android:layout_marginEnd="12dp"
                            android:background="?attr/colorPrimary"
                            android:gravity="center"
                            android:text="2"
                            android:textColor="@color/white"
                            android:textSize="14sp"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Click 'Generate API Key / Get Started'"
                            android:textColor="@color/text_primary" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical">

                        <TextView
                            android:layout_width="28dp"
                            android:layout_height="28dp"
                            android:layout_marginEnd="12dp"
                            android:background="?attr/colorPrimary"
                            android:gravity="center"
                            android:text="3"
                            android:textColor="@color/white"
                            android:textSize="14sp"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Copy the API key or scan the QR code"
                            android:textColor="@color/text_primary" />
                    </LinearLayout>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            
            <!-- App Version Info Card -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:layout_marginBottom="24dp"
                app:cardBackgroundColor="@color/background_secondary"
                app:cardCornerRadius="12dp"
                app:cardElevation="4dp">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_horizontal">

                        <ImageView
                            android:layout_width="36dp"
                            android:layout_height="36dp"
                            android:src="@drawable/ic_baseline_info_24"
                            android:tint="?attr/colorPrimary"
                            android:padding="4dp"
                            android:layout_marginEnd="14dp" />

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

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="App Information"
                                android:textColor="@color/text_primary"
                                android:textSize="16sp"
                                android:textStyle="bold" />

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:layout_marginTop="4dp">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Version: "
                                    android:textColor="@color/text_secondary"
                                    android:textSize="14sp" />

                                <TextView
                                    android:id="@+id/appVersionNameTxt"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="1.0.0"
                                    android:textColor="@color/text_primary"
                                    android:textSize="14sp"
                                    android:textStyle="bold" />
                                    
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text=" (Build: "
                                    android:textColor="@color/text_secondary"
                                    android:textSize="14sp"
                                    android:layout_marginStart="4dp" />
                                    
                                <TextView
                                    android:id="@+id/appVersionCodeTxt"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="100"
                                    android:textColor="@color/text_primary"
                                    android:textSize="14sp" />
                                    
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text=")"
                                    android:textColor="@color/text_secondary"
                                    android:textSize="14sp" />
                            </LinearLayout>
                            
                            <Button
                                android:id="@+id/checkUpdatesBtn"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="2dp"
                                android:text="Check for Updates"
                                android:textColor="?attr/colorPrimary"
                                android:background="@android:color/transparent"
                                android:textAllCaps="false"
                                android:paddingHorizontal="0dp"
                                style="@style/Widget.AppCompat.Button.Borderless" />
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>