<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/kbs_very_light_blue">

    <!-- SwipeRefreshLayout må pakke inn det skrollbare innholdet -->
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="8dp">

                <!-- OVERSKRIFT OG PROFIL -->
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:paddingHorizontal="8dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="KBS Intranett"
                        android:textSize="24sp"
                        android:textStyle="bold"
                        android:textColor="@color/kbs_muted_blue_gray"
                        android:layout_centerVertical="true"/>

                    <ImageView
                        android:id="@+id/btn_profile"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:src="@android:drawable/ic_menu_my_calendar"
                        android:background="?attr/selectableItemBackgroundBorderless"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        app:tint="@color/kbs_logo_blue"/>
                </RelativeLayout>

                <Button
                    android:id="@+id/btn_create_event"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="+ Ny Kalenderhendelse"
                    android:backgroundTint="@color/kbs_logo_blue"
                    android:textColor="#FFFFFF"
                    android:layout_marginHorizontal="8dp"
                    android:layout_marginBottom="12dp"
                    android:visibility="gone"/>

                <!-- KALENDER-SEKSJON -->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center_vertical"
                    android:layout_marginBottom="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Kommende hendelser"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:textColor="@color/black"/>

                    <TextView
                        android:id="@+id/btn_view_all_calendar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Se alle >"
                        android:textColor="@color/kbs_logo_blue"
                        android:textStyle="bold"
                        android:padding="8dp"
                        android:background="?attr/selectableItemBackground"/>
                </LinearLayout>

                <!-- ENDRET: Fast høyde for å skape "vindu" med scroll -->
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler_calendar"
                    android:layout_width="match_parent"
                    android:layout_height="190dp"
                    android:scrollbars="vertical"
                    android:layout_marginBottom="16dp"/>

                <!-- NYHETER-SEKSJON -->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center_vertical"
                    android:layout_marginBottom="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Siste nytt"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:textColor="@color/black"/>

                    <TextView
                        android:id="@+id/btn_view_all_news"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Se alle >"
                        android:textColor="@color/kbs_logo_blue"
                        android:textStyle="bold"
                        android:padding="8dp"
                        android:background="?attr/selectableItemBackground"/>
                </LinearLayout>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler_news"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:nestedScrollingEnabled="false"
                    android:scrollbars="vertical"/>

            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <!-- Initial Loader -->
    <ProgressBar
        android:id="@+id/main_loading_spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="visible"/>

</FrameLayout>