//
//  LiveRoomInfoSpeakerView.swift
//  SodaLive
//
//  Created by klaus on 2024/01/17.
//

import SwiftUI
import Kingfisher

struct LiveRoomInfoSpeakerView: View {
    
    let nickname: String
    let profileUrl: String
    
    let isMute: Bool
    let isActiveSpeaker: Bool
    
    let onClickProfile: () -> Void
    
    var body: some View {
        VStack(spacing: 5) {
            ZStack(alignment: .center) {
                KFImage(URL(string: profileUrl))
                    .cancelOnDisappear(true)
                    .downsampling(
                        size: CGSize(
                            width: 25,
                            height: 25
                        )
                    )
                    .resizable()
                    .frame(width: 25, height: 25)
                    .clipShape(Circle())
                
                if isMute {
                    Image("ic_mute")
                        .resizable()
                        .frame(width: 25, height: 25)
                }
            }
            .overlay(
                Circle()
                    .stroke(
                        Color.button,
                        lineWidth: isActiveSpeaker ? 3 : 0
                    )
            )
            
            Text(nickname)
                .font(.custom(Font.medium.rawValue, fixedSize: 8.7))
                .foregroundColor(.gray77)
                .lineLimit(1)
                .truncationMode(.tail)
                .frame(width: 28)
        }
        .onTapGesture { onClickProfile() }
    }
}

struct LiveRoomInfoSpeakerView_Previews: PreviewProvider {
    static var previews: some View {
        LiveRoomInfoSpeakerView(
            nickname: "테스트중입니다",
            profileUrl: "https://cf.sodalive.net/profile/13/13-profile-fabb75e0-2870-4d99-900e-1d9aa63e605b-685-1704859996417",
            isMute: false,
            isActiveSpeaker: true,
            onClickProfile: {}
        )
    }
}
