<?xml version="1.0" encoding="utf-8"?>

<FrameLayout 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="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent">

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/card_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="12dp"
        app:cardBackgroundColor="?attr/colorSurface"
        app:cardElevation="8dp"
        app:contentPaddingBottom="16dp"
        app:contentPaddingLeft="16dp"
        app:contentPaddingRight="16dp"
        app:contentPaddingTop="10dp"
        app:strokeWidth="0dp">

        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/inner_frame"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent">

                <ImageView
                    android:id="@+id/share_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="-1dp"
                    android:layout_marginLeft="5dp"
                    android:background="@drawable/selector_compose_button"
                    android:clickable="true"
                    android:contentDescription="@string/share_via"
                    android:focusable="true"
                    android:padding="4dp"
                    app:layout_constraintBottom_toBottomOf="@+id/identity_label"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toEndOf="@+id/identity_label"
                    app:layout_constraintTop_toTopOf="@id/identity_label"
                    app:srcCompat="@drawable/ic_share_outline"
                    app:tint="?attr/colorOnSurface" />

                <LinearLayout
                    android:id="@+id/button_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:orientation="vertical"
                    app:layout_constrainedWidth="true"
                    app:layout_constraintBottom_toBottomOf="@id/qr_container"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@id/qr_container"
                    app:layout_constraintTop_toTopOf="@id/qr_container">

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/scan_button"
                        style="@style/Threema.MaterialButton.Action"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ellipsize="end"
                        android:maxLines="2"
                        android:text="@string/scan_id"
                        app:ensureMinTouchTargetSize="false"
                        app:icon="@drawable/ic_qr_code_scan" />

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/profile_button"
                        style="@style/Threema.MaterialButton.Action"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4dp"
                        android:ellipsize="end"
                        android:maxLines="2"
                        android:text="@string/my_profile"
                        app:ensureMinTouchTargetSize="false"
                        app:icon="@drawable/ic_profile" />

                </LinearLayout>

                <TextView
                    android:id="@+id/identity_label"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:contentDescription="@string/my_id"
                    android:textColor="?attr/colorOnBackground"
                    android:textSize="24sp"
                    app:layout_constraintBottom_toTopOf="@+id/barrier_above_qr_container_and_button_container"
                    app:layout_constraintEnd_toStartOf="@+id/share_button"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintHorizontal_chainStyle="packed"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintWidth_default="wrap"
                    app:lineHeight="24sp"
                    tools:text="00000000" />

                <TextView
                    android:id="@+id/web_label"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:background="?selectableItemBackground"
                    android:clickable="true"
                    android:ellipsize="end"
                    android:focusable="true"
                    android:maxLines="1"
                    android:paddingBottom="6dp"
                    android:paddingLeft="8dp"
                    android:paddingRight="2dp"
                    android:paddingTop="6dp"
                    android:text="@string/webclient"
                    android:textAppearance="@style/Threema.TextAppearance.BodyMedium"
                    app:layout_constraintBaseline_toBaselineOf="@+id/web_enable"
                    app:layout_constraintLeft_toRightOf="@+id/web_enable"
                    app:layout_constraintRight_toRightOf="parent"
                    tools:text="slakdjalkjdlkasjdkljaskljdklsajdkjaskldjklasjdklasjdkalksjdklsajdalksdjklasjdkljaslkdjlkasjd" />

                <!-- material switch currently has theming problems -->

                <androidx.constraintlayout.widget.Barrier
                    android:id="@+id/barrier_above_qr_container_and_button_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:barrierDirection="top"
                    app:constraint_referenced_ids="qr_container,button_container" />

                <androidx.constraintlayout.widget.Barrier
                    android:id="@+id/barrier_below_qr_container_and_button_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:barrierDirection="bottom"
                    app:constraint_referenced_ids="qr_container,button_container" />


                <androidx.constraintlayout.widget.Group
                    android:id="@+id/web_controls"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="visible"
                    app:constraint_referenced_ids="web_enable, web_label" />

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/qr_container"
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    app:cardBackgroundColor="?attr/colorSurface"
                    app:cardElevation="-8dp"
                    app:contentPadding="4dp"
                    app:layout_constraintBottom_toTopOf="@+id/web_enable"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/identity_label"
                    app:strokeColor="@color/material_green"
                    app:strokeWidth="2dp">

                    <ImageView
                        android:id="@+id/qr_image"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_gravity="center"
                        android:adjustViewBounds="false"
                        android:clickable="true"
                        android:contentDescription="@string/qr_code"
                        android:focusable="true"
                        android:foreground="?selectableItemBackground"
                        android:scaleType="fitCenter" />

                </com.google.android.material.card.MaterialCardView>

                <com.google.android.material.materialswitch.MaterialSwitch
                    android:id="@+id/web_enable"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="14dp"
                    android:contentDescription="@string/webclient_enable"
                    android:minHeight="0dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/barrier_below_qr_container_and_button_container"
                    app:switchPadding="0dp" />

            </androidx.constraintlayout.widget.ConstraintLayout>

        </ScrollView>

    </com.google.android.material.card.MaterialCardView>

    <!-- arrow -->

    <com.google.android.material.card.MaterialCardView
        android:layout_width="@dimen/identity_popup_arrow_width"
        android:layout_height="@dimen/identity_popup_arrow_height"
        android:layout_gravity="left|top"
        android:layout_marginLeft="@dimen/identity_popup_arrow_inset_left"
        android:importantForAccessibility="no"
        app:cardBackgroundColor="?attr/colorSurface"
        app:cardElevation="8dp"
        app:shapeAppearance="@style/Threema.ShapeAppearance.Arrow.Up"
        app:strokeWidth="0dp" />

</FrameLayout>
