// // FootnoteViewController.swift // VDSSample // // Created by Kanamarlapudi, Vasavi on 21/08/24. // import Foundation import UIKit import VDS class FootnoteItemViewController: BaseViewController { internal enum SymbolType: String, DefaultValuing, CaseIterable { case asterisk case doubleAsterisk case character case none public static var defaultValue: Self { .asterisk } /// TextStyle relative to Size. public var text: String { switch self { case .asterisk: return "*" case .doubleAsterisk: return "**" case .character: return "1." case .none: return "" } } } lazy var kindPickerSelectorView = { PickerSelectorView(title: "secondary", picker: self.picker, items: FootnoteItem.Kind.allCases) }() lazy var symbolTypePickerSelectorView = { PickerSelectorView(title: "asterisk", picker: self.picker, items: SymbolType.allCases) }() lazy var sizePickerSelectorView = { PickerSelectorView(title: "micro", picker: self.picker, items: FootnoteItem.Size.allCases) }() var footnoteTextField = TextField() var widthTextField = NumericField() var percentageTextField = NumericField() var tooltipTitleTextField = TextField() var tooltipContentTextField = TextField() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: component) setupPicker() setupModel() } override func setupForm() { super.setupForm() addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Kind", view: kindPickerSelectorView) addFormRow(label: "Size", view: sizePickerSelectorView) addFormRow(label: "Symbol Type", view: symbolTypePickerSelectorView) addFormRow(label: "Text", view: footnoteTextField) addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Percentage (1-100)", view: percentageTextField) addFormRow(label: "ToolTip Title", view: tooltipTitleTextField) addFormRow(label: "ToolTip Content", view: tooltipContentTextField) footnoteTextField .textPublisher .sink { [weak self] text in self?.component.text = text }.store(in: &subscribers) widthTextField .numberPublisher .sink { [weak self] number in if let number { self?.component.width = .value(number.cgFloatValue) self?.percentageTextField.text = "" } else { self?.component.width = nil } }.store(in: &subscribers) percentageTextField .numberPublisher .sink { [weak self] number in if let number, number.intValue > 9 { self?.component.width = .percentage(number.cgFloatValue) self?.widthTextField.text = "" } else { self?.component.width = nil } }.store(in: &subscribers) tooltipTitleTextField .textPublisher .sink { [weak self] text in self?.updateTooltip() }.store(in: &subscribers) tooltipContentTextField .textPublisher .sink { [weak self] text in self?.updateTooltip() }.store(in: &subscribers) } func setupModel() { component.text = "Service is included for free for two years with activation of any iPhone15 model. Connection and response times vary based on location, site conditions, and other factors. See support.apple.com/en-us/HT213885 for more information." component.tooltipModel = nil footnoteTextField.text = component.text sizePickerSelectorView.text = component.size.rawValue kindPickerSelectorView.text = component.kind.rawValue symbolTypePickerSelectorView.text = SymbolType.defaultValue.text tooltipTitleTextField.text = component.tooltipModel?.title tooltipContentTextField.text = component.tooltipModel?.content } func setupPicker() { surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.surface = item self?.contentTopView.backgroundColor = item.color } kindPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.kind = item } sizePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.size = item } symbolTypePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.symbolType = item.text } } func updateTooltip() { let title = tooltipTitleTextField.text ?? "" let content = tooltipContentTextField.text ?? "" component.tooltipModel = !title.isEmpty || !content.isEmpty ? .init(title: title, content: content) : nil } }