import SwiftUI
import Bedrock

struct ContactPhotoRow: View {
    @Binding var photoData: Data?
    let onTap: () -> Void

    var body: some View {
        Button(action: onTap) {
            HStack(spacing: Design.Spacing.medium) {
                Group {
                    if let photoData, let uiImage = UIImage(data: photoData) {
                        Image(uiImage: uiImage)
                            .resizable()
                            .scaledToFill()
                    } else {
                        Image(systemName: "person.crop.circle.fill")
                            .typography(.title2)
                            .foregroundStyle(Color.Text.tertiary)
                    }
                }
                .frame(width: Design.CardSize.avatarLarge, height: Design.CardSize.avatarLarge)
                .clipShape(.circle)
                .overlay(Circle().stroke(Color.Text.tertiary.opacity(Design.Opacity.light), lineWidth: Design.LineWidth.thin))

                VStack(alignment: .leading, spacing: Design.Spacing.xSmall) {
                    Text("Profile Photo")
                        .typography(.subheading)
                        .foregroundStyle(Color.Text.primary)

                    Text(photoData == nil ? String.localized("Add a photo") : String.localized("Tap to change"))
                        .typography(.caption)
                        .foregroundStyle(Color.Text.secondary)
                }

                Spacer()

                Image(systemName: "chevron.right")
                    .typography(.caption)
                    .foregroundStyle(Color.Text.tertiary)
            }
            .padding(.vertical, Design.Spacing.xSmall)
            .contentShape(.rect)
        }
        .buttonStyle(.plain)
    }
}
