import SwiftUI struct CreatorChannelCommunitySection: View { let communities: [CreatorChannelCommunityPostResponse] let isOwnCreatorChannel: Bool let onSelectTab: (CreatorChannelTab) -> Void let onTapLike: (Int) -> Void let onTapMore: (CreatorChannelCommunityPostItem) -> Void let onTapDetail: (Int) -> Void private let homeVisibleCount = 3 init( communities: [CreatorChannelCommunityPostResponse], isOwnCreatorChannel: Bool, onSelectTab: @escaping (CreatorChannelTab) -> Void, onTapLike: @escaping (Int) -> Void = { _ in }, onTapMore: @escaping (CreatorChannelCommunityPostItem) -> Void = { _ in }, onTapDetail: @escaping (Int) -> Void = { _ in } ) { self.communities = communities self.isOwnCreatorChannel = isOwnCreatorChannel self.onSelectTab = onSelectTab self.onTapLike = onTapLike self.onTapMore = onTapMore self.onTapDetail = onTapDetail } var body: some View { if communities.isEmpty == false { VStack(alignment: .leading, spacing: SodaSpacing.s14) { SectionTitle(title: I18n.CreatorChannelHome.community) VStack(alignment: .leading, spacing: SodaSpacing.s8) { ForEach(visibleCommunities) { community in let post = community.communityPostItem let isOwnPost = post.creatorId == UserDefaults.int(forKey: .userId) CreatorChannelCommunityListItem( post: post, isOwnPost: isOwnPost, isOwnCreatorChannel: isOwnCreatorChannel, onTapLike: { onTapLike(post.postId) }, onTapMore: { onTapMore(post) }, onTapDetail: { onTapDetail(post.postId) } ) } } .padding(.horizontal, SodaSpacing.s14) Button { onSelectTab(.community) } label: { Text(I18n.CreatorChannelHome.viewAll) .appFont(size: 16, weight: .medium) .foregroundColor(.white) .frame(maxWidth: .infinity) .frame(height: 44) .overlay( Capsule() .stroke(Color.white.opacity(0.3), lineWidth: 1) ) } .buttonStyle(.plain) .contentShape(Rectangle()) .padding(.horizontal, SodaSpacing.s14) } .padding(.top, SodaSpacing.s20) } } private var visibleCommunities: [CreatorChannelCommunityPostResponse] { Array(communities.prefix(homeVisibleCount)) } } private extension CreatorChannelCommunityPostResponse { var communityPostItem: CreatorChannelCommunityPostItem { CreatorChannelCommunityPostItem( postId: postId, creatorId: creatorId, creatorNickname: creatorNickname, creatorProfileUrl: creatorProfileUrl, createdAtUtc: dateUtc, content: content, imageUrl: imageUrl, audioUrl: audioUrl, price: price, isCommentAvailable: isCommentAvailable, likeCount: likeCount, commentCount: commentCount, isPinned: isPinned, existOrdered: existOrdered, isLiked: isLiked ) } } struct CreatorChannelCommunitySection_Previews: PreviewProvider { private static let previewImageUrl = "https://picsum.photos/500/500" static var previews: some View { CreatorChannelCommunitySection( communities: (1...3).map { index in CreatorChannelCommunityPostResponse( postId: index, creatorId: 10, creatorNickname: "크리에이터 이름", creatorProfileUrl: previewImageUrl, imageUrl: index == 1 ? nil : previewImageUrl, audioUrl: nil, content: "크리에이터가 커뮤니티에 올린 글이 보이는 부분 크리에이터가 커뮤니티에 올린 글이 보이는 부분", price: index == 2 ? 30 : 0, dateUtc: "2026-07-03T03:44:00Z", existOrdered: false, likeCount: 5, commentCount: 6, isLiked: false, isCommentAvailable: index != 3, isPinned: index == 1 ) }, isOwnCreatorChannel: true, onSelectTab: { _ in }, onTapMore: { _ in }, onTapDetail: { _ in } ) .background(Color.black) .previewLayout(.sizeThatFits) } }