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

class ShareDialog extends FStatelessWidget implements FPage {
  final String url;

  ShareDialog(this.url);

  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      titlePadding: kIsMobile
          ? EdgeInsets.symmetric(vertical: 0)
          : EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 12.0),
      insetPadding: kIsMobile
          ? EdgeInsets.symmetric(vertical: 0)
          : EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
      isDefault: false,
      okString: i18nBook.common.confirm.t,
      cancelString: i18nBook.common.cancel.t,
      onClose: router.back,
      contentPadding: kIsMobile ? EdgeInsets.all(20) : EdgeInsets.all(20),
      title: FText(
        i18nBook.remedical.share.t,
        style: TextStyle(color: Colors.white),
      ),
      children: [
        FColumn(
          children: [
            FContainer(
              width: kIsMobile ? 250 : 360,
              child: FContainer(
                padding: kIsMobile
                    ? const EdgeInsets.only(top: 5, bottom: 5)
                    : const EdgeInsets.only(top: 20, bottom: 20),
                child: QRCodeWithLogo(
                  url,
                  codeStatement: i18nBook.remedical.scanQrCodeToShare.t,
                  operationStatement: i18nBook.remedical.copyLink.t,
                  operationSuccessCallback: () {
                    if (FPlatform.isWindows || FPlatform.isMacOS) {
                      rpc.platform.copyToClipboard(url);
                    } else {
                      Clipboard.setData(ClipboardData(text: url));
                    }
                    PromptBox.toast(i18nBook.remedical.copySuccess.t);
                  },
                ),
              ),
            ),
            FSizedBox(height: kIsMobile ? 0 : 10),
            _buildCancelButton(),
          ],
        ),
      ],
    );
  }

  ///取消按钮
  FWidget _buildCancelButton() {
    if (kIsMobile) {
      return FSizedBox();
    }
    return FBottomCanCelButton(
      businessParent: this,
      name: "cancel",
      radius: 4,
      height: 35,
      onPressed: router.back,
      title: i18nBook.common.cancel.t,
    );
  }

  @override
  String get pageName => "ShareDialog";
}
