import SwiftUI

/// Stylized "R" logo shape from the desktop SVG.
/// Renders at any size as a vector — no bitmap artifacts.
struct RosettaLogoShape: Shape {
    func path(in rect: CGRect) -> Path {
        // Original SVG viewBox: 0 0 384 384
        let w = rect.width
        let h = rect.height
        let sx = w / 384.0
        let sy = h / 384.0

        var path = Path()

        // Bottom-right piece (the "leg" + diagonal)
        path.move(to: CGPoint(x: 254.16 * sx, y: 284.45 * sy))
        path.addLine(to: CGPoint(x: 288.41 * sx, y: 275.19 * sy))
        path.addCurve(
            to: CGPoint(x: 337.41 * sx, y: 240.77 * sy),
            control1: CGPoint(x: 310.0 * sx, y: 265.0 * sy),
            control2: CGPoint(x: 326.0 * sx, y: 254.0 * sy)
        )
        path.addCurve(
            to: CGPoint(x: 369.26 * sx, y: 163.69 * sy),
            control1: CGPoint(x: 358.63 * sx, y: 220.92 * sy),
            control2: CGPoint(x: 369.26 * sx, y: 195.24 * sy)
        )
        path.addLine(to: CGPoint(x: 369.26 * sx, y: 110.0 * sy))
        path.addLine(to: CGPoint(x: 249.55 * sx, y: 110.22 * sy))
        path.addLine(to: CGPoint(x: 249.55 * sx, y: 168.15 * sy))
        path.addCurve(
            to: CGPoint(x: 226.15 * sx, y: 208.22 * sy),
            control1: CGPoint(x: 249.55 * sx, y: 184.85 * sy),
            control2: CGPoint(x: 241.75 * sx, y: 198.20 * sy)
        )
        path.addCurve(
            to: CGPoint(x: 159.01 * sx, y: 223.23 * sy),
            control1: CGPoint(x: 210.55 * sx, y: 218.23 * sy),
            control2: CGPoint(x: 188.18 * sx, y: 223.23 * sy)
        )
        path.addLine(to: CGPoint(x: 134.07 * sx, y: 223.23 * sy))
        path.addLine(to: CGPoint(x: 134.07 * sx, y: 301.0 * sy))
        path.addLine(to: CGPoint(x: 206.65 * sx, y: 381.43 * sy))
        path.addLine(to: CGPoint(x: 344.77 * sx, y: 381.43 * sy))
        path.addLine(to: CGPoint(x: 254.16 * sx, y: 284.45 * sy))
        path.closeSubpath()

        // Top-left piece (the square block)
        path.move(to: CGPoint(x: 248.42 * sx, y: 109.26 * sy))
        path.addLine(to: CGPoint(x: 248.42 * sx, y: 2.61 * sy))
        path.addLine(to: CGPoint(x: 14.77 * sx, y: 2.61 * sy))
        path.addLine(to: CGPoint(x: 14.77 * sx, y: 221.52 * sy))
        path.addLine(to: CGPoint(x: 132.94 * sx, y: 221.52 * sy))
        path.addLine(to: CGPoint(x: 132.94 * sx, y: 109.26 * sy))
        path.addLine(to: CGPoint(x: 248.42 * sx, y: 109.26 * sy))
        path.closeSubpath()

        return path
    }
}
