import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/router.dart';
import 'package:flyinsono/pages/organization/org_personnel/controller.dart';

class OrgStrutureDialogPage extends FStatefulWidget {
  OrgStrutureDialogPage({
    Key? key,
    this.isEdit = false,
    this.onOkTap,
  }) : super(key: key);

  /// 是否是编辑组织架构
  final bool? isEdit;

  /// 编辑和新建组织架构使用不同方法
  final ValueCallback<bool>? onOkTap;
  @override
  FState<OrgStrutureDialogPage> createState() => _OrgStrutureDialogState();
}

class _OrgStrutureDialogState extends FState<OrgStrutureDialogPage> {
  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      backgroundColor: Colors.white,
      title: FText(
        widget.isEdit!
            ? i18nBook.organization.editOrgStructure.t
            : i18nBook.organization.addOrgStructure.t,
        style: TextStyle(
          color: Colors.white,
          fontSize: 18,
        ),
      ),
      okString: i18nBook.common.save4Btn.t,
      cancelString: i18nBook.common.cancel.t,
      children: [
        FContainer(
          alignment: Alignment.center,
          margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
          width: 500,
          child: FColumn(
            children: [
              FContainer(
                padding: EdgeInsets.symmetric(
                  horizontal: 40,
                ),
                child: _OrgStrutureDialog(
                  isEdit: widget.isEdit,
                ),
              ),
            ],
          ),
        ),
      ],
      isDefault: true,
      onOk: () {
        widget.onOkTap?.call(widget.isEdit!);
      },
      onCancel: () {
        router.back();
      },
    );
  }
}

class _OrgStrutureDialog extends FisView<OrgPesonnelController> {
  _OrgStrutureDialog({
    Key? key,
    this.isEdit = false,
  }) : super(key: key);

  ///是否为编辑状态
  final bool? isEdit;

  @override
  FWidget build(BuildContext context) {
    return FContainer(
      margin: EdgeInsets.only(top: 50, left: 40, right: 40, bottom: 30),
      child: FColumn(
        children: [
          FFlex(
            direction: Axis.horizontal,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              FColumn(
                children: [
                  FText(
                    i18nBook.organization.departmentName.t,
                    style: const TextStyle(
                      fontSize: 16,
                    ),
                  ),
                  const FSizedBox(
                    height: 6,
                  ),
                ],
              ),
              const FSizedBox(
                width: 10,
              ),
              FBorderInput(
                contentSize: 16,
                maxLength: i18nBook.isCurrentChinese ? 20 : 50,
                borderColor: Color.fromRGBO(
                  230,
                  230,
                  230,
                  1,
                ),
                height: 38,
                onChanged: (value) => controller.organizationName = value,
                controller: TextEditingController(
                  text: controller.organizationName,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
