//
//  TopView.swift
//  AcaMate
//
//  Created by TAnine on 2/4/25.
//

import SwiftUI

struct TopView: View {
    @StateObject var btnVM = ButtonViewModel()
    
    @State var titleName: String = ""
    
    @State private var leftBtnID = UUID()
    @State private var rightBtnID = UUID()
    
    //MARK: - 변경 값
    var myType: UserType = .Student
    
    var body: some View {
        HStack(alignment: .center, spacing: 0) {
            SimpleBtnView(vm: btnVM, id: leftBtnID)
                .background {
                    if let state = btnVM.btnStates[leftBtnID], state.image == nil {
                        Circle()
                            .strokeBorder(Color(.Second.normal) ,lineWidth: 4)
                            .frame(width: 40, height: 40)
                    }
                }
                .padding(EdgeInsets(top: 12, leading: 24, bottom: 12, trailing: 12))
    
            
            Text("\(titleName)")
                .foregroundStyle(Color(.Text.detail))
                .font(.nps(font: .bold, size: 20))
            Spacer()
            
            SimpleBtnView(vm: btnVM, id: rightBtnID)
                .padding(EdgeInsets(top: 12, leading: 12, bottom: 12, trailing: 24))
            
        }
        .background {
            Rectangle()
                .foregroundStyle(Color(.Other.cell))
                .ignoresSafeArea(edges: .top)
        }
        .frame(maxWidth: .infinity)
        .onAppear {
            btnVM.btnStates[leftBtnID] = ButtonState()
            btnVM.btnStates[rightBtnID] = ButtonState()
            
            btnVM.setSize(for: leftBtnID, newWidth: 40, newHeight: 40)
            btnVM.setSize(for: rightBtnID, newWidth: 40, newHeight: 40)
            
            if self.myType == .Student {
                btnVM.setImage(for: leftBtnID, newImage: Image(.Icon.face))
            } else {
                btnVM.setText(for: leftBtnID,
                              newText: "\(myType.rawValue)",
                              newFont: .nps(font: .bold, size: 24))
            }
            btnVM.setImage(for: rightBtnID, newImage: Image(.Icon.notificationSET))
        }
        
    }
}

//struct TypeIcon: View {
//    var myType: UserType
//    
//    var body: some View {
        
//        if self.myType == .Student {
            
//            SimpleBtnView(image: Image(.Icon.face), title: nil, font: nil, width: 40, height: 40)
//        } else {
//            SimpleBtnView(image: nil, title: "\(self.myType.rawValue)", font: .nps(font: .bold, size: 24), width: 40, height: 40)
//            .doAction {
//                printLog("CHECK!!!")
//            }
//            .setTextColor(.red)
//            .setIsUsable(false)
            
            
            
//        }
            
//    }
//}

//#Preview {
//    TopView(titleName: "Name")
//}
