//
//  LoadResistanceIconView.swift
//  USB Meter
//

import SwiftUI

struct LoadResistanceIconView: View {
    let color: Color

    var body: some View {
        GeometryReader { proxy in
            let width = proxy.size.width
            let height = proxy.size.height
            let midY = height / 2
            let startX = width * 0.10
            let endX = width * 0.90
            let boxMinX = width * 0.28
            let boxMaxX = width * 0.72
            let boxHeight = height * 0.34
            let boxRect = CGRect(
                x: boxMinX,
                y: midY - (boxHeight / 2),
                width: boxMaxX - boxMinX,
                height: boxHeight
            )
            let strokeWidth = max(1.2, height * 0.055)

            ZStack {
                Path { path in
                    path.move(to: CGPoint(x: startX, y: midY))
                    path.addLine(to: CGPoint(x: boxRect.minX, y: midY))
                    path.move(to: CGPoint(x: boxRect.maxX, y: midY))
                    path.addLine(to: CGPoint(x: endX, y: midY))
                }
                .stroke(
                    color,
                    style: StrokeStyle(
                        lineWidth: strokeWidth,
                        lineCap: .round,
                        lineJoin: .round
                    )
                )

                Path { path in
                    path.addRect(boxRect)
                }
                .stroke(
                    color,
                    style: StrokeStyle(
                        lineWidth: strokeWidth,
                        lineCap: .round,
                        lineJoin: .round
                    )
                )
            }
        }
        .padding(4)
    }
}