import 'package:flutter/material.dart';

/// 应用国际化配置
class AppLocalizations {
  final Locale locale;

  AppLocalizations(this.locale);

  static AppLocalizations? of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations);
  }

  static const LocalizationsDelegate<AppLocalizations> delegate =
      _AppLocalizationsDelegate();

  // 状态栏
  String get deviceName => _localizedValues[locale.languageCode]?['deviceName'] ?? '污水毒品前处理一体机';
  String get running => _localizedValues[locale.languageCode]?['running'] ?? '运行中';
  String get idle => _localizedValues[locale.languageCode]?['idle'] ?? '未运行';
  String get lighting => _localizedValues[locale.languageCode]?['lighting'] ?? '照明';
  String get deviceControl => _localizedValues[locale.languageCode]?['deviceControl'] ?? '设备控制';

  // 程序管理
  String get programs => _localizedValues[locale.languageCode]?['programs'] ?? '程序管理';
  String get programList => _localizedValues[locale.languageCode]?['programList'] ?? '程序列表';
  String get programName => _localizedValues[locale.languageCode]?['programName'] ?? '程序名称';
  String get programCode => _localizedValues[locale.languageCode]?['programCode'] ?? '程序编号';
  String get createTime => _localizedValues[locale.languageCode]?['createTime'] ?? '创建时间';
  String get addProgram => _localizedValues[locale.languageCode]?['addProgram'] ?? '新增程序';
  String get editProgram => _localizedValues[locale.languageCode]?['editProgram'] ?? '编辑程序';
  String get deleteProgram => _localizedValues[locale.languageCode]?['deleteProgram'] ?? '删除程序';
  String get importProgram => _localizedValues[locale.languageCode]?['importProgram'] ?? '导入程序';
  String get downloadTemplate => _localizedValues[locale.languageCode]?['downloadTemplate'] ?? '下载模板';
  String get viewDetails => _localizedValues[locale.languageCode]?['viewDetails'] ?? '查看详情';
  String get selectedProgram => _localizedValues[locale.languageCode]?['selectedProgram'] ?? '当前选中程序';
  String get selectedProgramLabel => _localizedValues[locale.languageCode]?['selectedProgramLabel'] ?? '当前选中';
  String get availablePrograms => _localizedValues[locale.languageCode]?['availablePrograms'] ?? '可用程序';
  String get runningMonitor => _localizedValues[locale.languageCode]?['runningMonitor'] ?? '运行状态监控';
  String get currentHole => _localizedValues[locale.languageCode]?['currentHole'] ?? '当前孔位';
  String get stepParams => _localizedValues[locale.languageCode]?['stepParams'] ?? '步骤参数';
  String get speed => _localizedValues[locale.languageCode]?['speed'] ?? '速度';
  String get speedLevel => _localizedValues[locale.languageCode]?['speedLevel'] ?? '档';
  String get temperature => _localizedValues[locale.languageCode]?['temperature'] ?? '温度';
  String get airflowTime => _localizedValues[locale.languageCode]?['airflowTime'] ?? '吹气时间';
  String get duration => _localizedValues[locale.languageCode]?['duration'] ?? '持续时间';
  String get sampleVolume => _localizedValues[locale.languageCode]?['sampleVolume'] ?? '样品体积';
  String get pleaseSelectProgram => _localizedValues[locale.languageCode]?['pleaseSelectProgram'] ?? '请选择要运行的程序';

  // 运行控制
  String get run => _localizedValues[locale.languageCode]?['run'] ?? '运行';
  String get pause => _localizedValues[locale.languageCode]?['pause'] ?? '暂停';
  String get continue_ => _localizedValues[locale.languageCode]?['continue'] ?? '继续';
  String get stop => _localizedValues[locale.languageCode]?['stop'] ?? '停止';
  String get startRun => _localizedValues[locale.languageCode]?['startRun'] ?? '开始运行';
  String get currentStep => _localizedValues[locale.languageCode]?['currentStep'] ?? '当前步骤';
  String get remainingTime => _localizedValues[locale.languageCode]?['remainingTime'] ?? '剩余时间';
  String get progress => _localizedValues[locale.languageCode]?['progress'] ?? '进度';
  String get ceramicSleeveConfirm => _localizedValues[locale.languageCode]?['ceramicSleeveConfirm'] ?? '运行前请确认已安装瓷套棒';
  String get ceramicSleeveConfirmMessage => _localizedValues[locale.languageCode]?['ceramicSleeveConfirmMessage'] ?? '请确认已放置瓷套棒后再启动程序。';
  String get paused => _localizedValues[locale.languageCode]?['paused'] ?? '已暂停';
  String get stopConfirm => _localizedValues[locale.languageCode]?['stopConfirm'] ?? '确定要停止当前运行的程序吗？';
  String get currentProgram => _localizedValues[locale.languageCode]?['currentProgram'] ?? '当前程序';
  String get backToHome => _localizedValues[locale.languageCode]?['backToHome'] ?? '返回首页';
  String get runAgain => _localizedValues[locale.languageCode]?['runAgain'] ?? '重新运行';
  String get deleteConfirm => _localizedValues[locale.languageCode]?['deleteConfirm'] ?? '确定要删除此程序吗？';

  // 步骤参数
  String get stepNo => _localizedValues[locale.languageCode]?['stepNo'] ?? '步骤编号';
  String get position => _localizedValues[locale.languageCode]?['position'] ?? '孔位';
  String get stepName => _localizedValues[locale.languageCode]?['stepName'] ?? '步骤名称';
  String get mixTime => _localizedValues[locale.languageCode]?['mixTime'] ?? '混合时间';
  String get magnetTime => _localizedValues[locale.languageCode]?['magnetTime'] ?? '吸磁时间';
  String get volume => _localizedValues[locale.languageCode]?['volume'] ?? '容积';
  String get blowTime => _localizedValues[locale.languageCode]?['blowTime'] ?? '吹气时间';

  // 设置
  String get settings => _localizedValues[locale.languageCode]?['settings'] ?? '系统设置';
  String get language => _localizedValues[locale.languageCode]?['language'] ?? '语言设置';
  String get password => _localizedValues[locale.languageCode]?['password'] ?? '密码修改';
  String get upgrade => _localizedValues[locale.languageCode]?['upgrade'] ?? '软件升级';
  String get usbImport => _localizedValues[locale.languageCode]?['usbImport'] ?? 'U盘导入';

  // 通用
  String get confirm => _localizedValues[locale.languageCode]?['confirm'] ?? '确认';
  String get cancel => _localizedValues[locale.languageCode]?['cancel'] ?? '取消';
  String get save => _localizedValues[locale.languageCode]?['save'] ?? '保存';
  String get delete => _localizedValues[locale.languageCode]?['delete'] ?? '删除';
  String get select => _localizedValues[locale.languageCode]?['select'] ?? '选择';
  String get selected => _localizedValues[locale.languageCode]?['selected'] ?? '已选择';
  String get detail => _localizedValues[locale.languageCode]?['detail'] ?? '详情';
  String get noData => _localizedValues[locale.languageCode]?['noData'] ?? '暂无数据';

  // 完成提示
  String get runComplete => _localizedValues[locale.languageCode]?['runComplete'] ?? '运行完成';
  String get sampleDropGuide => _localizedValues[locale.languageCode]?['sampleDropGuide'] ?? '请将样本滴入检测卡';
  String get complete => _localizedValues[locale.languageCode]?['complete'] ?? '完成';

  // 补充缺失的翻译
  String get lightOn => _localizedValues[locale.languageCode]?['lightOn'] ?? '亮';
  String get lightOff => _localizedValues[locale.languageCode]?['lightOff'] ?? '暗';
  String get enabled => _localizedValues[locale.languageCode]?['enabled'] ?? '启用';
  String get disabled => _localizedValues[locale.languageCode]?['disabled'] ?? '停用';
  String get stepList => _localizedValues[locale.languageCode]?['stepList'] ?? '步骤列表';
  String get operationSteps => _localizedValues[locale.languageCode]?['operationSteps'] ?? '操作步骤';
  String get addStep => _localizedValues[locale.languageCode]?['addStep'] ?? '添加步骤';
  String get editStep => _localizedValues[locale.languageCode]?['editStep'] ?? '编辑步骤';
  String get deleteStep => _localizedValues[locale.languageCode]?['deleteStep'] ?? '删除步骤';
  String get deleteStepConfirm => _localizedValues[locale.languageCode]?['deleteStepConfirm'] ?? '确定要删除此步骤吗？';
  String get stepsCount => _localizedValues[locale.languageCode]?['stepsCount'] ?? '步';
  String get noSteps => _localizedValues[locale.languageCode]?['noSteps'] ?? '暂无步骤';
  String get selectStepFirst => _localizedValues[locale.languageCode]?['selectStepFirst'] ?? '请选择或添加步骤';
  String get oldPassword => _localizedValues[locale.languageCode]?['oldPassword'] ?? '原密码';
  String get newPassword => _localizedValues[locale.languageCode]?['newPassword'] ?? '新密码';
  String get confirmPassword => _localizedValues[locale.languageCode]?['confirmPassword'] ?? '确认新密码';
  String get passwordMinLength => _localizedValues[locale.languageCode]?['passwordMinLength'] ?? '至少6位字符';
  String get passwordChanged => _localizedValues[locale.languageCode]?['passwordChanged'] ?? '密码已修改';
  String get passwordChangeFailed => _localizedValues[locale.languageCode]?['passwordChangeFailed'] ?? '密码修改失败';
  String get oldPasswordError => _localizedValues[locale.languageCode]?['oldPasswordError'] ?? '原密码错误';
  String get passwordMismatch => _localizedValues[locale.languageCode]?['passwordMismatch'] ?? '两次输入的新密码不一致';
  String get fillAllFields => _localizedValues[locale.languageCode]?['fillAllFields'] ?? '请填写所有字段';
  String get importSuccess => _localizedValues[locale.languageCode]?['importSuccess'] ?? '成功导入';
  String get importFailed => _localizedValues[locale.languageCode]?['importFailed'] ?? '导入失败';
  String get programsImported => _localizedValues[locale.languageCode]?['programsImported'] ?? '个程序';
  String get usbDetected => _localizedValues[locale.languageCode]?['usbDetected'] ?? '检测到U盘';
  String get usbNotDetected => _localizedValues[locale.languageCode]?['usbNotDetected'] ?? '未检测到U盘';
  String get insertUsb => _localizedValues[locale.languageCode]?['insertUsb'] ?? '请插入U盘后重试';
  String get detectingUsb => _localizedValues[locale.languageCode]?['detectingUsb'] ?? '正在检测U盘...';
  String get currentVersion => _localizedValues[locale.languageCode]?['currentVersion'] ?? '当前版本';
  String get latestVersion => _localizedValues[locale.languageCode]?['latestVersion'] ?? '已是最新版本';
  String get updateAvailable => _localizedValues[locale.languageCode]?['updateAvailable'] ?? '有新版本可用';
  String get checkUpdate => _localizedValues[locale.languageCode]?['checkUpdate'] ?? '检查更新';

  // ---- 状态 ----
  String get status => _localizedValues[locale.languageCode]?['status'] ?? '状态';
  String get operation => _localizedValues[locale.languageCode]?['operation'] ?? '操作';
  String get serialConnected => _localizedValues[locale.languageCode]?['serialConnected'] ?? '已连接';
  String get serialConnecting => _localizedValues[locale.languageCode]?['serialConnecting'] ?? '连接中';
  String get serialDisconnected => _localizedValues[locale.languageCode]?['serialDisconnected'] ?? '未连接';
  String get serialError => _localizedValues[locale.languageCode]?['serialError'] ?? '错误';

  // ---- 完成页 ----
  String get programRunComplete => _localizedValues[locale.languageCode]?['programRunComplete'] ?? '程序运行完成';
  String get extractSample => _localizedValues[locale.languageCode]?['extractSample'] ?? '取出样本';
  String get dropToTestCard => _localizedValues[locale.languageCode]?['dropToTestCard'] ?? '滴入检测卡';
  String get waitForReaction => _localizedValues[locale.languageCode]?['waitForReaction'] ?? '等待反应';
  String get viewResults => _localizedValues[locale.languageCode]?['viewResults'] ?? '查看结果';

  // ---- 表单 ----
  String get codeLabel => _localizedValues[locale.languageCode]?['codeLabel'] ?? '编号';
  String get nameLabel => _localizedValues[locale.languageCode]?['nameLabel'] ?? '名称';
  String get enterCode => _localizedValues[locale.languageCode]?['enterCode'] ?? '请输入编号';
  String get enterName => _localizedValues[locale.languageCode]?['enterName'] ?? '请输入名称';
  String get enterStepName => _localizedValues[locale.languageCode]?['enterStepName'] ?? '请输入步骤名称';
  String get hintCode => _localizedValues[locale.languageCode]?['hintCode'] ?? '例如: P001';
  String get hintProgramName => _localizedValues[locale.languageCode]?['hintProgramName'] ?? '请输入程序名称';
  String get hintStepName => _localizedValues[locale.languageCode]?['hintStepName'] ?? '例如: 混合、吸磁、吹气';
  String get saveFailed => _localizedValues[locale.languageCode]?['saveFailed'] ?? '保存失败，请检查编号是否重复';
  String get saved => _localizedValues[locale.languageCode]?['saved'] ?? '已保存';
  String get stepUpdated => _localizedValues[locale.languageCode]?['stepUpdated'] ?? '步骤已更新';
  String get add => _localizedValues[locale.languageCode]?['add'] ?? '添加';
  String get reset => _localizedValues[locale.languageCode]?['reset'] ?? '重置';
  String get confirmNewPassword => _localizedValues[locale.languageCode]?['confirmNewPassword'] ?? '确认新密码';
  String get enterNewPassword => _localizedValues[locale.languageCode]?['enterNewPassword'] ?? '再次输入新密码';
  String get enterCurrentPassword => _localizedValues[locale.languageCode]?['enterCurrentPassword'] ?? '请输入当前密码';
  String get newPwdMinLength => _localizedValues[locale.languageCode]?['newPwdMinLength'] ?? '新密码至少6位字符';
  String get defaultPassword => _localizedValues[locale.languageCode]?['defaultPassword'] ?? '默认密码为 123456';

  // ---- 删除确认 ----
  String get deleteConfirmSingle => _localizedValues[locale.languageCode]?['deleteConfirmSingle'] ?? '确定要删除此程序吗？';
  String deleteConfirmMultiple(int count) =>
    locale.languageCode == 'en'
      ? 'Are you sure to delete $count selected programs?'
      : '确定要删除选中的 $count 个程序吗？';
  String get deleteStepConfirmSingle => _localizedValues[locale.languageCode]?['deleteStepConfirmSingle'] ?? '确定要删除此步骤吗？';
  String deleteStepConfirmMultiple(int count) =>
    locale.languageCode == 'en'
      ? 'Are you sure to delete $count selected steps?'
      : '确定要删除选中的 $count 个步骤吗？';

  // ---- 导入 ----
  String get cannotReadFile => _localizedValues[locale.languageCode]?['cannotReadFile'] ?? '无法读取文件';
  String processedPrograms(int count) =>
    locale.languageCode == 'en'
      ? 'Successfully processed $count programs'
      : '成功处理 $count 个程序';
  String get noValidProgramData => _localizedValues[locale.languageCode]?['noValidProgramData'] ?? 'Excel 中无有效程序数据';
  String get templateSaved => _localizedValues[locale.languageCode]?['templateSaved'] ?? '模板已保存';
  String get generateTemplateFailed => _localizedValues[locale.languageCode]?['generateTemplateFailed'] ?? '生成模板失败';
  String get importingPrograms => _localizedValues[locale.languageCode]?['importingPrograms'] ?? '正在导入程序...';

  // ---- 语言设置 ----
  String get languageSettings => _localizedValues[locale.languageCode]?['languageSettings'] ?? '语言设置';
  String get switchLanguageEffect => _localizedValues[locale.languageCode]?['switchLanguageEffect'] ?? '切换语言后立即生效';

  // ---- 串口配置 ----
  String get serialStatus => _localizedValues[locale.languageCode]?['serialStatus'] ?? '串口状态';
  String get availableSerialDevices => _localizedValues[locale.languageCode]?['availableSerialDevices'] ?? '可用串口设备';
  String get refresh => _localizedValues[locale.languageCode]?['refresh'] ?? '刷新';
  String get noSerialDevice => _localizedValues[locale.languageCode]?['noSerialDevice'] ?? '未检测到 USB 串口设备';
  String get serialDeviceHint => _localizedValues[locale.languageCode]?['serialDeviceHint'] ?? '请确认下位机已上电并通过 USB 接入设备';
  String get scanFailed => _localizedValues[locale.languageCode]?['scanFailed'] ?? '扫描设备失败';
  String get selectSerialFirst => _localizedValues[locale.languageCode]?['selectSerialFirst'] ?? '请先选择串口设备';
  String get connectSuccess => _localizedValues[locale.languageCode]?['connectSuccess'] ?? '连接成功';
  String get connectFailed => _localizedValues[locale.languageCode]?['connectFailed'] ?? '连接失败';
  String get disconnected => _localizedValues[locale.languageCode]?['disconnected'] ?? '已断开串口';
  String get connectFirst => _localizedValues[locale.languageCode]?['connectFirst'] ?? '请先连接串口';
  String get sendTestFrame => _localizedValues[locale.languageCode]?['sendTestFrame'] ?? '发送测试帧';
  String get serialParams => _localizedValues[locale.languageCode]?['serialParams'] ?? '串口参数';
  String get baudRate => _localizedValues[locale.languageCode]?['baudRate'] ?? '波特率';
  String get dataBits => _localizedValues[locale.languageCode]?['dataBits'] ?? '数据位';
  String get stopBits => _localizedValues[locale.languageCode]?['stopBits'] ?? '停止位';
  String get parity => _localizedValues[locale.languageCode]?['parity'] ?? '校验位';
  String get parityNone => _localizedValues[locale.languageCode]?['parityNone'] ?? '无';
  String get parityOdd => _localizedValues[locale.languageCode]?['parityOdd'] ?? '奇';
  String get parityEven => _localizedValues[locale.languageCode]?['parityEven'] ?? '偶';
  String get parityMark => _localizedValues[locale.languageCode]?['parityMark'] ?? '标记';
  String get paritySpace => _localizedValues[locale.languageCode]?['paritySpace'] ?? '空';
  String get flowControl => _localizedValues[locale.languageCode]?['flowControl'] ?? '流控';
  String get autoSaveParams => _localizedValues[locale.languageCode]?['autoSaveParams'] ?? '参数修改后自动保存';
  String get connect => _localizedValues[locale.languageCode]?['connect'] ?? '连接';
  String get disconnect => _localizedValues[locale.languageCode]?['disconnect'] ?? '断开';
  String get unknownError => _localizedValues[locale.languageCode]?['unknownError'] ?? '未知错误';

  // ---- USB 导入 ----
  String get usbConnected => _localizedValues[locale.languageCode]?['usbConnected'] ?? 'U盘已连接';
  String get mountPath => _localizedValues[locale.languageCode]?['mountPath'] ?? '挂载路径';
  String get reDetect => _localizedValues[locale.languageCode]?['reDetect'] ?? '重新检测';
  String get usageInstructions => _localizedValues[locale.languageCode]?['usageInstructions'] ?? '使用说明';
  String get usbUsageStep1 => _localizedValues[locale.languageCode]?['usbUsageStep1'] ?? '将程序文件 (.json) 放入 U盘根目录的 programs 文件夹';
  String get usbUsageStep2 => _localizedValues[locale.languageCode]?['usbUsageStep2'] ?? '插入 U盘后点击"重新检测"';
  String get usbUsageStep3 => _localizedValues[locale.languageCode]?['usbUsageStep3'] ?? '检测成功后点击"导入程序"加载程序列表';
  String get usbPathInvalid => _localizedValues[locale.languageCode]?['usbPathInvalid'] ?? 'U盘路径无效';

  // ---- 启动认证 ----
  String get authTitle => _localizedValues[locale.languageCode]?['authTitle'] ?? '身份验证';
  String get authSubtitle => _localizedValues[locale.languageCode]?['authSubtitle'] ?? '请输入操作员密码以继续使用';
  String get enterPassword => _localizedValues[locale.languageCode]?['enterPassword'] ?? '请输入密码';
  String get passwordError => _localizedValues[locale.languageCode]?['passwordError'] ?? '密码错误';
  String lockCountdown(int seconds) =>
    locale.languageCode == 'en'
      ? 'Please wait $seconds seconds to retry'
      : '请等待 $seconds 秒后重试';
  String remainingAttempts(int count) =>
    locale.languageCode == 'en'
      ? '$count attempt${count > 1 ? 's' : ''} remaining'
      : '剩余 $count 次尝试机会';

  // ---- 通用 ----
  String get back => _localizedValues[locale.languageCode]?['back'] ?? '返回';
  String get totalProgress => _localizedValues[locale.languageCode]?['totalProgress'] ?? '总进度';
  String get appTitle => _localizedValues[locale.languageCode]?['appTitle'] ?? '污水毒品快检一体机';

  // ---- 参数化方法 ----
  String get stepUnit => _localizedValues[locale.languageCode]?['stepUnit'] ?? '步';
  String speedLevelValue(int speed) =>
    locale.languageCode == 'en'
      ? '$speed level'
      : '$speed 档';
  String stepLabel(int stepNo) =>
    locale.languageCode == 'en'
      ? 'Step $stepNo'
      : '步骤 $stepNo';
  String stepsCountLabel(int count) =>
    locale.languageCode == 'en'
      ? '$count steps'
      : '$count 步';

  static final Map<String, Map<String, String>> _localizedValues = {
    'zh': {
      'deviceName': '污水毒品前处理一体机',
      'running': '运行中',
      'idle': '未运行',
      'lighting': '照明',
      'deviceControl': '设备控制',
      'programs': '程序管理',
      'programList': '程序列表',
      'programName': '程序名称',
      'programCode': '程序编号',
      'createTime': '创建时间',
      'addProgram': '新增程序',
      'editProgram': '编辑程序',
      'deleteProgram': '删除程序',
      'importProgram': '导入程序',
      'downloadTemplate': '下载模板',
      'viewDetails': '查看详情',
      'selectedProgram': '当前选中程序',
      'selectedProgramLabel': '当前选中',
      'availablePrograms': '可用程序',
      'runningMonitor': '运行状态监控',
      'currentHole': '当前孔位',
      'stepParams': '步骤参数',
      'speed': '速度',
      'speedLevel': '档',
      'temperature': '温度',
      'airflowTime': '吹气时间',
      'duration': '持续时间',
      'sampleVolume': '样品体积',
      'pleaseSelectProgram': '请选择要运行的程序',
      'run': '运行',
      'pause': '暂停',
      'continue': '继续',
      'stop': '停止',
      'startRun': '开始运行',
      'currentStep': '当前步骤',
      'remainingTime': '剩余时间',
      'progress': '进度',
      'ceramicSleeveConfirm': '运行前请确认已安装瓷套棒',
      'ceramicSleeveConfirmMessage': '请确认已放置瓷套棒后再启动程序。',
      'paused': '已暂停',
      'stopConfirm': '确定要停止当前运行的程序吗？',
      'currentProgram': '当前程序',
      'backToHome': '返回首页',
      'runAgain': '重新运行',
      'deleteConfirm': '确定要删除此程序吗？',
      'stepNo': '步骤编号',
      'position': '孔位',
      'stepName': '步骤名称',
      'mixTime': '混合时间',
      'magnetTime': '吸磁时间',
      'volume': '容积',
      'blowTime': '吹气时间',
      'settings': '系统设置',
      'language': '语言设置',
      'password': '密码修改',
      'upgrade': '软件升级',
      'usbImport': 'U盘导入',
      'confirm': '确认',
      'cancel': '取消',
      'save': '保存',
      'delete': '删除',
      'select': '选择',
      'selected': '已选择',
      'detail': '详情',
      'noData': '暂无数据',
      'runComplete': '运行完成',
      'sampleDropGuide': '请将样本滴入检测卡',
      'complete': '完成',
      'lightOn': '亮',
      'lightOff': '暗',
      'enabled': '启用',
      'disabled': '停用',
      'stepList': '步骤列表',
      'operationSteps': '操作步骤',
      'addStep': '添加步骤',
      'editStep': '编辑步骤',
      'deleteStep': '删除步骤',
      'deleteStepConfirm': '确定要删除此步骤吗？',
      'stepsCount': '步',
      'noSteps': '暂无步骤',
      'selectStepFirst': '请选择或添加步骤',
      'oldPassword': '原密码',
      'newPassword': '新密码',
      'confirmPassword': '确认新密码',
      'passwordMinLength': '至少6位字符',
      'passwordChanged': '密码已修改',
      'passwordChangeFailed': '密码修改失败',
      'oldPasswordError': '原密码错误',
      'passwordMismatch': '两次输入的新密码不一致',
      'fillAllFields': '请填写所有字段',
      'importSuccess': '成功导入',
      'importFailed': '导入失败',
      'programsImported': '个程序',
      'usbDetected': '检测到U盘',
      'usbNotDetected': '未检测到U盘',
      'insertUsb': '请插入U盘后重试',
      'detectingUsb': '正在检测U盘...',
      'currentVersion': '当前版本',
      'latestVersion': '已是最新版本',
      'updateAvailable': '有新版本可用',
      'checkUpdate': '检查更新',
      'status': '状态',
      'operation': '操作',
      'serialConnected': '已连接',
      'serialConnecting': '连接中',
      'serialDisconnected': '未连接',
      'serialError': '错误',
      'programRunComplete': '程序运行完成',
      'extractSample': '取出样本',
      'dropToTestCard': '滴入检测卡',
      'waitForReaction': '等待反应',
      'viewResults': '查看结果',
      'codeLabel': '编号',
      'nameLabel': '名称',
      'enterCode': '请输入编号',
      'enterName': '请输入名称',
      'enterStepName': '请输入步骤名称',
      'hintCode': '例如: P001',
      'hintProgramName': '请输入程序名称',
      'hintStepName': '例如: 混合、吸磁、吹气',
      'saveFailed': '保存失败，请检查编号是否重复',
      'saved': '已保存',
      'stepUpdated': '步骤已更新',
      'add': '添加',
      'reset': '重置',
      'confirmNewPassword': '确认新密码',
      'enterNewPassword': '再次输入新密码',
      'enterCurrentPassword': '请输入当前密码',
      'newPwdMinLength': '新密码至少6位字符',
      'defaultPassword': '默认密码为 123456',
      'deleteConfirmSingle': '确定要删除此程序吗？',
      'deleteStepConfirmSingle': '确定要删除此步骤吗？',
      'cannotReadFile': '无法读取文件',
      'noValidProgramData': 'Excel 中无有效程序数据',
      'templateSaved': '模板已保存',
      'generateTemplateFailed': '生成模板失败',
      'importingPrograms': '正在导入程序...',
      'languageSettings': '语言设置',
      'switchLanguageEffect': '切换语言后立即生效',
      'serialStatus': '串口状态',
      'availableSerialDevices': '可用串口设备',
      'refresh': '刷新',
      'noSerialDevice': '未检测到 USB 串口设备',
      'serialDeviceHint': '请确认下位机已上电并通过 USB 接入设备',
      'scanFailed': '扫描设备失败',
      'selectSerialFirst': '请先选择串口设备',
      'connectSuccess': '连接成功',
      'connectFailed': '连接失败',
      'disconnected': '已断开串口',
      'connectFirst': '请先连接串口',
      'sendTestFrame': '发送测试帧',
      'serialParams': '串口参数',
      'baudRate': '波特率',
      'dataBits': '数据位',
      'stopBits': '停止位',
      'parity': '校验位',
      'parityNone': '无',
      'parityOdd': '奇',
      'parityEven': '偶',
      'parityMark': '标记',
      'paritySpace': '空',
      'flowControl': '流控',
      'autoSaveParams': '参数修改后自动保存',
      'connect': '连接',
      'disconnect': '断开',
      'unknownError': '未知错误',
      'usbConnected': 'U盘已连接',
      'mountPath': '挂载路径',
      'reDetect': '重新检测',
      'usageInstructions': '使用说明',
      'usbUsageStep1': '将程序文件 (.json) 放入 U盘根目录的 programs 文件夹',
      'usbUsageStep2': '插入 U盘后点击"重新检测"',
      'usbUsageStep3': '检测成功后点击"导入程序"加载程序列表',
      'usbPathInvalid': 'U盘路径无效',
      'authTitle': '身份验证',
      'authSubtitle': '请输入操作员密码以继续使用',
      'enterPassword': '请输入密码',
      'passwordError': '密码错误',
      'back': '返回',
      'totalProgress': '总进度',
      'appTitle': '污水毒品快检一体机',
      'stepUnit': '步',
    },
    'en': {
      'deviceName': 'Wastewater Drug Pretreatment System',
      'running': 'Running',
      'idle': 'Idle',
      'lighting': 'Lighting',
      'deviceControl': 'Device Control',
      'programs': 'Programs',
      'programList': 'Program List',
      'programName': 'Program Name',
      'programCode': 'Program Code',
      'createTime': 'Create Time',
      'addProgram': 'Add Program',
      'editProgram': 'Edit Program',
      'deleteProgram': 'Delete Program',
      'importProgram': 'Import Program',
      'downloadTemplate': 'Download Template',
      'viewDetails': 'View Details',
      'selectedProgram': 'Selected Program',
      'selectedProgramLabel': 'Selected',
      'availablePrograms': 'Available Programs',
      'runningMonitor': 'Running Status Monitor',
      'currentHole': 'Current Position',
      'stepParams': 'Step Parameters',
      'speed': 'Speed',
      'speedLevel': 'level',
      'temperature': 'Temperature',
      'airflowTime': 'Airflow Time',
      'duration': 'Duration',
      'sampleVolume': 'Sample Volume',
      'pleaseSelectProgram': 'Please select a program',
      'run': 'Run',
      'pause': 'Pause',
      'continue': 'Continue',
      'stop': 'Stop',
      'startRun': 'Start Run',
      'currentStep': 'Current Step',
      'remainingTime': 'Remaining',
      'progress': 'Progress',
      'ceramicSleeveConfirm': 'Please confirm ceramic sleeve is installed',
      'ceramicSleeveConfirmMessage': 'Please make sure the ceramic sleeve is in place before starting the program.',
      'paused': 'Paused',
      'stopConfirm': 'Are you sure to stop the running program?',
      'currentProgram': 'Current Program',
      'backToHome': 'Back to Home',
      'runAgain': 'Run Again',
      'deleteConfirm': 'Are you sure to delete this program?',
      'stepNo': 'Step No.',
      'position': 'Position',
      'stepName': 'Step Name',
      'mixTime': 'Mix Time',
      'magnetTime': 'Magnet Time',
      'volume': 'Volume',
      'blowTime': 'Blow Time',
      'settings': 'Settings',
      'language': 'Language',
      'password': 'Password',
      'upgrade': 'Upgrade',
      'usbImport': 'USB Import',
      'confirm': 'Confirm',
      'cancel': 'Cancel',
      'save': 'Save',
      'delete': 'Delete',
      'select': 'Select',
      'selected': 'Selected',
      'detail': 'Detail',
      'noData': 'No Data',
      'runComplete': 'Complete',
      'sampleDropGuide': 'Drop sample to test card',
      'complete': 'Done',
      'lightOn': 'On',
      'lightOff': 'Off',
      'enabled': 'Enabled',
      'disabled': 'Disabled',
      'stepList': 'Step List',
      'operationSteps': 'Operation Steps',
      'addStep': 'Add Step',
      'editStep': 'Edit Step',
      'deleteStep': 'Delete Step',
      'deleteStepConfirm': 'Are you sure to delete this step?',
      'stepsCount': 'steps',
      'noSteps': 'No steps',
      'selectStepFirst': 'Please select or add a step',
      'oldPassword': 'Old Password',
      'newPassword': 'New Password',
      'confirmPassword': 'Confirm Password',
      'passwordMinLength': 'At least 6 characters',
      'passwordChanged': 'Password changed',
      'passwordChangeFailed': 'Password change failed',
      'oldPasswordError': 'Old password incorrect',
      'passwordMismatch': 'Passwords do not match',
      'fillAllFields': 'Please fill all fields',
      'importSuccess': 'Successfully imported',
      'importFailed': 'Import failed',
      'programsImported': 'programs',
      'usbDetected': 'USB detected',
      'usbNotDetected': 'USB not detected',
      'insertUsb': 'Please insert USB and try again',
      'detectingUsb': 'Detecting USB...',
      'currentVersion': 'Current Version',
      'latestVersion': 'Already latest version',
      'updateAvailable': 'Update available',
      'checkUpdate': 'Check Update',
      'status': 'Status',
      'operation': 'Actions',
      'serialConnected': 'Connected',
      'serialConnecting': 'Connecting',
      'serialDisconnected': 'Disconnected',
      'serialError': 'Error',
      'programRunComplete': 'Program Run Complete',
      'extractSample': 'Extract Sample',
      'dropToTestCard': 'Drop to Test Card',
      'waitForReaction': 'Wait for Reaction',
      'viewResults': 'View Results',
      'codeLabel': 'Code',
      'nameLabel': 'Name',
      'enterCode': 'Please enter code',
      'enterName': 'Please enter name',
      'enterStepName': 'Please enter step name',
      'hintCode': 'e.g. P001',
      'hintProgramName': 'Enter program name',
      'hintStepName': 'e.g. Mix, Magnet, Blow',
      'saveFailed': 'Save failed, please check if code is duplicate',
      'saved': 'Saved',
      'stepUpdated': 'Step updated',
      'add': 'Add',
      'reset': 'Reset',
      'confirmNewPassword': 'Confirm New Password',
      'enterNewPassword': 'Re-enter new password',
      'enterCurrentPassword': 'Enter current password',
      'newPwdMinLength': 'New password at least 6 characters',
      'defaultPassword': 'Default password is 123456',
      'deleteConfirmSingle': 'Are you sure to delete this program?',
      'deleteStepConfirmSingle': 'Are you sure to delete this step?',
      'cannotReadFile': 'Cannot read file',
      'noValidProgramData': 'No valid program data in Excel',
      'templateSaved': 'Template saved',
      'generateTemplateFailed': 'Failed to generate template',
      'importingPrograms': 'Importing programs...',
      'languageSettings': 'Language Settings',
      'switchLanguageEffect': 'Language change takes effect immediately',
      'serialStatus': 'Serial Status',
      'availableSerialDevices': 'Available Serial Devices',
      'refresh': 'Refresh',
      'noSerialDevice': 'No USB serial device detected',
      'serialDeviceHint': 'Please ensure the device is powered on and connected via USB',
      'scanFailed': 'Device scan failed',
      'selectSerialFirst': 'Please select a serial device first',
      'connectSuccess': 'Connected successfully',
      'connectFailed': 'Connection failed',
      'disconnected': 'Serial disconnected',
      'connectFirst': 'Please connect serial first',
      'sendTestFrame': 'Send Test Frame',
      'serialParams': 'Serial Parameters',
      'baudRate': 'Baud Rate',
      'dataBits': 'Data Bits',
      'stopBits': 'Stop Bits',
      'parity': 'Parity',
      'parityNone': 'None',
      'parityOdd': 'Odd',
      'parityEven': 'Even',
      'parityMark': 'Mark',
      'paritySpace': 'Space',
      'flowControl': 'Flow Control',
      'autoSaveParams': 'Parameters auto-saved after change',
      'connect': 'Connect',
      'disconnect': 'Disconnect',
      'unknownError': 'Unknown error',
      'usbConnected': 'USB Connected',
      'mountPath': 'Mount Path',
      'reDetect': 'Re-detect',
      'usageInstructions': 'Usage Instructions',
      'usbUsageStep1': 'Place program files (.json) in the programs folder on USB root',
      'usbUsageStep2': 'Insert USB then click "Re-detect"',
      'usbUsageStep3': 'After detection, click "Import Programs" to load',
      'usbPathInvalid': 'USB path invalid',
      'authTitle': 'Authentication',
      'authSubtitle': 'Enter operator password to continue',
      'enterPassword': 'Enter password',
      'passwordError': 'Password incorrect',
      'back': 'Back',
      'totalProgress': 'Total Progress',
      'appTitle': 'Wastewater Drug Detection System',
      'stepUnit': 'steps',
    },
  };
}

class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const _AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) {
    return ['zh', 'en'].contains(locale.languageCode);
  }

  @override
  Future<AppLocalizations> load(Locale locale) async {
    return AppLocalizations(locale);
  }

  @override
  bool shouldReload(_AppLocalizationsDelegate old) => false;
}