All files / app/(auth) wifi-setup.tsx

0% Statements 0/119
0% Branches 0/76
0% Functions 0/24
0% Lines 0/116

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
/**
 * WiFi Setup Screen
 *
 * Allows user to configure WiFi on WellNuo ESP32 sensors via Bluetooth.
 * Uses @orbital-systems/react-native-esp-idf-provisioning for BLE communication.
 */
 
import React, { useState, useEffect, useCallback } from 'react';
import {
  View,
  Text,
  StyleSheet,
  TouchableOpacity,
  TextInput,
  ScrollView,
  ActivityIndicator,
  Alert,
  FlatList,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { router, useLocalSearchParams } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { AppColors, Spacing, BorderRadius, FontSizes, FontWeights } from '@/constants/theme';
import {
  espProvisioning,
  type WellNuoDevice,
  type WifiNetwork,
} from '@/services/espProvisioning';
import {
  validateWiFiCredentials,
  getValidationErrorMessage,
  sanitizeWiFiCredentials,
} from '@/utils/wifiValidation';
 
type Step = 'scan' | 'connect' | 'wifi-select' | 'wifi-password' | 'provisioning' | 'complete';
 
export default function WifiSetupScreen() {
  const params = useLocalSearchParams<{ lovedOneName?: string; beneficiaryId?: string }>();
  const lovedOneName = params.lovedOneName || '';
 
  // State
  const [step, setStep] = useState<Step>('scan');
  const [isLoading, setIsLoading] = useState(false);
  const [error, setError] = useState<string | null>(null);
 
  // Devices
  const [devices, setDevices] = useState<WellNuoDevice[]>([]);
  const [selectedDevice, setSelectedDevice] = useState<WellNuoDevice | null>(null);
 
  // WiFi
  const [wifiNetworks, setWifiNetworks] = useState<WifiNetwork[]>([]);
  const [selectedWifi, setSelectedWifi] = useState<WifiNetwork | null>(null);
  const [wifiPassword, setWifiPassword] = useState('');
  const [showPassword, setShowPassword] = useState(false);
 
  // Cleanup on unmount
  useEffect(() => {
    return () => {
      espProvisioning.disconnect();
    };
  }, []);
 
  // Step 1: Scan for BLE devices
  const handleScanDevices = useCallback(async () => {
    setIsLoading(true);
    setError(null);
    setDevices([]);
 
    try {
      const foundDevices = await espProvisioning.scanForDevices(10000);
 
      if (foundDevices.length === 0) {
        setError('No WellNuo sensors found. Make sure your sensor is powered on and in setup mode.');
      } else {
        setDevices(foundDevices);
      }
    } catch (err: unknown) {
      const errorMessage = err instanceof Error ? err.message : 'Unknown error';
      setError(`Failed to scan: ${errorMessage}`);
    } finally {
      setIsLoading(false);
    }
  }, []);
 
  // Auto-scan on mount
  useEffect(() => {
    handleScanDevices();
  }, [handleScanDevices]);
 
  // Step 2: Connect to selected device
  const handleSelectDevice = async (device: WellNuoDevice) => {
    setSelectedDevice(device);
    setStep('connect');
    setIsLoading(true);
    setError(null);
 
    try {
      await espProvisioning.connect(device.device);
      setStep('wifi-select');
      // Auto-scan WiFi networks after connecting
      handleScanWifi();
    } catch (err: unknown) {
      const errorMessage = err instanceof Error ? err.message : 'Unknown error';
      setError(`Failed to connect: ${errorMessage}`);
      setStep('scan');
    } finally {
      setIsLoading(false);
    }
  };
 
  // Step 3: Scan for WiFi networks
  const handleScanWifi = async () => {
    setIsLoading(true);
    setError(null);
    setWifiNetworks([]);
 
    try {
      const networks = await espProvisioning.scanWifiNetworks();
      // Sort by signal strength
      const sorted = networks.sort((a, b) => b.rssi - a.rssi);
      setWifiNetworks(sorted);
 
      if (sorted.length === 0) {
        setError('No WiFi networks found. Make sure you are in range of your WiFi network.');
      }
    } catch (err: unknown) {
      const errorMessage = err instanceof Error ? err.message : 'Unknown error';
      setError(`Failed to scan WiFi: ${errorMessage}`);
    } finally {
      setIsLoading(false);
    }
  };
 
  // Step 4: Select WiFi network
  const handleSelectWifi = (network: WifiNetwork) => {
    setSelectedWifi(network);
    setWifiPassword('');
    setStep('wifi-password');
  };
 
  // Step 5: Provision with password
  const handleProvision = async () => {
    if (!selectedWifi) return;
 
    // Validate credentials before provisioning
    const validation = validateWiFiCredentials(
      selectedWifi.ssid,
      wifiPassword,
      selectedWifi.auth
    );
 
    if (!validation.valid) {
      const errorMsg = getValidationErrorMessage(validation);
      setError(errorMsg);
      return;
    }
 
    // Show warning if present (but allow to continue)
    if (validation.warnings.length > 0) {
      const warningMsg = validation.warnings.join('\n');
      Alert.alert(
        'Warning',
        `${warningMsg}\n\nDo you want to continue?`,
        [
          { text: 'Cancel', style: 'cancel' },
          {
            text: 'Continue',
            onPress: () => provisionDevice(),
          },
        ]
      );
      return;
    }
 
    // No warnings, proceed directly
    await provisionDevice();
  };
 
  // Actual provisioning logic
  const provisionDevice = async () => {
    if (!selectedWifi) return;
 
    setStep('provisioning');
    setIsLoading(true);
    setError(null);
 
    try {
      // Sanitize credentials before sending
      const sanitized = sanitizeWiFiCredentials({
        ssid: selectedWifi.ssid,
        password: wifiPassword,
      });
 
      await espProvisioning.provisionWifi(sanitized.ssid, sanitized.password);
      setStep('complete');
    } catch (err: unknown) {
      const errorMessage = err instanceof Error ? err.message : 'Unknown error';
      setError(`Failed to configure WiFi: ${errorMessage}`);
      setStep('wifi-password');
    } finally {
      setIsLoading(false);
    }
  };
 
  // Complete and navigate
  const handleComplete = async () => {
    await espProvisioning.disconnect();
    // Navigate to activate screen or back
    if (params.beneficiaryId) {
      router.replace({
        pathname: '/(auth)/activate',
        params: { beneficiaryId: params.beneficiaryId, lovedOneName },
      });
    } else {
      router.back();
    }
  };
 
  // Render signal strength icon
  const renderSignalIcon = (rssi: number) => {
    let iconName: 'wifi' | 'wifi-outline' = 'wifi';
    let color = AppColors.success;
 
    if (rssi < -70) {
      color = AppColors.warning;
    }
    if (rssi < -80) {
      color = AppColors.error;
    }
 
    return <Ionicons name={iconName} size={20} color={color} />;
  };
 
  // Step 1: Scan for devices
  if (step === 'scan' || step === 'connect') {
    return (
      <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
        <View style={styles.content}>
          {/* Header */}
          <View style={styles.header}>
            <TouchableOpacity style={styles.backButton} onPress={() => router.back()}>
              <Ionicons name="arrow-back" size={24} color={AppColors.textPrimary} />
            </TouchableOpacity>
            <Text style={styles.title}>WiFi Setup</Text>
            <View style={styles.placeholder} />
          </View>
 
          {/* Icon */}
          <View style={styles.iconContainer}>
            <Ionicons name="bluetooth" size={64} color={AppColors.primary} />
          </View>
 
          {/* Instructions */}
          <Text style={styles.instructions}>
            {step === 'connect'
              ? `Connecting to ${selectedDevice?.name}...`
              : 'Searching for WellNuo sensors nearby...'}
          </Text>
 
          {/* Loading or device list */}
          {isLoading ? (
            <View style={styles.loadingContainer}>
              <ActivityIndicator size="large" color={AppColors.primary} />
              <Text style={styles.loadingText}>
                {step === 'connect' ? 'Connecting...' : 'Scanning for devices...'}
              </Text>
            </View>
          ) : error ? (
            <View style={styles.errorContainer}>
              <Ionicons name="alert-circle" size={48} color={AppColors.error} />
              <Text style={styles.errorText}>{error}</Text>
              <TouchableOpacity style={styles.retryButton} onPress={handleScanDevices}>
                <Text style={styles.retryButtonText}>Retry Scan</Text>
              </TouchableOpacity>
            </View>
          ) : (
            <FlatList
              data={devices}
              keyExtractor={(item) => item.name}
              style={styles.deviceList}
              renderItem={({ item }) => (
                <TouchableOpacity
                  style={styles.deviceItem}
                  onPress={() => handleSelectDevice(item)}
                >
                  <View style={styles.deviceIcon}>
                    <Ionicons name="hardware-chip" size={24} color={AppColors.primary} />
                  </View>
                  <View style={styles.deviceInfo}>
                    <Text style={styles.deviceName}>{item.name}</Text>
                    {item.wellId && (
                      <Text style={styles.deviceMeta}>Sensor ID: {item.wellId}</Text>
                    )}
                  </View>
                  <Ionicons name="chevron-forward" size={20} color={AppColors.textMuted} />
                </TouchableOpacity>
              )}
              ListEmptyComponent={
                <Text style={styles.emptyText}>No devices found</Text>
              }
            />
          )}
 
          {/* Rescan button */}
          {!isLoading && devices.length > 0 && (
            <TouchableOpacity style={styles.secondaryButton} onPress={handleScanDevices}>
              <Ionicons name="refresh" size={20} color={AppColors.primary} />
              <Text style={styles.secondaryButtonText}>Scan Again</Text>
            </TouchableOpacity>
          )}
        </View>
      </SafeAreaView>
    );
  }
 
  // Step 3: Select WiFi network
  if (step === 'wifi-select') {
    return (
      <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
        <View style={styles.content}>
          {/* Header */}
          <View style={styles.header}>
            <TouchableOpacity
              style={styles.backButton}
              onPress={async () => {
                await espProvisioning.disconnect();
                setStep('scan');
              }}
            >
              <Ionicons name="arrow-back" size={24} color={AppColors.textPrimary} />
            </TouchableOpacity>
            <Text style={styles.title}>Select WiFi</Text>
            <View style={styles.placeholder} />
          </View>
 
          {/* Connected device info */}
          <View style={styles.connectedDevice}>
            <Ionicons name="checkmark-circle" size={20} color={AppColors.success} />
            <Text style={styles.connectedText}>Connected to {selectedDevice?.name}</Text>
          </View>
 
          {/* Instructions */}
          <Text style={styles.instructions}>
            Select the WiFi network for your sensor
          </Text>
 
          {/* Loading or WiFi list */}
          {isLoading ? (
            <View style={styles.loadingContainer}>
              <ActivityIndicator size="large" color={AppColors.primary} />
              <Text style={styles.loadingText}>Scanning WiFi networks...</Text>
            </View>
          ) : error ? (
            <View style={styles.errorContainer}>
              <Ionicons name="alert-circle" size={48} color={AppColors.error} />
              <Text style={styles.errorText}>{error}</Text>
              <TouchableOpacity style={styles.retryButton} onPress={handleScanWifi}>
                <Text style={styles.retryButtonText}>Retry Scan</Text>
              </TouchableOpacity>
            </View>
          ) : (
            <FlatList
              data={wifiNetworks}
              keyExtractor={(item, index) => `${item.ssid}-${index}`}
              style={styles.deviceList}
              renderItem={({ item }) => (
                <TouchableOpacity
                  style={styles.deviceItem}
                  onPress={() => handleSelectWifi(item)}
                >
                  {renderSignalIcon(item.rssi)}
                  <View style={styles.deviceInfo}>
                    <Text style={styles.deviceName}>{item.ssid}</Text>
                    <Text style={styles.deviceMeta}>{item.auth}</Text>
                  </View>
                  <Ionicons name="chevron-forward" size={20} color={AppColors.textMuted} />
                </TouchableOpacity>
              )}
              ListEmptyComponent={
                <Text style={styles.emptyText}>No WiFi networks found</Text>
              }
            />
          )}
 
          {/* Rescan button */}
          {!isLoading && (
            <TouchableOpacity style={styles.secondaryButton} onPress={handleScanWifi}>
              <Ionicons name="refresh" size={20} color={AppColors.primary} />
              <Text style={styles.secondaryButtonText}>Scan Again</Text>
            </TouchableOpacity>
          )}
        </View>
      </SafeAreaView>
    );
  }
 
  // Step 4: Enter WiFi password
  if (step === 'wifi-password' || step === 'provisioning') {
    return (
      <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
        <ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
          {/* Header */}
          <View style={styles.header}>
            <TouchableOpacity
              style={styles.backButton}
              onPress={() => setStep('wifi-select')}
              disabled={step === 'provisioning'}
            >
              <Ionicons
                name="arrow-back"
                size={24}
                color={step === 'provisioning' ? AppColors.textMuted : AppColors.textPrimary}
              />
            </TouchableOpacity>
            <Text style={styles.title}>Enter Password</Text>
            <View style={styles.placeholder} />
          </View>
 
          {/* WiFi icon */}
          <View style={styles.iconContainer}>
            <Ionicons name="wifi" size={64} color={AppColors.primary} />
          </View>
 
          {/* Selected network */}
          <View style={styles.selectedNetwork}>
            <Text style={styles.selectedNetworkLabel}>Network:</Text>
            <Text style={styles.selectedNetworkName}>{selectedWifi?.ssid}</Text>
          </View>
 
          {/* Password input */}
          <View style={styles.inputContainer}>
            <TextInput
              style={styles.input}
              value={wifiPassword}
              onChangeText={setWifiPassword}
              placeholder="Enter WiFi password"
              placeholderTextColor={AppColors.textMuted}
              secureTextEntry={!showPassword}
              autoCorrect={false}
              editable={step !== 'provisioning'}
            />
            <TouchableOpacity
              style={styles.showPasswordButton}
              onPress={() => setShowPassword(!showPassword)}
            >
              <Ionicons
                name={showPassword ? 'eye-off' : 'eye'}
                size={24}
                color={AppColors.textMuted}
              />
            </TouchableOpacity>
          </View>
 
          {/* Error */}
          {error && (
            <View style={styles.inlineError}>
              <Ionicons name="alert-circle" size={16} color={AppColors.error} />
              <Text style={styles.inlineErrorText}>{error}</Text>
            </View>
          )}
 
          {/* Connect button */}
          <TouchableOpacity
            style={[
              styles.primaryButton,
              (step === 'provisioning' || (selectedWifi?.auth !== 'Open' && !wifiPassword)) &&
                styles.buttonDisabled,
            ]}
            onPress={handleProvision}
            disabled={step === 'provisioning' || (selectedWifi?.auth !== 'Open' && !wifiPassword)}
          >
            {step === 'provisioning' ? (
              <>
                <ActivityIndicator color={AppColors.white} style={{ marginRight: 8 }} />
                <Text style={styles.primaryButtonText}>Configuring...</Text>
              </>
            ) : (
              <Text style={styles.primaryButtonText}>Connect to WiFi</Text>
            )}
          </TouchableOpacity>
 
          {/* Note for open networks */}
          {selectedWifi?.auth === 'Open' && (
            <Text style={styles.noteText}>
              This is an open network. You can leave the password empty.
            </Text>
          )}
 
          {/* Password requirements */}
          {selectedWifi?.auth?.includes('WPA') && (
            <Text style={styles.noteText}>
              Password must be 8-63 characters for WPA/WPA2/WPA3 networks.
            </Text>
          )}
        </ScrollView>
      </SafeAreaView>
    );
  }
 
  // Step 5: Complete
  return (
    <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
      <View style={styles.content}>
        {/* Success */}
        <View style={styles.successContainer}>
          <View style={styles.successIcon}>
            <Ionicons name="checkmark-circle" size={80} color={AppColors.success} />
          </View>
 
          <Text style={styles.successTitle}>WiFi Configured!</Text>
          <Text style={styles.successMessage}>
            Your sensor <Text style={styles.highlight}>{selectedDevice?.name}</Text> is now
            connected to <Text style={styles.highlight}>{selectedWifi?.ssid}</Text>
          </Text>
 
          {/* Next steps */}
          <View style={styles.nextSteps}>
            <Text style={styles.nextStepsTitle}>What happens next:</Text>
            <View style={styles.stepItem}>
              <Ionicons name="checkmark" size={20} color={AppColors.success} />
              <Text style={styles.stepText}>Sensor will connect to your WiFi</Text>
            </View>
            <View style={styles.stepItem}>
              <Ionicons name="checkmark" size={20} color={AppColors.success} />
              <Text style={styles.stepText}>Data will start syncing to WellNuo</Text>
            </View>
            <View style={styles.stepItem}>
              <Ionicons name="checkmark" size={20} color={AppColors.success} />
              <Text style={styles.stepText}>You&apos;ll see updates in the dashboard</Text>
            </View>
          </View>
        </View>
 
        {/* Complete button */}
        <TouchableOpacity style={styles.primaryButton} onPress={handleComplete}>
          <Text style={styles.primaryButtonText}>Continue</Text>
        </TouchableOpacity>
      </View>
    </SafeAreaView>
  );
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: AppColors.background,
  },
  content: {
    flex: 1,
    padding: Spacing.lg,
  },
  header: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    marginBottom: Spacing.xl,
  },
  backButton: {
    padding: Spacing.sm,
    marginLeft: -Spacing.sm,
  },
  title: {
    fontSize: FontSizes.xl,
    fontWeight: FontWeights.bold,
    color: AppColors.textPrimary,
  },
  placeholder: {
    width: 40,
  },
  iconContainer: {
    alignItems: 'center',
    marginBottom: Spacing.lg,
  },
  instructions: {
    fontSize: FontSizes.base,
    color: AppColors.textSecondary,
    textAlign: 'center',
    marginBottom: Spacing.lg,
  },
  loadingContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  loadingText: {
    marginTop: Spacing.md,
    fontSize: FontSizes.base,
    color: AppColors.textSecondary,
  },
  errorContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: Spacing.lg,
  },
  errorText: {
    marginTop: Spacing.md,
    fontSize: FontSizes.base,
    color: AppColors.error,
    textAlign: 'center',
  },
  retryButton: {
    marginTop: Spacing.lg,
    paddingHorizontal: Spacing.xl,
    paddingVertical: Spacing.md,
    backgroundColor: AppColors.primary,
    borderRadius: BorderRadius.lg,
  },
  retryButtonText: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.white,
  },
  deviceList: {
    flex: 1,
    marginBottom: Spacing.md,
  },
  deviceItem: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.lg,
    padding: Spacing.md,
    marginBottom: Spacing.sm,
    gap: Spacing.md,
  },
  deviceIcon: {
    width: 40,
    height: 40,
    borderRadius: 20,
    backgroundColor: `${AppColors.primary}20`,
    alignItems: 'center',
    justifyContent: 'center',
  },
  deviceInfo: {
    flex: 1,
  },
  deviceName: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.medium,
    color: AppColors.textPrimary,
  },
  deviceMeta: {
    fontSize: FontSizes.sm,
    color: AppColors.textMuted,
    marginTop: 2,
  },
  emptyText: {
    fontSize: FontSizes.base,
    color: AppColors.textMuted,
    textAlign: 'center',
    marginTop: Spacing.xl,
  },
  secondaryButton: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    gap: Spacing.sm,
    paddingVertical: Spacing.md,
    borderRadius: BorderRadius.lg,
    borderWidth: 1,
    borderColor: AppColors.primary,
  },
  secondaryButtonText: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.medium,
    color: AppColors.primary,
  },
  connectedDevice: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    gap: Spacing.sm,
    backgroundColor: `${AppColors.success}15`,
    paddingVertical: Spacing.sm,
    paddingHorizontal: Spacing.md,
    borderRadius: BorderRadius.md,
    marginBottom: Spacing.md,
  },
  connectedText: {
    fontSize: FontSizes.sm,
    color: AppColors.success,
    fontWeight: FontWeights.medium,
  },
  selectedNetwork: {
    alignItems: 'center',
    marginBottom: Spacing.lg,
  },
  selectedNetworkLabel: {
    fontSize: FontSizes.sm,
    color: AppColors.textMuted,
  },
  selectedNetworkName: {
    fontSize: FontSizes.lg,
    fontWeight: FontWeights.semibold,
    color: AppColors.textPrimary,
    marginTop: 4,
  },
  inputContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.lg,
    borderWidth: 1,
    borderColor: AppColors.border,
    marginBottom: Spacing.md,
  },
  input: {
    flex: 1,
    paddingHorizontal: Spacing.lg,
    paddingVertical: Spacing.md,
    fontSize: FontSizes.base,
    color: AppColors.textPrimary,
  },
  showPasswordButton: {
    padding: Spacing.md,
  },
  inlineError: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.sm,
    marginBottom: Spacing.md,
  },
  inlineErrorText: {
    fontSize: FontSizes.sm,
    color: AppColors.error,
    flex: 1,
  },
  primaryButton: {
    flexDirection: 'row',
    backgroundColor: AppColors.primary,
    paddingVertical: Spacing.lg,
    borderRadius: BorderRadius.lg,
    alignItems: 'center',
    justifyContent: 'center',
    marginTop: Spacing.md,
  },
  buttonDisabled: {
    opacity: 0.7,
  },
  primaryButtonText: {
    fontSize: FontSizes.lg,
    fontWeight: FontWeights.semibold,
    color: AppColors.white,
  },
  noteText: {
    fontSize: FontSizes.sm,
    color: AppColors.textMuted,
    textAlign: 'center',
    marginTop: Spacing.md,
  },
  successContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  successIcon: {
    marginBottom: Spacing.xl,
  },
  successTitle: {
    fontSize: FontSizes['2xl'],
    fontWeight: FontWeights.bold,
    color: AppColors.textPrimary,
    marginBottom: Spacing.md,
  },
  successMessage: {
    fontSize: FontSizes.base,
    color: AppColors.textSecondary,
    textAlign: 'center',
    marginBottom: Spacing.xl,
    paddingHorizontal: Spacing.lg,
  },
  highlight: {
    fontWeight: FontWeights.bold,
    color: AppColors.primary,
  },
  nextSteps: {
    width: '100%',
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.lg,
    padding: Spacing.lg,
  },
  nextStepsTitle: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.textPrimary,
    marginBottom: Spacing.md,
  },
  stepItem: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.md,
    marginBottom: Spacing.sm,
  },
  stepText: {
    fontSize: FontSizes.sm,
    color: AppColors.textSecondary,
    flex: 1,
  },
});