import 'package:fis_i18n/i18n.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/router/router.dart';

class SetCammeraStyle extends FStatefulWidget implements FPage {
  @override
  String get pageName => "SetStyle";
  final void Function(CameraStyleEnum) onOk;

  SetCammeraStyle(this.onOk);

  @override
  FState<FStatefulWidget> createState() {
    return _SetStyleState();
  }
}

class _SetStyleState extends FState<SetCammeraStyle> {
  CameraStyleEnum _cameraStyleEnum = CameraStyleEnum.Right;
  final double _width = 272;
  final double _height = 152;
  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      onOk: () {
        widget.onOk.call(_cameraStyleEnum);
      },
      title: FText(
        i18nBook.college.styleSetting.t,
        style: TextStyle(color: Colors.white),
      ),
      isDefault: true,
      okString: i18nBook.common.confirm.t,
      cancelString: i18nBook.common.cancel.t,
      onCancel: router.back,
      onClose: router.back,
      contentPadding: EdgeInsets.all(20),
      children: [
        FContainer(
          width: 580,
          height: 500,
          alignment: Alignment.center,
          child: FColumn(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              _buildFirstLineView(),
              const FSizedBox(height: 20),
              FRow(
                children: [
                  _buildStackCamera(CameraStyleEnum.Topleft),
                  FSizedBox(
                    width: 40,
                  ),
                  _buildStackCamera(CameraStyleEnum.TopRight),
                ],
              ),
              const FSizedBox(height: 20),
              FRow(
                children: [
                  _buildStackCamera(CameraStyleEnum.BottomLeft),
                  FSizedBox(
                    width: 40,
                  ),
                  _buildStackCamera(CameraStyleEnum.BottomRight),
                ],
              ),
            ],
          ),
        )
      ],
    );
  }

  FWidget styleWidget(FWidget child) {
    return FContainer(
      decoration: BoxDecoration(color: Colors.grey),
      child: child,
    );
  }

  FWidget _buildStackCamera(CameraStyleEnum alignment) {
    return FContainer(
      height: _height,
      width: _width,
      decoration: BoxDecoration(
          border: Border.all(
              color: _cameraStyleEnum == alignment
                  ? FTheme.ins.colorScheme.primary
                  : Colors.grey)),
      child: FMouseRegion(
        cursor: SystemMouseCursors.click,
        child: FGestureDetector(
          businessParent: widget,
          name: alignment.name,
          onTap: () {
            setState(() {
              _cameraStyleEnum = alignment;
            });
          },
          child: FStack(
            children: [
              FRow(
                children: [
                  FContainer(
                    alignment: Alignment.center,
                    width: _width - 92,
                    height: _height - 2,
                    color: Colors.grey,
                    child: FText("电脑桌面/超声机"),
                  ),
                  FContainer(
                    width: 90,
                    height: _height,
                    color: Colors.white,
                  ),
                ],
              ),
              FPositioned(
                top: (alignment == CameraStyleEnum.TopRight ||
                        alignment == CameraStyleEnum.Topleft)
                    ? 0
                    : null,
                bottom: (alignment == CameraStyleEnum.BottomLeft ||
                        alignment == CameraStyleEnum.BottomRight)
                    ? 0
                    : null,
                left: (alignment == CameraStyleEnum.BottomLeft ||
                        alignment == CameraStyleEnum.Topleft)
                    ? 0
                    : null,
                right: (alignment == CameraStyleEnum.TopRight ||
                        alignment == CameraStyleEnum.BottomRight)
                    ? 90
                    : null,
                child: FContainer(
                  height: 35,
                  width: 90,
                  alignment: Alignment.center,
                  color: FTheme.ins.colorScheme.primary,
                  child: FText(i18nBook.college.camera.t),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  FWidget _buildTopCameraView() {
    return FColumn(
      children: [
        FContainer(
          height: 35,
          width: 90,
          alignment: Alignment.center,
          color: FTheme.ins.colorScheme.primary,
          child: FText(i18nBook.college.camera.t),
        ),
        FContainer(
          height: 115,
          width: 90,
          color: Colors.white,
        ),
      ],
    );
  }

  FWidget _buildFirstLineView() {
    return FRow(
      children: [
        FContainer(
            width: _width,
            height: _height,
            decoration: BoxDecoration(
              color: Colors.grey,
              border: Border.all(
                color: _cameraStyleEnum == CameraStyleEnum.Right
                    ? FTheme.ins.colorScheme.primary
                    : Colors.grey,
              ),
            ),
            child: FMouseRegion(
              cursor: SystemMouseCursors.click,
              child: FGestureDetector(
                businessParent: widget,
                name: '',
                onTap: () {
                  setState(() {
                    _cameraStyleEnum = CameraStyleEnum.Right;
                  });
                },
                child: FRow(
                  children: [
                    FContainer(
                      width: 180,
                      height: 150,
                      alignment: Alignment.center,
                      child:
                          FText(i18nBook.college.computerDesktopUltrasound.t),
                    ),
                    _buildTopCameraView(),
                  ],
                ),
              ),
            )),
        FSizedBox(
          width: 40,
        ),
        FMouseRegion(
          cursor: SystemMouseCursors.click,
          child: FGestureDetector(
            businessParent: widget,
            name: '',
            onTap: () {
              setState(() {
                _cameraStyleEnum = CameraStyleEnum.Left;
              });
            },
            child: FContainer(
              width: _width,
              height: _height,
              decoration: BoxDecoration(
                color: Colors.grey,
                border: Border.all(
                  color: _cameraStyleEnum == CameraStyleEnum.Left
                      ? FTheme.ins.colorScheme.primary
                      : Colors.grey,
                ),
              ),
              child: FRow(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  _buildTopCameraView(),
                  FContainer(
                    width: 180,
                    height: 150,
                    alignment: Alignment.center,
                    child: FText(i18nBook.college.computerDesktopUltrasound.t),
                  ),
                ],
              ),
            ),
          ),
        ),
      ],
    );
  }
}

enum CameraStyleEnum {
  Right,
  Left,
  TopRight,
  BottomRight,
  Topleft,
  BottomLeft,
}
