import 'package:fis_ui/index.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/material.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:flyinsono/architecture/router/router.dart';
import 'package:fis_measure/process/workspace/rpc_bridge.dart';
import 'package:flyinsono/architecture/router/desktop/names.dart';
import 'package:flyinsono/pages/remedical/report/report_edit/index.dart';
import 'package:flyinsono/pages/remedical/translation_delegate_helper.dart';

/// 移动端图片预览块
class ImagePreviewMobile extends FStatelessWidget implements FPage {
  final int index;
  final String? application;
  final String? patientCode;
  final bool isCanCreateReport;
  final TerminalImage image;
  final String remedicalCode;
  final RemedicalInfoDTO remedicalInfo;

  ImagePreviewMobile({
    required this.image,
    required this.index,
    required this.remedicalCode,
    required this.remedicalInfo,
    this.application,
    this.patientCode,
    this.isCanCreateReport = false,
  });

  @override
  final String pageName = "ImagePreviewMobile";

  @override
  FWidget build(BuildContext context) {
    final imageUrlMap = image.imageUrl ?? '';
    return FGestureDetector(
      businessParent: this,
      name: "selectImage",
      onTap: () {
        routerToVidPlayer(
          index,
          remedicalCode,
        );
      },
      child: FContainer(
        color: Colors.black,
        child: FCenter(
          child: FFittedBox(
            fit: BoxFit.scaleDown,
            child: imageUrlMap.isEmpty
                ? FSizedBox()
                : FContentImage(
                    remedicalInfo: remedicalInfo,
                    onDoubleTap: () => routerToVidPlayer(
                      index,
                      remedicalCode,
                    ),
                    onTap: () => routerToVidPlayer(
                      index,
                      remedicalCode,
                    ),
                    ifShowIndex: false,
                    locationDescription: translation_delegate_helper
                        .translateLocationDescription(
                      remedicalInfo.imageLocation?.quadrant,
                      remedicalInfo.imageLocation?.position,
                    ),
                    description:
                        translation_delegate_helper.translateDescription(
                            remedicalInfo.application,
                            remedicalInfo.applicationCategory),
                  ),
          ),
        ),
      ),
    );
  }

  void routerToVidPlayer(int index, String remedicalCode) {
    RPCBridge.ins.source = VidImageSource.Remedical;
    router.to(RouteNames.Remedical.Measure, parameters: {
      "patientCode": patientCode ?? '',
      "remedicalCode": remedicalCode,
      "recordCode": remedicalInfo.recordCode ?? '',
      "isCanWriteReport": isCanCreateReport.toString(),
    });
  }
}
