//
// © 2018-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

import UIKit

class TreeIndentView: UIView {
    enum Shape {
        case none
        case parent
        case lastChild
        case peer
        case noPeers
    }

    var shape = Shape.none
    let lineColor = UIColor.lightGray

    override func draw(_ rect: CGRect) {
        // Drawing code
        if shape == .none {
            return
        }

        let line = UIBezierPath()
        let midX = bounds.size.width / 2.0
        let midY = bounds.size.height / 2.0
        line.move(to: CGPoint(x: midX, y: 0.0))

        switch shape {
        case .none:
            break
        case .parent:
            // draw line from top to bottom
            line.addLine(to: CGPoint(x: midX, y: bounds.size.height))
        case .lastChild:
            line.addLine(to: CGPoint(x: midX, y: midY))
            line.addLine(to: CGPoint(x: bounds.size.width, y: midY))
        case .peer:
            line.addLine(to: CGPoint(x: midX, y: bounds.size.height))
            line.move(to: CGPoint(x: midX, y: midY))
            line.addLine(to: CGPoint(x: bounds.size.width, y: midY))
        case .noPeers:
            line.move(to: CGPoint(x: 0.0, y: midY))
            line.addLine(to: CGPoint(x: bounds.size.width, y: midY))
        }

        line.lineWidth = 4.0
        lineColor.setStroke()
        line.stroke()
    }
}
