// // AttendanceView.swift // AcaMate // // Created by TAnine on 2/7/25. // import SwiftUI struct AttendanceView: View { @StateObject var btnVM = ButtonViewModel() @State private var attMoreBtnID = UUID() @State var monthlyGroup: (Int,Int) = (5,10)//(0,0) @State var dailyGroup: (Int,Int) = (3,4)//(0,0) var body: some View { VStack(spacing: 0) { HStack(spacing: 0){ Image(.Icon.attendance) .resizable() .frame(width: 24, height: 24, alignment: .center) .padding([.trailing],4) Text("출석") .font(.nps(font: .bold, size: 20)) .foregroundStyle(Color(.Text.detail)) Spacer() SimpleBtnView(vm: btnVM, id: attMoreBtnID) } .padding([.bottom],2) Rectangle() .frame(maxWidth: .infinity, maxHeight: 2) .foregroundStyle(Color(.Second.normal)) .padding([.bottom],12) HStack(spacing: 4) { AttCellView(isDaily: false, valueGroup: $monthlyGroup) Spacer() // Spacer(minLength: 1) AttCellView(isDaily: true, valueGroup: $dailyGroup) } .frame(maxWidth: .infinity) } .padding(24) .onAppear { btnVM.setSize(for: attMoreBtnID, newWidth: 40, newHeight: 24) btnVM.setText(for: attMoreBtnID, newText: "더보기", newFont: .nps(size: 12)) btnVM.setTextColor(for: attMoreBtnID, newColor: .Text.disabled) // MARK: TO-DO // 더보기 동작 로직 추가 } } } struct AttCellView: View { @StateObject var btnVM = ButtonViewModel() @State private var cellBtnID = UUID() let isDaily: Bool @Binding var valueGroup: (Int,Int) @State private var cellText: (name: String, group: String) = ("","") var body: some View { HStack { CircleBtnView(vm: btnVM, id: cellBtnID) VStack(alignment: .leading,spacing: 0) { HStack(alignment: .center, spacing: 2) { Text("\(cellText.name)").font(.nps(font: .bold, size: 12)) .foregroundStyle(Color(.Text.detail)) Text("출석").font(.nps(size: 12)) .foregroundStyle(Color(.Text.detail)) // Spacer() } .padding(.top,4) HStack(alignment: .center, spacing: 2) { Spacer() Text("\(valueGroup.0)").font(.nps(font: .bold, size: 20)) .foregroundStyle(((Double(valueGroup.0)/Double(valueGroup.1)) < 0.7) ? Color(.Other.red) : Color(.Other.blue)) .frame(width: 28,alignment: .center) Text("/").font(.nps(size: 12)) .foregroundStyle(Color(.Text.detail)) Text("\(valueGroup.1)").font(.nps(font: .bold, size: 20)) .foregroundStyle(Color(.Text.detail)) .frame(width: 28,alignment: .center) Text("\(cellText.group)") .font(.nps(size: 16)) .foregroundStyle(Color(.Text.detail)) .lineLimit(1) .minimumScaleFactor(0.5) .truncationMode(.tail) } .frame(maxWidth: .infinity) } } .onAppear { btnVM.setImage(for: cellBtnID, newImage: isDaily ? Image(.Icon.attendanceDaily) : Image(.Icon.attendanceMonthly)) btnVM.setSize(for: cellBtnID, newWidth: 48, newHeight: 48) btnVM.setIsReverse(for: cellBtnID, newValue: true) btnVM.setIsSelected(for: cellBtnID, newValue: true) if isDaily { cellText = ("일일", "시간") } else { cellText = ("월간", "일") } } } } #Preview { AttendanceView() }