<?xml version="1.0" encoding="utf-8"?>
<!--
  TimeLimit Copyright <C> 2019 Jonas Lochmann
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation version 3 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<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">

    <data>
        <variable
            name="primaryDeviceTitle"
            type="String" />

        <variable
            name="status"
            type="io.timelimit.android.ui.manage.child.primarydevice.PrimaryDeviceStatus" />

        <variable
            name="canAssignThisDevice"
            type="Boolean" />

        <import type="android.view.View" />
        <import type="io.timelimit.android.ui.manage.child.primarydevice.PrimaryDeviceStatus" />
    </data>

    <androidx.cardview.widget.CardView
        app:cardUseCompatPadding="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:padding="8dp"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:textAppearance="?android:textAppearanceLarge"
                android:text="@string/primary_device_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:textAppearance="?android:textAppearanceMedium"
                android:text="@string/primary_device_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <CheckBox
                android:enabled="@{status != PrimaryDeviceStatus.LocalMode}"
                android:text="@string/primary_device_checkbox_relax"
                android:id="@+id/relax_primary_device_checkbox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <View
                android:layout_width="match_parent"
                android:layout_height="8dp" />

            <TextView
                android:visibility="@{status == PrimaryDeviceStatus.LocalMode ? View.VISIBLE : View.GONE}"
                android:textAppearance="?android:textAppearanceMedium"
                android:text="@string/primary_device_status_local_mode"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:visibility="@{status == PrimaryDeviceStatus.NoDeviceSelected ? View.VISIBLE : View.GONE}"
                android:textAppearance="?android:textAppearanceMedium"
                android:text="@string/primary_device_status_no_device"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:visibility="@{status == PrimaryDeviceStatus.OtherDeviceSelected ? View.VISIBLE : View.GONE}"
                android:textAppearance="?android:textAppearanceMedium"
                tools:text="@string/primary_device_status_other_device"
                android:text="@{@string/primary_device_status_other_device(primaryDeviceTitle)}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/btn_assign"
                android:visibility="@{((status == PrimaryDeviceStatus.NoDeviceSelected) || (status == PrimaryDeviceStatus.OtherDeviceSelected)) &amp;&amp; safeUnbox(canAssignThisDevice) ? View.VISIBLE : View.GONE}"
                android:background="?selectableItemBackground"
                android:layout_gravity="end"
                android:text="@string/primary_device_btn_assign_this"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:visibility="@{status == PrimaryDeviceStatus.ThisDeviceSelected ? View.VISIBLE : View.GONE}"
                android:textAppearance="?android:textAppearanceMedium"
                android:text="@string/primary_device_status_this_device"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/btn_unassign"
                android:visibility="@{status == PrimaryDeviceStatus.ThisDeviceSelected ? View.VISIBLE : View.GONE}"
                android:background="?selectableItemBackground"
                android:layout_gravity="end"
                android:text="@string/primary_device_btn_unassign_this"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:textAppearance="?android:textAppearanceSmall"
                android:text="@string/purchase_required_info_only_networking"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>
    </androidx.cardview.widget.CardView>
</layout>
