import UIKit

// swiftlint: disable force_unwrapping
class StepperTableViewCell: UITableViewCell {
    @IBOutlet var labelView: UILabel!
    @IBOutlet var stepperView: UIStepper!

    var valueChangedListener: ((UIStepper) -> Void)?
    var updateLabel: ((Double) -> String?)?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    @IBAction func valueChanged(_ sender: UIStepper) {
        valueChangedListener?(sender)
        setValue(stepperView.value)
    }

    func setValue(_ value: Double) {
        stepperView.value = value
        if updateLabel != nil {
            labelView.text = updateLabel!(value)
        }
    }
}
