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

    <ScrollView
        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_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="24dp">

            <!-- Title -->
            <TextView
                android:id="@+id/titleTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:text="Создать чат"
                android:textColor="@color/text_primary"
                android:textSize="24sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <!-- Chat Type Selection -->
            <TextView
                android:id="@+id/chatTypeLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:text="Тип чата"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/titleTextView" />

            <RadioGroup
                android:id="@+id/chatTypeRadioGroup"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:orientation="vertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/chatTypeLabel">

                <RadioButton
                    android:id="@+id/radioPersonal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Личный чат"
                    android:checked="true" />

                <RadioButton
                    android:id="@+id/radioGroup"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Групповой чат" />

                <RadioButton
                    android:id="@+id/radioExternal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Внешний чат" />

            </RadioGroup>

            <!-- Provider Info (hidden but used internally) -->
            <TextView
                android:id="@+id/providerInfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Используется CRM Chat Provider (ID: 994)"
                android:textColor="@color/text_hint"
                android:textSize="12sp"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/chatTypeRadioGroup" />

            <!-- Select User Button (Personal Chat) -->
            <TextView
                android:id="@+id/companionLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:text="Собеседник"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/providerInfo" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/selectUserButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="Выбрать пользователя"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/companionLabel" />

            <TextView
                android:id="@+id/selectedUserTextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:textColor="@color/text_secondary"
                android:textSize="14sp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/selectUserButton"
                tools:text="Выбран: Иван Иванов (ID: 12031100)" />

            <!-- Group Title -->
            <TextView
                android:id="@+id/groupTitleLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:text="Название группы"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/providerInfo" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/groupTitleInputLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:hint="Введите название группы"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/groupTitleLabel">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/groupTitleEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text" />

            </com.google.android.material.textfield.TextInputLayout>

            <!-- Participant IDs (Group Chat) - Hidden for simplified UI -->
            <TextView
                android:id="@+id/participantsLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="ID участников (через запятую)"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/groupTitleInputLayout" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/participantsInputLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:hint="1,2,3"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/participantsLabel">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/participantsEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text" />

            </com.google.android.material.textfield.TextInputLayout>

            <!-- External Chat Title -->
            <TextView
                android:id="@+id/externalTitleLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:text="Название чата"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/providerInfo" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/externalTitleInputLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:hint="Введите название чата"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/externalTitleLabel">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/externalTitleEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text" />

            </com.google.android.material.textfield.TextInputLayout>

            <!-- Entity ID -->
            <TextView
                android:id="@+id/entityLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="ID сущности (опционально)"
                android:textColor="@color/text_primary"
                android:textSize="16sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/externalTitleInputLayout" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/entityInputLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:hint="Введите ID сущности"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/entityLabel">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/entityEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="number" />

            </com.google.android.material.textfield.TextInputLayout>

            <!-- Create Button -->
            <com.google.android.material.button.MaterialButton
                android:id="@+id/createButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:backgroundTint="@color/primary"
                android:text="Создать чат"
                android:textColor="@color/white"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/groupTitleInputLayout" />

            <!-- Progress Bar -->
            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/createButton" />

            <!-- Error Text -->
            <TextView
                android:id="@+id/errorTextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:textColor="@color/error"
                android:textSize="14sp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/progressBar" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
