import ComponentLibrary
import SwiftUI

// Ruler with major and minor ticks for the WaveformStrip in WaveformEditorView
public struct WaveformStripRulerView: View {
    let width: CGFloat

    public init(width: CGFloat) {
        self.width = width
    }

    public var body: some View {
        Canvas { context, size in
            // Draws base line
            let basePath = Path(roundedRect: CGRect(x: 0, y: size.height - 0.5, width: width, height: 1), cornerRadius: 0.5)
            context.stroke(
                basePath,
                with: .color(Color.SemanticV1.iconTertiary)
            )

            // Adds major and minor tick marks
            for x in stride(from: 0, to: width, by: 4) {
                let height = Int(x) % 8 == 0 ? 4.0 : 3.0
                let y = size.height - height
                let tickRect = CGRect(x: x, y: y, width: 1, height: height)
                let roundedTickPath = Path(roundedRect: tickRect, cornerRadius: 0.5)
                context.fill(
                    roundedTickPath,
                    with: .color(Color.SemanticV1.iconTertiary)
                )
            }
        }
        .frame(width: width, height: 4)
    }
}
