import SwiftUI

struct CommentDetailView: View {
    var comment: Comment
    var postId: Int

    var children: [Comment] {
        comment.children.sorted(by: { $0.date < $1.date })
    }
    
    var body: some View {
        ScrollViewWithBanner(banner: nil, onRefresh: nil) { _ in
            VStack(spacing: 0) {
                CommentView(comment: comment, seperatorStyle: .none, showReplyCount: false)
                ConversationButton(postId: postId, parentCommentId: comment.id, hasComments: true)
                    .padding(.bottom, 26)
                
                ForEach(children, id: \.self) { childComment in
                    NavigationLink {
                        CommentDetailView(comment: childComment, postId: postId)
                    } label: {
                        CommentView(comment: childComment, seperatorStyle: childComment == children.first ? .standard : .indented)
                    }
                    .buttonStyle(FlatButtonStyle())
                }
            }
            .padding()
        }
    }
}
