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

    <data>

        <import type="com.wireguard.android.backend.Tunnel.State" />

        <import type="com.getbubblenow.android.util.ClipboardUtils" />

        <variable
            name="fragment"
            type="com.getbubblenow.android.fragment.TunnelDetailFragment" />

        <variable
            name="tunnel"
            type="com.getbubblenow.android.model.ObservableTunnel" />

        <variable
            name="config"
            type="com.wireguard.config.Config" />
    </data>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?attr/colorBackground"
        android:clickable="true"
        android:focusable="true">

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

            <com.google.android.material.card.MaterialCardView
                android:id="@+id/tunnel_detail_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

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

                    <com.google.android.material.textview.MaterialTextView
                        android:id="@+id/interface_title"
                        style="@style/SectionText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/interface_title"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <com.getbubblenow.android.widget.ToggleSwitch
                        android:id="@+id/tunnel_switch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="16dp"
                        app:checked="@{tunnel.state == State.UP}"
                        app:layout_constraintBaseline_toBaselineOf="@+id/interface_title"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:onBeforeCheckedChanged="@{fragment::setTunnelState}" />

                    <TextView
                        android:id="@+id/interface_name_label"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/interface_name_text"
                        android:text="@string/name"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/interface_title" />

                    <TextView
                        android:id="@+id/interface_name_text"
                        style="@style/DetailText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/name"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{tunnel.name}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/interface_name_label"
                        tools:text="wg0" />

                    <TextView
                        android:id="@+id/public_key_label"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/public_key_text"
                        android:text="@string/public_key"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/interface_name_text" />

                    <TextView
                        android:id="@+id/public_key_text"
                        style="@style/DetailText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/public_key"
                        android:ellipsize="end"
                        android:maxLines="1"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:singleLine="true"
                        android:text="@{config.interface.keyPair.publicKey.toBase64}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/public_key_label"
                        tools:text="wOs2eguFEohqIZxlSJ1CAT9584tc6ejj9hfGFsoBVkA=" />

                    <TextView
                        android:id="@+id/addresses_label"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/addresses_text"
                        android:text="@string/addresses"
                        android:visibility="@{config.interface.addresses.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/public_key_text" />

                    <TextView
                        android:id="@+id/addresses_text"
                        style="@style/DetailText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/addresses"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{config.interface.addresses}"
                        android:visibility="@{config.interface.addresses.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/addresses_label"
                        tools:text="fc00:bbbb:bbbb:bb11::3:368b/128" />

                    <TextView
                        android:id="@+id/dns_servers_label"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/dns_servers_text"
                        android:text="@string/dns_servers"
                        android:visibility="@{config.interface.dnsServers.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/addresses_text" />

                    <TextView
                        android:id="@+id/dns_servers_text"
                        style="@style/DetailText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/dns_servers"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{config.interface.dnsServers}"
                        android:visibility="@{config.interface.dnsServers.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/dns_servers_label"
                        tools:text="8.8.8.8, 8.8.4.4" />

                    <TextView
                        android:id="@+id/listen_port_label"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/listen_port_text"
                        android:text="@string/listen_port"
                        android:visibility="@{config.interface.listenPort.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintEnd_toStartOf="@id/mtu_label"
                        app:layout_constraintHorizontal_weight="0.5"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/dns_servers_text" />

                    <TextView
                        android:id="@+id/listen_port_text"
                        style="@style/DetailText"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/listen_port"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{config.interface.listenPort}"
                        android:visibility="@{config.interface.listenPort.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintEnd_toStartOf="@id/mtu_label"
                        app:layout_constraintHorizontal_weight="0.5"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/listen_port_label"
                        tools:text="51820" />

                    <TextView
                        android:id="@+id/mtu_label"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/mtu_text"
                        android:text="@string/mtu"
                        android:visibility="@{config.interface.mtu.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_weight="0.5"
                        app:layout_constraintLeft_toRightOf="@id/listen_port_label"
                        app:layout_constraintStart_toEndOf="@id/listen_port_label"
                        app:layout_constraintTop_toBottomOf="@id/dns_servers_text" />

                    <TextView
                        android:id="@+id/mtu_text"
                        style="@style/DetailText"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/mtu"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{config.interface.mtu}"
                        android:visibility="@{config.interface.mtu.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_weight="0.5"
                        app:layout_constraintStart_toEndOf="@id/listen_port_label"
                        app:layout_constraintStart_toStartOf="@+id/mtu_label"
                        app:layout_constraintTop_toBottomOf="@+id/mtu_label"
                        tools:text="1500" />

                    <TextView
                        android:id="@+id/applications_label"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:labelFor="@+id/applications_text"
                        android:text="@string/applications"
                        android:visibility="@{config.interface.includedApplications.isEmpty() &amp;&amp; config.interface.excludedApplications.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/listen_port_text" />

                    <TextView
                        android:id="@+id/applications_text"
                        style="@style/DetailText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/applications"
                        android:onClick="@{ClipboardUtils::copyTextView}"
                        android:text="@{config.interface.includedApplications.isEmpty() ? @plurals/n_excluded_applications(config.interface.excludedApplications.size(), config.interface.excludedApplications.size()) : @plurals/n_included_applications(config.interface.includedApplications.size(), config.interface.includedApplications.size())}"
                        android:visibility="@{config.interface.includedApplications.isEmpty() &amp;&amp; config.interface.excludedApplications.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/applications_label"
                        tools:text="8 excluded" />
                </androidx.constraintlayout.widget.ConstraintLayout>
            </com.google.android.material.card.MaterialCardView>

            <LinearLayout
                android:id="@+id/peers_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:divider="@null"
                android:orientation="vertical"
                app:items="@{config.peers}"
                app:layout="@{@layout/tunnel_detail_peer}"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tunnel_detail_card"
                tools:ignore="UselessLeaf" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
</layout>
