// // UserProfileDonationAllView.swift // SodaLive // // Created by klaus on 2023/08/29. // import SwiftUI import Kingfisher struct UserProfileDonationAllView: View { let userId: Int @StateObject var viewModel = UserProfileDonationAllViewModel() var body: some View { BaseView(isLoading: $viewModel.isLoading) { VStack(spacing: 0) { DetailNavigationBar(title: "후원랭킹 전체보기") if userId == UserDefaults.int(forKey: .userId) { VStack(spacing: 13.3) { HStack(spacing: 0) { Text("오늘") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Spacer() Text("\(viewModel.accumulatedCansToday.comma())") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Text(" 캔") .font(.custom(Font.light.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) } HStack(spacing: 0) { Text("지난주") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Spacer() Text("\(viewModel.accumulatedCansLastWeek.comma())") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Text(" 캔") .font(.custom(Font.light.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) } HStack(spacing: 0) { Text("이번 달 어제까지") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Spacer() Text("\(viewModel.accumulatedCansThisMonth.comma())") .font(.custom(Font.bold.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) Text(" 캔") .font(.custom(Font.light.rawValue, size: 12)) .foregroundColor(Color(hex: "eeeeee")) } } .padding(.vertical, 13.3) .padding(.horizontal, 16.7) .background(Color(hex: "2b2635")) .cornerRadius(8) .padding(.top, 13.3) .padding(.horizontal, 13.3) } HStack(alignment: .center, spacing: 0) { Text("전체") .font(.custom(Font.medium.rawValue, size: 14.7)) .foregroundColor(Color(hex: "eeeeee")) Text("\(viewModel.totalCount)") .font(.custom(Font.medium.rawValue, size: 12)) .foregroundColor(Color(hex: "9970ff")) .padding(.leading, 6.7) Text("개") .font(.custom(Font.medium.rawValue, size: 12)) .foregroundColor(Color(hex: "777777")) Spacer() } .padding(.top, 13.3) .padding(.horizontal, 13.3) Rectangle() .frame(width: screenSize().width - 26.7, height: 1) .foregroundColor(Color(hex: "909090").opacity(0.5)) .padding(.top, 6.7) ScrollView(.vertical, showsIndicators: false) { LazyVStack(spacing: 0) { ForEach(0.. 10 ? "\(String(item.nickname.prefix(10)))..." : item.nickname Text(nickname) .font(.custom(Font.medium.rawValue, size: 13.3)) .foregroundColor(Color(hex: "eeeeee")) Spacer() if let donationCan = item.donationCan, donationCan > 0, withDonationCan { Text("\(donationCan) 캔") .font(.custom(Font.medium.rawValue, size: 13.3)) .foregroundColor(Color(hex: "eeeeee")) } } .padding(.horizontal, isTop3Index(index: index) ? 20 : 0) .padding(.top, getTopPadding(index: index)) .padding(.bottom, getBottomPadding(index: index)) .background(Color(hex: "2b2635").opacity(isTop3Index(index: index) ? 1 : 0)) .cornerRadius(4.7, corners: cornerRadiusConers(index: index)) .padding(.horizontal, isTop3Index(index: index) ? 0 : 6.7) } private func isTop3Index(index: Int) -> Bool { return index == 0 || index == 1 || index == 2 } private func getTopPadding(index: Int) -> CGFloat { if index == 0 || index == 3 { return 20 } else { return 6.7 } } private func getBottomPadding(index: Int) -> CGFloat { if (index == 0 && itemCount == 1) || (index == 1 && itemCount == 2) || index == 2 { return 20 } else { return 6.7 } } private func cornerRadiusConers(index: Int) -> UIRectCorner { if (index == 0 && itemCount == 1) { return [.topLeft, .topRight, .bottomLeft, .bottomRight] } else if index == 0 { return [.topLeft, .topRight] } else if (index == 1 && itemCount == 2) || index == 2 { return [.bottomLeft, .bottomRight] } else { return [] } } }