<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:elevation="0dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways|snap">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="16dp"
                android:paddingHorizontal="16dp"
                android:gravity="center_vertical">

                <Space
                    android:layout_width="48dp"
                    android:layout_height="0dp" />

                <TextView
                    android:id="@+id/title"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/multiplayer_room_browser"
                    android:textAppearance="@style/TextAppearance.Material3.TitleLarge" />

                <FrameLayout
                    android:layout_width="48dp"
                    android:layout_height="48dp">

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/refresh_button"
                        style="@style/Widget.Material3.Button.IconButton"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="center"
                        android:text="@string/refresh"
                        app:icon="@drawable/ic_refresh" />

                    <ProgressBar
                        android:id="@+id/progress_bar"
                        style="?android:attr/progressBarStyleSmall"
                        android:layout_width="24dp"
                        android:layout_height="24dp"
                        android:layout_gravity="center"
                        android:visibility="gone" />
                </FrameLayout>
            </LinearLayout>

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

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/search_background"
                    style="?attr/materialCardViewFilledStyle"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginTop="12dp"
                    app:cardCornerRadius="24dp">

                    <LinearLayout
                        android:id="@+id/search_container"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginStart="16dp"
                        android:layout_marginEnd="16dp"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginEnd="16dp"
                            android:src="@drawable/ic_search"
                            app:tint="?attr/colorOnSurfaceVariant" />

                        <EditText
                            android:id="@+id/search_text"
                            android:layout_width="180dp"
                            android:layout_height="match_parent"
                            android:background="@android:color/transparent"
                            android:hint="@string/multiplayer_search_public_lobbies"
                            android:imeOptions="flagNoFullscreen"
                            android:inputType="text"
                            android:maxLines="1" />

                    </LinearLayout>

                    <ImageView
                        android:id="@+id/clear_button"
                        android:layout_width="24dp"
                        android:layout_height="24dp"
                        android:layout_gravity="center_vertical|end"
                        android:layout_marginEnd="48dp"
                        android:background="?attr/selectableItemBackground"
                        android:src="@drawable/ic_clear"
                        android:visibility="invisible"
                        app:tint="?attr/colorOnSurfaceVariant"
                        tools:visibility="visible" />

                    <ImageView
                        android:id="@+id/btn_submit"
                        android:layout_width="24dp"
                        android:layout_height="24dp"
                        android:layout_gravity="center_vertical|end"
                        android:layout_marginEnd="16dp"
                        android:background="?attr/selectableItemBackground"
                        android:src="@drawable/ic_send"
                        android:contentDescription="@string/submit"
                        app:tint="?attr/colorOnSurfaceVariant"
                        tools:visibility="visible" />

                </com.google.android.material.card.MaterialCardView>

            </LinearLayout>


            <HorizontalScrollView
                android:id="@+id/horizontalScrollView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fadingEdge="horizontal"
                android:scrollbars="none"
                android:layout_marginVertical="8dp"
                android:clipToPadding="false"
                android:paddingHorizontal="16dp">

                <LinearLayout
                    android:id="@+id/chips"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clipToPadding="false">

                    <com.google.android.material.chip.Chip
                        android:id="@+id/chip_hide_empty"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:checkable="true"
                        android:checked="false"
                        android:text="@string/multiplayer_hide_empty_rooms"
                        app:chipCornerRadius="16dp" />

                    <com.google.android.material.chip.Chip
                        android:id="@+id/chip_hide_full"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:checkable="true"
                        android:checked="false"
                        android:text="@string/multiplayer_hide_full_rooms"
                        app:chipCornerRadius="16dp" />

                </LinearLayout>
            </HorizontalScrollView>
        </LinearLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/room_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:contentDescription="@string/room_list"
        android:paddingBottom="16dp"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <LinearLayout
        android:id="@+id/empty_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:gravity="center"
        android:padding="32dp"
        android:visibility="gone">

        <ImageView
            android:layout_width="72dp"
            android:layout_height="72dp"
            android:layout_marginBottom="16dp"
            android:src="@drawable/ic_refresh"
            android:alpha="0.5"
            app:tint="?attr/colorOnSurface" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/multiplayer_no_rooms_found"
            android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/multiplayer_tap_refresh_to_check_again"
            android:textAppearance="@style/TextAppearance.Material3.BodyMedium" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/empty_refresh_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="@string/refresh"
            app:icon="@drawable/ic_refresh" />
    </LinearLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>