import ComponentLibrary
import Localization
import SwiftUI

struct WaveformStripLoadingView: View {
    @State private var dotCount = 0
    @State private var timer: Timer?
    let waveformData: [Float]
    let width: CGFloat
    let height: CGFloat

    var body: some View {
        VStack {
            HStack(spacing: 0) {
                Text(L10n.FeatureEditClip.waveformLoadingMessage)
                    .typographyV1(.caption)
                Text(String(repeating: ".", count: (dotCount % 3) + 1))
                    .typographyV1(.caption)
                    .frame(width: 24, alignment: .leading)
            }
            .foregroundColor(.SemanticV1.textSecondary)
            .onAppear {
                if waveformData.isEmpty {
                    timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in
                        if waveformData.isEmpty {
                            dotCount += 1
                        } else {
                            timer?.invalidate()
                            timer = nil
                        }
                    }
                }
            }
            .onDisappear {
                timer?.invalidate()
                timer = nil
            }
        }
        .frame(width: width, height: height)
        .clipped()
    }
}
