import ComponentLibrary
import Localization
import SwiftUI

public struct ChatAudioTermsOfServiceView: View {
    let onAccept: () -> Void
    let onDismiss: () -> Void

    public init(onAccept: @escaping () -> Void, onDismiss: @escaping () -> Void) {
        self.onAccept = onAccept
        self.onDismiss = onDismiss
    }

    public var body: some View {
        VStack(spacing: 0) {
            VStack(alignment: .leading, spacing: 16) {
                Text(L10n.FeatureCreateClip.termsOfService)
                    .typographyV1(
                        TypographyV1.headline5
                            .lineHeight(24)
                            .kerning(0.36)
                    )
                    .foregroundColor(ChatConstants.Colors.Foreground.primary)
                    .padding(.horizontal, 24)
                    .padding(.top, 24)

                ScrollView {
                    Text(L10n.FeatureCreateClip.disclaimerMessage)
                        .typographyV1(
                            TypographyV1.bodySmall
                                .lineHeight(16)
                                .kerning(0.24)
                        )
                        .foregroundColor(ChatConstants.Colors.Foreground.secondary)
                        .padding(.horizontal, 24)
                        .padding(.bottom, 16)
                }
            }

            VStack(spacing: 9) {
                Button {
                    onAccept()
                } label: {
                    Text(L10n.FeatureCreateClip.accept)
                        .font(TypographyV1.headline5.font)
                        .foregroundColor(ChatConstants.Colors.Background.primary)
                        .frame(maxWidth: .infinity)
                        .frame(height: 56)
                        .background(ChatConstants.Colors.Foreground.primary)
                        .cornerRadius(100)
                }
                .padding(.horizontal, 24)
            }
            .padding(.vertical, 12)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
        .background(
            ChatConstants.Colors.Background.secondary
                .ignoresSafeArea(edges: .bottom)
        )
        .presentationDetents([.fraction(0.5)])
        .presentationDragIndicator(.visible)
        .presentationBackground {
            ChatConstants.Colors.Background.secondary
                .ignoresSafeArea(edges: .bottom)
        }
        .onDisappear {
            onDismiss()
        }
    }
}
