import SwiftUI // MARK: - Phone Input Component struct PhoneInputView: View { @Binding var phoneNumber: String @Binding var message: String let inputType: PhoneInputType @FocusState var focusedField: PhoneField? // Phone input type enum enum PhoneInputType: String, CaseIterable { case phone = "Phone" case sms = "SMS" var displayName: String { switch self { case .phone: return "phone".localized case .sms: return "sms".localized } } var icon: String { switch self { case .phone: return "phone" case .sms: return "message" } } var placeholder: String { switch self { case .phone: return "phone_placeholder".localized case .sms: return "sms_placeholder".localized } } var hint: String { switch self { case .phone: return "enter_phone_number".localized case .sms: return "enter_sms_content".localized } } } // Phone field enum enum PhoneField: Hashable { case phoneNumber, message } var body: some View { VStack(spacing: 16) { // Type information HStack { Image(systemName: inputType.icon) .font(.title2) .foregroundColor(.blue) VStack(alignment: .leading, spacing: 2) { Text(inputType.displayName) .font(.headline) .foregroundColor(.primary) Text(inputType.hint) .font(.caption) .foregroundColor(.secondary) } Spacer() } .padding(.horizontal, 12) .padding(.vertical, 8) .background( RoundedRectangle(cornerRadius: 8) .fill(Color.blue.opacity(0.1)) ) // Phone number (required) VStack(alignment: .leading, spacing: 8) { HStack { Text("phone_number".localized) .font(.subheadline) .foregroundColor(.primary) Text("*") .foregroundColor(.red) Spacer() } TextField("phone_placeholder".localized, text: $phoneNumber) .textFieldStyle(RoundedBorderTextFieldStyle()) .keyboardType(.phonePad) .focused($focusedField, equals: .phoneNumber) } // SMS content (SMS type only) if inputType == .sms { VStack(alignment: .leading, spacing: 8) { HStack { Text("sms_content".localized) .font(.subheadline) .foregroundColor(.primary) Spacer() } TextField("sms_placeholder".localized, text: $message) .textFieldStyle(RoundedBorderTextFieldStyle()) .focused($focusedField, equals: .message) } } // Format instructions VStack(alignment: .leading, spacing: 8) { HStack { Image(systemName: "info.circle") .font(.caption) .foregroundColor(.blue) Text("format_instructions".localized) .font(.caption) .foregroundColor(.primary) Spacer() } Text(getFormatHint()) .font(.caption) .foregroundColor(.secondary) .lineLimit(nil) } .padding(.horizontal, 12) .padding(.vertical, 8) .background( RoundedRectangle(cornerRadius: 8) .fill(Color.blue.opacity(0.1)) ) } .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() Button("done".localized) { focusedField = nil } .foregroundColor(.blue) .font(.system(size: 16, weight: .medium)) } } } private func getFormatHint() -> String { switch inputType { case .phone: return "phone_format_hint".localized case .sms: return "sms_format_hint".localized } } } #Preview { PhoneInputView( phoneNumber: .constant(""), message: .constant(""), inputType: .phone ) }