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

import SwiftUI



struct CircleBtnView: View {
    @ObservedObject var vm: ButtonViewModel
    let id: UUID
    
    var body: some View {
        if let state = vm.btnStates[id] {
            ZStack {
                if state.isReverse {
                    Circle()
                        .foregroundStyle(state.backColor)
                        .frame(width: state.width, height: state.height)
                        .innerShadow(shape: Circle(), color: Color(.Text.black).opacity(0.75), blur: 8, x: 0, y: 4)
                } else {
                    Circle()
                        .foregroundStyle(state.backColor)
                        .frame(width: state.width, height: state.height)
                        .shadow(color: Color(.Text.black).opacity(0.75), radius: 8, x: 4, y: 8)
                }
                VStack(alignment: .center, spacing: 0) {
                    if let image = state.image {
                        image
                            .resizable()
                            .renderingMode(.template)
                            .foregroundStyle(state.foreColor)
                            .frame(width: state.width/2, height: state.height/2)
                    }
                    if let title = state.text, let font = state.font {
                        Text("\(title)")
                            .font(font)
                            .lineLimit(1)
                            .minimumScaleFactor(0.5)
                            .truncationMode(.tail)
                            .foregroundStyle(state.foreColor)
                    }
                }
            }
            .frame(width: state.width, height: state.height)
            .onTapGesture {
                guard let action = state.action else {return}
                action()
            }
        }
    }
}
