<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".ui.main.MainActivity">

    <!-- Toolbar -->
    <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/primary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.Material3.Dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:title=""
            app:titleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">

        <!-- Logo Block -->
        <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:orientation="horizontal"
                android:gravity="center_vertical">

            <ImageView
                    android:id="@+id/logoImageView"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:contentDescription="Medical Control Logo"
                    android:scaleType="centerInside"
                    android:src="@mipmap/ic_launcher"
                    android:tint="@android:color/white"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="12dp"
                    android:text="Medical Control"
                    android:textColor="@android:color/white"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif-medium"/>

        </LinearLayout>

        <!-- Menu Button -->
        <ImageButton
                android:id="@+id/menuButton"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_gravity="end"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:contentDescription="Menu"
                android:padding="12dp"
                android:scaleType="centerInside"
                android:src="@drawable/ic_menu"
                android:visibility="visible" />

    </androidx.appcompat.widget.Toolbar>

    <!-- SwipeRefreshLayout for chat list -->
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <!-- RecyclerView for chat list -->
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/chatsRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:padding="8dp"
            tools:listitem="@layout/item_chat" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <!-- Empty state -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/emptyStateLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <TextView
            android:id="@+id/emptyStateTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no_chats"
            android:textColor="@color/text_secondary"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <!-- Loading state -->
    <ProgressBar
        android:id="@+id/loadingProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <!-- Error state -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/errorStateLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <TextView
            android:id="@+id/errorTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:text="@string/error_loading_chats"
            android:textColor="@color/error"
            android:textSize="16sp"
            app:layout_constraintBottom_toTopOf="@id/retryButton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/retryButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/retry"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <!-- Floating Action Button for creating new chat -->
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/createChatFab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:contentDescription="@string/create_chat"
        android:src="@drawable/ic_add"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:tint="@color/white" />

</androidx.constraintlayout.widget.ConstraintLayout>
