import SwiftUI struct CommunityPostCard: View { let creatorNickname: String let creatorProfileImageUrl: String? let content: String let imageUrl: String? let price: Int? let existOrdered: Bool let createdAt: String? let likeCount: Int? let commentCount: Int? var body: some View { VStack(alignment: .leading, spacing: SodaSpacing.s12) { header Text(content) .appFont(.body4) .foregroundColor(.white) .lineLimit(3) .truncationMode(.tail) if hasImage { imageContent } footer } .padding(SodaSpacing.s12) .background(Color.gray900) .clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous)) } private var header: some View { HStack(spacing: SodaSpacing.s8) { DownsampledKFImage(url: URL(string: creatorProfileImageUrl ?? ""), size: CGSize(width: 32, height: 32)) .background(Color.gray800) .clipShape(Circle()) Text(creatorNickname) .appFont(.body5) .foregroundColor(.white) .lineLimit(1) Spacer(minLength: 0) } } private var imageContent: some View { ZStack { DownsampledKFImage(url: URL(string: imageUrl ?? ""), size: CGSize(width: 240, height: 150)) .background(Color.gray800) .frame(maxWidth: .infinity) .clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s12, style: .continuous)) .blur(radius: isLocked ? 8 : 0) if isLocked { VStack(spacing: SodaSpacing.s6) { Image("ic_new_community_lock") .resizable() .renderingMode(.template) .foregroundColor(.white) .frame(width: 24, height: 24) if let price { Text("\(price) can") .appFont(.caption2) .foregroundColor(Color.button) .padding(.horizontal, SodaSpacing.s12) .padding(.vertical, SodaSpacing.s6) .overlay( Capsule() .stroke(Color.button, lineWidth: 1) ) } } } } } private var footer: some View { HStack(spacing: SodaSpacing.s12) { if let createdAt, !createdAt.isEmpty { Text(createdAt) .appFont(.caption2) .foregroundColor(Color.gray500) } if let likeCount { Text("Like \(likeCount)") .appFont(.caption2) .foregroundColor(Color.gray500) } if let commentCount { Text("Comment \(commentCount)") .appFont(.caption2) .foregroundColor(Color.gray500) } } } private var hasImage: Bool { !(imageUrl ?? "").isEmpty } private var isLocked: Bool { (price ?? 0) > 0 && !existOrdered } } struct CommunityPostCard_Previews: PreviewProvider { static var previews: some View { CommunityPostCard( creatorNickname: "크리에이터", creatorProfileImageUrl: nil, content: "커뮤니티 본문입니다.", imageUrl: nil, price: nil, existOrdered: false, createdAt: "방금 전", likeCount: 10, commentCount: 2 ) .padding(SodaSpacing.s20) .background(Color.black) .previewLayout(.sizeThatFits) } }