package com.aiosman.riderpro.ui.favourite

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.paging.compose.collectAsLazyPagingItems
import com.aiosman.riderpro.R
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
import com.aiosman.riderpro.ui.like.ActionPostNoticeItem

/**
 * 收藏消息界面
 */
@Composable
fun FavouriteNoticeScreen() {
    val model = FavouriteNoticeViewModel
    val listState = rememberLazyListState()
    var dataFlow = model.favouriteItemsFlow
    var favourites = dataFlow.collectAsLazyPagingItems()
    LaunchedEffect(Unit) {
        model.reload()
        model.updateNotice()
    }
    StatusBarMaskLayout(
        darkIcons = true,
        maskBoxBackgroundColor = Color(0xFFFFFFFF)
    ) {
        Column(
            modifier = Modifier
                .weight(1f)
                .background(color = Color(0xFFFFFFFF))
                .padding(horizontal = 16.dp)
        ) {
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(vertical = 16.dp)
            ) {
                NoticeScreenHeader(
                    stringResource(R.string.favourites_upper),
                    moreIcon = false
                )
            }
            LazyColumn(
                modifier = Modifier.weight(1f),
                state = listState,
            ) {
                items(favourites.itemCount) {
                    val favouriteItem = favourites[it]
                    if (favouriteItem != null) {
                        ActionPostNoticeItem(
                            avatar = favouriteItem.user.avatar,
                            nickName = favouriteItem.user.nickName,
                            likeTime = favouriteItem.favoriteTime,
                            thumbnail = favouriteItem.post.images[0].thumbnail,
                            action = "favourite",
                            userId = favouriteItem.user.id,
                            postId = favouriteItem.post.id,
                        )
                    }
                }
                item {
                    BottomNavigationPlaceholder()
                }
            }


        }
    }

}