// // WhatProblemStepViewModel.swift // Lockdown // // Created by Pavel Vilbik on 23.06.23. // Copyright © 2023 Confirmed Inc. All rights reserved. // import UIKit class WhatProblemStepViewModel: BaseStepViewModel, StepViewModelProtocol { private let problemList = [ NSLocalizedString("Internet connection is blocked", comment: ""), NSLocalizedString("VPN not connecting", comment: ""), NSLocalizedString("Blocking not working", comment: ""), NSLocalizedString("Battery Drain", comment: ""), NSLocalizedString("Other", comment: "") ] private var selectedProblemIndex = -1 private var otherInput: String? { didSet { didChangeReady?(isFilled) } } private var selectedProblem: String? { if (0..= 0 else { return nil } var result = "" result.append(problemList[selectedProblemIndex]) if isSelectedOther(), let otherInput { result.append("\n") result.append(otherInput) } result.append("\n") return result } var isFilled: Bool { guard selectedProblemIndex >= 0 else { return false } if isSelectedOther() { return !(otherInput?.isEmpty ?? true) } return true } var didChangeReady: ((Bool) -> Void)? init(didChangeReady: ((Bool) -> Void)?) { self.didChangeReady = didChangeReady } override func updateRows() { staticTableView?.clear() addTitleRow( NSLocalizedString("What problem are you experiencing?", comment: ""), subtitle: NSLocalizedString("Select your problem", comment: "") ) for index in 0.. Bool { selectedProblemIndex == problemList.count - 1 } private func updateForSelect(problemIndex: Int, isSelected: Bool) { if isSelected { selectedProblemIndex = problemIndex } else { selectedProblemIndex = -1 } if !isSelectedOther() { otherInput = nil } updateRows() didChangeReady?(isFilled) } }