import 'package:flutter/material.dart'; import 'package:tools/def.dart'; import 'package:tools/models/device.dart'; import 'package:tools/models/post_install_options.dart'; class ReviewInstallView extends StatelessWidget { const ReviewInstallView({ super.key, required this.network, required this.prefix, required this.selectedImage, required this.scriptDestination, required this.localScriptPath, required this.remoteScriptUrl, required this.rebootAfterInstall, required this.postInstallOptionsByDevice, required this.selectedDevices, required this.onStartInstall, }); final String network; final int prefix; final String selectedImage; final ScriptDestination scriptDestination; final String localScriptPath; final String remoteScriptUrl; final bool rebootAfterInstall; final Map postInstallOptionsByDevice; final List selectedDevices; final VoidCallback onStartInstall; String get _scriptSource { return switch (scriptDestination) { ScriptDestination.self => 'Встроенный скрипт', ScriptDestination.local => localScriptPath, ScriptDestination.remote => remoteScriptUrl, }; } @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Проверьте параметры перед запуском', style: Theme.of(context).textTheme.titleMedium, ), const SizedBox(height: 12), Expanded( child: ListView( children: [ ListTile( title: const Text('Сеть'), subtitle: Text('$network/$prefix'), ), ListTile( title: const Text('Образ'), subtitle: Text(selectedImage), ), ListTile( title: const Text('Источник скрипта'), subtitle: Text( _scriptSource.isEmpty ? 'Не указан' : _scriptSource, ), ), ListTile( title: const Text('Перезагрузка после установки'), subtitle: Text(rebootAfterInstall ? 'Да' : 'Нет'), ), ListTile( title: const Text('Пост-установка'), subtitle: Text( 'Настройки заданы для ${selectedDevices.length} устройств', ), ), ListTile( title: const Text('Выбранные устройства'), subtitle: Text('${selectedDevices.length} шт.'), ), const Divider(), ...selectedDevices.map( (device) => ListTile( dense: true, title: Text(device.address), subtitle: Text(_devicePostInstallSummary(device)), trailing: device.isOrange ? const Chip(label: Text('Orange Pi')) : null, ), ), ], ), ), const SizedBox(height: 12), SizedBox( width: double.infinity, child: FilledButton.icon( onPressed: onStartInstall, icon: const Icon(Icons.play_arrow), label: const Text('Начать установку'), ), ), ], ); } String _devicePostInstallSummary(Device device) { final options = postInstallOptionsByDevice[device.address] ?? const PostInstallOptions(); return 'dhcp: ${options.useDhcp ? 'on' : 'off'}, ' '${options.useDhcp ? '' : 'network: ${options.staticNetwork}/${options.staticPrefix}, '}' 'archive: ${options.archiveName.isEmpty ? 'not set' : options.archiveName}, ' 'device: ${options.deviceType}, ' 'root pass: ${options.changeRootPassword ? 'set' : 'skip'}, ' 'trombon pass: ${options.changeTrombonPassword ? 'set' : 'skip'}, ' 'MAC: ${device.mac.isEmpty ? 'unknown' : device.mac}'; } }