<?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.SMSFilterActivity">

    <!-- Header Section -->
    <LinearLayout
        android:id="@+id/header"
        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_marginBottom="10dp">

            <ImageButton
                android:id="@+id/backButton"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:src="@android:drawable/ic_menu_revert"
                android:tint="@color/white"
                android:contentDescription="Back"
                android:padding="8dp" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="SMS Filter"
                android:textAlignment="center"
                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" />

            <View
                android:layout_width="48dp"
                android:layout_height="48dp" />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Configure SMS filtering rules"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:textSize="13sp"
            android:letterSpacing="0.01"
            android:alpha="0.95" />
    </LinearLayout>

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

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

            <!-- Filter Settings Card -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:layout_marginTop="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="Filter Settings"
                        android:textColor="@color/text_primary"
                        android:textSize="19sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.01" />

                    <!-- Filter Enabled 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="Enable Filter"
                                android:textColor="@color/text_primary"
                                android:textSize="16sp"
                                android:textStyle="bold" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Enable SMS filtering"
                                android:textColor="@color/text_secondary"
                                android:textSize="14sp" />
                        </LinearLayout>

                        <Switch
                            android:id="@+id/filterEnabledSwitch"
                            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" />

                    <!-- Filter Mode Selection -->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="12dp"
                        android:text="Filter Mode"
                        android:textColor="@color/text_primary"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <RadioGroup
                        android:id="@+id/filterModeRadioGroup"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginStart="8dp">

                        <RadioButton
                            android:id="@+id/allowListRadio"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Allow List (only process SMS matching these filters)"
                            android:textColor="@color/text_primary"
                            android:paddingVertical="8dp" />

                        <RadioButton
                            android:id="@+id/blockListRadio"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Block List (exclude these numbers/messages)"
                            android:textColor="@color/text_primary"
                            android:paddingVertical="8dp" />
                    </RadioGroup>
                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <!-- Filter Rules 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="Filter Rules"
                        android:textColor="@color/text_primary"
                        android:textSize="19sp"
                        android:textStyle="bold"
                        android:letterSpacing="0.01" />

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/filterRulesRecyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:nestedScrollingEnabled="false" />

                    <com.google.android.material.floatingactionbutton.FloatingActionButton
                        android:id="@+id/addRuleFab"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:layout_marginTop="16dp"
                        android:src="@android:drawable/ic_input_add"
                        app:tint="@color/white"
                        app:backgroundTint="?attr/colorPrimary" />
                </LinearLayout>
            </androidx.cardview.widget.CardView>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>
