<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/app_background"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="20dp"
        android:fontFamily="@font/open_sans_semibold"
        android:text="@string/qbooks_title"
        android:textColor="@color/ink_color"
        android:textSize="30sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="20dp"
        android:text="@string/qbooks_subtitle"
        android:textColor="@color/ink_soft_color"
        android:textSize="14sp" />

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/search_card"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        app:cardBackgroundColor="#F0F0F3"
        app:cardCornerRadius="27dp"
        app:cardElevation="0dp"
        app:strokeWidth="0dp">

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:boxBackgroundMode="none"
            app:endIconMode="clear_text"
            app:endIconTint="@color/ink_soft_color"
            app:hintEnabled="false"
            app:startIconDrawable="@drawable/ic_nav_search"
            app:startIconTint="@color/ink_soft_color">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/search_input"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:gravity="center_vertical"
                android:hint="@string/label_search_qbooks"
                android:imeOptions="actionSearch"
                android:paddingTop="0dp"
                android:paddingBottom="0dp"
                android:singleLine="true"
                android:textColor="@color/ink_color"
                android:textColorHint="@color/ink_soft_color"
                android:textSize="16sp" />
        </com.google.android.material.textfield.TextInputLayout>
    </com.google.android.material.card.MaterialCardView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="20dp"
        android:fontFamily="@font/open_sans_semibold"
        android:text="@string/search_genres_title"
        android:textColor="@color/ink_color"
        android:textSize="18sp" />

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:clipToPadding="false"
        android:scrollbars="none">

        <com.google.android.material.chip.ChipGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            app:chipSpacingHorizontal="8dp"
            app:singleLine="true">

            <com.google.android.material.chip.Chip android:id="@+id/genre_fantasy" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_fantasy" />
            <com.google.android.material.chip.Chip android:id="@+id/genre_detective" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_detective" />
            <com.google.android.material.chip.Chip android:id="@+id/genre_romance" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_romance" />
            <com.google.android.material.chip.Chip android:id="@+id/genre_fantasy_magic" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_fantasy_magic" />
            <com.google.android.material.chip.Chip android:id="@+id/genre_history" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_history" />
            <com.google.android.material.chip.Chip android:id="@+id/genre_science" style="@style/Widget.Material3.Chip.Assist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/genre_science" />
        </com.google.android.material.chip.ChipGroup>
    </HorizontalScrollView>

    <LinearLayout
        android:id="@+id/qbooks_actions_row"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:layout_marginStart="12dp"
        android:layout_marginTop="6dp"
        android:layout_marginEnd="12dp"
        android:gravity="end|center_vertical"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/refresh_catalog_button"
            android:layout_width="wrap_content"
            android:layout_height="44dp"
            android:gravity="center"
            android:paddingStart="10dp"
            android:paddingEnd="10dp"
            android:text="@string/action_refresh_catalog"
            android:textColor="@color/accent_color"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/catalog_settings_button"
            android:layout_width="wrap_content"
            android:layout_height="44dp"
            android:gravity="center"
            android:paddingStart="10dp"
            android:paddingEnd="10dp"
            android:text="@string/action_settings"
            android:textColor="@color/ink_soft_color"
            android:textSize="13sp" />
    </LinearLayout>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/catalog_overview_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="8dp"
        app:cardBackgroundColor="@color/white"
        app:cardCornerRadius="14dp"
        app:cardElevation="0dp"
        app:strokeColor="@color/border_color"
        app:strokeWidth="1dp">

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

            <TextView
                android:id="@+id/catalog_overview_title_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/open_sans_semibold"
                android:textColor="@color/ink_color"
                android:textSize="13sp" />

            <TextView
                android:id="@+id/catalog_status_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:textColor="@color/ink_soft_color"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/catalog_overview_meta_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:textColor="@color/accent_color"
                android:textSize="11sp" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/download_status_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="8dp"
        android:visibility="gone"
        app:cardBackgroundColor="@color/accent_soft_color"
        app:cardCornerRadius="14dp"
        app:cardElevation="0dp">

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

            <ProgressBar
                android:id="@+id/download_status_progress"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:indeterminateTint="@color/accent_color" />

            <TextView
                android:id="@+id/download_status_text"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_weight="1"
                android:textColor="@color/ink_color"
                android:textSize="13sp" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/not_configured_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:visibility="gone">

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="18dp">
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/open_sans_semibold" android:text="@string/status_qbooks_not_configured" android:textColor="@color/ink_color" android:textSize="18sp" />
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:text="@string/status_qbooks_not_configured_subtitle" android:textColor="@color/ink_soft_color" />
            <com.google.android.material.button.MaterialButton android:id="@+id/open_settings_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="@string/action_open_settings" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/error_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:visibility="gone">

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="18dp">
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/open_sans_semibold" android:text="@string/status_connection_failed" android:textColor="@color/ink_color" android:textSize="18sp" />
            <TextView android:id="@+id/error_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:textColor="@color/ink_soft_color" />
            <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:orientation="horizontal">
                <com.google.android.material.button.MaterialButton android:id="@+id/retry_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/action_retry" />
                <com.google.android.material.button.MaterialButton android:id="@+id/error_settings_button" style="@style/Widget.Aletheia.Button.Secondary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="@string/action_settings" />
            </LinearLayout>
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>

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

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/qbooks_recycler"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:contentDescription="@string/a11y_qbooks_list"
                android:paddingTop="4dp"
                android:paddingBottom="20dp" />
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/empty_results_card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_margin="20dp"
            android:visibility="gone"
            app:cardBackgroundColor="@color/white"
            app:cardCornerRadius="18dp"
            app:cardElevation="0dp">

            <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" android:padding="24dp">
                <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/open_sans_semibold" android:gravity="center" android:text="@string/status_empty_qbooks" android:textColor="@color/ink_color" android:textSize="19sp" />
                <TextView android:id="@+id/empty_results_detail_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center" android:textColor="@color/ink_soft_color" android:textSize="14sp" />
            </LinearLayout>
        </com.google.android.material.card.MaterialCardView>
    </FrameLayout>
</LinearLayout>
