//
//  FollowCreatorItemView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/19.
//

import SwiftUI
import Kingfisher

struct FollowCreatorItemView: View {
    
    let creator: GetCreatorFollowingAllListItem
    let onClickFollow: (Int) -> Void
    let showCreatorFollowNotifyDialog: (Int) -> Void
    
    var body: some View {
        VStack(spacing: 13.3) {
            HStack(spacing: 0) {
                KFImage(URL(string: creator.profileImageUrl))
                    .cancelOnDisappear(true)
                    .downsampling(
                        size: CGSize(
                            width: 60,
                            height: 60
                        )
                    )
                    .resizable()
                    .frame(width: 60, height: 60)
                    .clipShape(Circle())
                
                Text(creator.nickname)
                    .font(.custom(Font.bold.rawValue, size: 16.7))
                    .foregroundColor(Color.grayee)
                    .padding(.leading, 13.3)
                
                Spacer()
                
                Image(
                    creator.isFollow ?
                    creator.isNotify ?
                    "btn_following_big" :
                        "btn_following_no_alarm_big" :
                        "btn_follow_big"
                )
                .onTapGesture {
                    if creator.isFollow {
                        showCreatorFollowNotifyDialog(creator.creatorId)
                    } else {
                        onClickFollow(creator.creatorId)
                    }
                }
            }
            
            Rectangle()
                .foregroundColor(Color.gray59)
                .frame(height: 0.5)
        }
    }
}
