//
//  LiveRoomTopCreatorView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/14.
//

import SwiftUI

import Kingfisher

struct LiveRoomTopCreatorView: View {
    
    let creatorId: Int
    var nickname: String
    var profileImageUrl: String
    var isFollowing: Bool
    var onClickProfile: () -> Void
    var onClickFollow: (Bool) -> Void
    
    var body: some View {
        HStack(spacing: 5.3) {
            KFImage(URL(string: profileImageUrl))
                .cancelOnDisappear(true)
                .downsampling(
                    size: CGSize(
                        width: 33.3,
                        height: 33.3
                    )
                )
                .resizable()
                .scaledToFill()
                .frame(width: 33.3, height: 33.3)
                .clipShape(Circle())
                .contentShape(Circle())
                .onTapGesture { onClickProfile() }
            
            Image("ic_crown")
            
            Text(nickname)
                .font(.custom(Font.light.rawValue, size: 12))
                .foregroundColor(Color(hex: "eeeeee"))
            
            if creatorId != UserDefaults.int(forKey: .userId) {
                Image(isFollowing ? "btn_following" : "btn_follow")
                    .contentShape(Rectangle())
                    .onTapGesture { onClickFollow(isFollowing) }
                    .padding(.leading, 13.3)
            }
        }
    }
}
