import Foundation
import Charts

/// registration section footer view
class RegistraceSectionFooterView: UIView {
    let chart: PieChartView = {
        let view = PieChartView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.drawHoleEnabled = false
        view.drawEntryLabelsEnabled = false
        view.rotationAngle = 0
        view.legend.enabled = true
        return view
    }()
    
    /// initialization function
    /// - Parameter frame: frame
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(chart)
        NSLayoutConstraint.activate([
            chart.topAnchor.constraint(equalTo: topAnchor),
            chart.leadingAnchor.constraint(equalTo: leadingAnchor),
            chart.trailingAnchor.constraint(equalTo: trailingAnchor),
            chart.bottomAnchor.constraint(equalTo: bottomAnchor)
        ])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// function that adds entries into chart for display
    /// - Parameter entries: entries
    func addEntries(entries: [PieChartDataEntry]?) {
        guard let entries = entries else { return }
        let dataSet = PieChartDataSet(entries: entries, label: nil)
        dataSet.colors = chartColors
        dataSet.drawValuesEnabled = false
        chart.data = PieChartData(dataSet: dataSet)
    }
}
