<?xml version="1.0" encoding="utf-8"?>
<layout 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"
    xmlns:card_view="http://schemas.android.com/tools">
    <data>
        <variable
            name="viewModel"
            type="au.gov.health.covidsafe.ui.home.HomeFragmentViewModel" />

        <import type="au.gov.health.covidsafe.ui.home.CaseNumbersState" />
    </data>
    <merge>

        <androidx.cardview.widget.CardView
            android:id="@+id/case_number_card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/space_24"
            app:layout_constraintTop_toBottomOf="@+id/case_top_barrier"
            card_view:cardBackgroundColor="@color/white"
            card_view:cardCornerRadius="0dp"
            card_view:cardMaxElevation="@dimen/card_elevation_10dp"
            card_view:cardUseCompatPadding="true"
            card_view:contentPadding="0dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:id="@+id/case_loading_view"
                    visibility="@{viewModel.caseNumberDataState == CaseNumbersState.LOADING}"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/case_number_loading_card_height"
                    android:visibility="gone">

                    <com.airbnb.lottie.LottieAnimationView
                        android:id="@+id/case_loading_animation_view"
                        android:layout_width="@dimen/covidsafe_loading_animation_size"
                        android:layout_height="@dimen/covidsafe_loading_animation_size"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="@dimen/space_24"
                        android:layout_marginBottom="@dimen/space_24"
                        app:lottie_autoPlay="true"
                        app:lottie_fileName="loading_upload.json"
                        app:lottie_loop="true"
                        app:lottie_speed="1" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/case_loading_animation_view"
                        android:layout_centerHorizontal="true"
                        android:text="@string/loading_numbers"
                        android:textAppearance="@style/fontRobotoRegular16"
                        android:textColor="@color/slate_black_1" />

                </RelativeLayout>

                <LinearLayout
                    visibility="@{viewModel.caseNumberDataState != CaseNumbersState.LOADING}"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="60dp">

                    <TextView
                        android:id="@+id/national_numbers_text_view"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_marginStart="@dimen/space_16"
                        android:gravity="center_vertical"
                        android:text="@{viewModel.titleOfNumber}"
                        android:textSize="20sp"
                        android:textAppearance="@style/fontRobotoRegular28"
                        android:textColor="@color/slate_black_1"
                        android:textStyle="bold" />

                        <TextView
                            android:id="@+id/txt_show_number"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_marginEnd="@dimen/space_16"
                            android:gravity="center_vertical"
                            android:text="@string/show"
                            android:textAppearance="@style/fontRobotoRegular28"
                            android:textColor="@color/dark_green"
                            android:textSize="@dimen/text_size_16"
                            android:layout_alignParentEnd="true"
                            style="@style/fontRobotoRegular20"
                            visibility="@{!viewModel.turnCaseNumber}"
                            android:onClick="@{() -> viewModel.turnCaseNumber(true)}"/>

                        <TextView
                            android:id="@+id/txt_hide_number"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_marginEnd="@dimen/space_16"
                            android:gravity="center_vertical"
                            android:text="@string/hide"
                            android:textAppearance="@style/fontRobotoRegular28"
                            android:textColor="@color/dark_green"
                            android:textSize="@dimen/text_size_16"
                            android:layout_alignParentEnd="true"
                            style="@style/fontRobotoRegular20"
                            visibility="@{viewModel.turnCaseNumber}"
                            android:onClick="@{() -> viewModel.turnCaseNumber(false)}"/>

                    </RelativeLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="@dimen/space_16"
                        android:layout_marginBottom="@dimen/space_16"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        visibility="@{viewModel.isV2Available}"
                        android:onClick="@{() -> viewModel.showSelectSate(true)}">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_map_pin"
                            android:layout_alignParentEnd="true"
                            android:layout_below="@+id/txt_show_number"
                            android:foregroundGravity="left"/>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/dark_green"
                            android:layout_marginStart="@dimen/space_8"
                            android:text="@string/select_state_territory_heading"
                            style="@style/fontRobotoRegular16"/>

                    </LinearLayout>
                    <FrameLayout
                        android:id="@+id/show_error_message"
                        visibility="@{viewModel.caseNumberDataState == CaseNumbersState.ERROR_NO_NETWORK || viewModel.caseNumberDataState == CaseNumbersState.ERROR_UNKNOWN}"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:id="@+id/no_network_error_text_view"
                            visibility="@{viewModel.caseNumberDataState == CaseNumbersState.ERROR_NO_NETWORK}"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/space_16"
                            android:layout_marginEnd="@dimen/space_16"
                            android:layout_marginBottom="@dimen/space_16"
                            android:text="@string/numbers_no_internet"
                            android:textAppearance="@style/fontRobotoRegular16"
                            android:textColor="@color/error_red"
                            android:visibility="gone" />

                        <TextView
                            android:id="@+id/unknown_error_text_view"
                            visibility="@{viewModel.caseNumberDataState == CaseNumbersState.ERROR_UNKNOWN &amp; !viewModel.getStatisticSuccessfull}"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/space_16"
                            android:layout_marginEnd="@dimen/space_16"
                            android:clickable="true"
                            android:focusable="true"
                            android:text="@string/numbers_error"
                            android:textAppearance="@style/fontRobotoRegular16"
                            android:textColor="@color/error_red"
                            android:visibility="gone" />

                    </FrameLayout>

                    <TextView
                        android:id="@+id/refresh_button"
                        addUnderline="@{@string/numbers_refresh}"
                        visibility="@{viewModel.caseNumberDataState == CaseNumbersState.ERROR_UNKNOWN &amp; !viewModel.getStatisticSuccessfull}"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@color/transparent"
                        android:clickable="true"
                        android:focusable="true"
                        android:paddingStart="@dimen/space_16"
                        android:paddingTop="@dimen/space_16"
                        android:paddingEnd="@dimen/space_16"
                        android:paddingBottom="@dimen/space_16"
                        android:textAppearance="@style/fontRobotoRegular16"
                        android:textColor="@color/dark_green"
                        android:visibility="gone" />

                    <include
                        layout="@layout/view_state_case_statistics"
                        app:viewModel="@{viewModel}" />

                </LinearLayout>

            </FrameLayout>

        </androidx.cardview.widget.CardView>

    </merge>

</layout>
