import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:fis_lib_qrcode/qr_flutter.dart';
import 'package:flyinsono/architecture/utils/prompt_box.dart';
import 'package:flyinsono/rpc.dart';
import 'package:fis_common/index.dart';

class DeviceLiveShareDialog extends FStatelessWidget {
  DeviceLiveShareDialog({required this.link});

  final String link;
  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      contentPadding: EdgeInsets.symmetric(vertical: 25, horizontal: 25),
      title: FText(
        i18nBook.remedical.share.t,
        style: TextStyle(
          color: Colors.white,
          fontSize: 18,
        ),
      ),
      okString: i18nBook.common.confirm4Btn.t,
      onClose: () {
        router.back();
      },
      cancelString: i18nBook.common.cancel.t,
      insetPadding: EdgeInsets.symmetric(vertical: 100),
      children: [
        _buildQrCode(),
      ],
      isDefault: false,
    );
  }

  FWidget _buildQrCode() {
    return FColumn(
      children: [
        FContainer(
          width: 360,
          child: FContainer(
            padding: const EdgeInsets.only(top: 20, bottom: 20),
            child: QRCodeWithLogo(
              link,
              codeStatement: i18nBook.remedical.scanQrCodeToShare.t,
              operationStatement: i18nBook.remedical.copyLink.t,
              operationSuccessCallback: () {
                if (FPlatform.isWindows || FPlatform.isMacOS) {
                  rpc.platform.copyToClipboard(link);
                }
                PromptBox.toast(i18nBook.remedical.copySuccess.t);
              },
            ),
          ),
        ),
      ],
    );
  }
}
