import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/utils/prompt_box.dart';
import 'package:flyinsono/views/desktop/device_live/device_live_list/controller.dart';
import 'package:get/get.dart';

class AddVersionDialog extends FStatefulWidget {
  AddVersionDialog({
    required this.deviceVersionType,
    required this.versionAddCallback,
    required this.addVersionTitle,
  });

  final DeviceVersionEnum deviceVersionType;
  final ValueCallback<String> versionAddCallback;
  final String addVersionTitle;

  @override
  FState<AddVersionDialog> createState() => _AddVersionDialogState();
}

class _AddVersionDialogState extends FState<AddVersionDialog> {
  final controller = Get.find<DeviceLiveListDesktopController>();

  String versionText = '';
  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      contentPadding: EdgeInsets.all(30),
      title: FText(
        i18nBook.remoteControl.addVersionNumber.t,
        style: TextStyle(
          color: Colors.white,
          fontSize: 18,
        ),
      ),
      okString: i18nBook.common.submit.t,
      onCancel: () {
        router.back();
      },
      onOk: () async {
        final result = await controller.addDevicePatchVersionAsync(
          deviceVersionType: widget.deviceVersionType,
          version: versionText,
        );
        if (result) {
          widget.versionAddCallback.call(versionText);
          router.back();
        } else {
          PromptBox.toast(i18nBook.remedical.addFailed.t);
        }
      },
      cancelString: i18nBook.common.close.t,
      insetPadding: EdgeInsets.symmetric(vertical: 100),
      children: [
        _buildAddVersionTitle(),
        _buildAddVersionInput(),
      ],
      isDefault: true,
    );
  }

  FWidget _buildAddVersionTitle() {
    return FContainer(
      margin: EdgeInsets.only(bottom: 15),
      child: FText(
        widget.addVersionTitle,
        // i18nBook.remoteControl.enterUltrasoundSoftwareVersion.t,
      ),
    );
  }

  FWidget _buildAddVersionInput() {
    /// 输入框
    return FContainer(
      width: 400,
      child: FRow(
        children: [
          FBorderInput(
            hintSize: 16,
            contentSize: 16,
            maxLength: 20,
            borderColor: Color.fromRGBO(234, 234, 234, 1),
            height: 38,
            hintText: '',
            onChanged: (value) {
              versionText = value;
            },
          )
        ],
      ),
    );
  }
}
