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 EditRankDialogPage extends FStatefulWidget {
  EditRankDialogPage({
    Key? key,
    this.isEdit = false,
    this.onOkTap,
  }) : super(key: key);

  /// 是否是编辑职称
  final bool? isEdit;

  /// 确认按钮
  final ValueCallback<bool>? onOkTap;
  @override
  FState<EditRankDialogPage> createState() => _EditRankDialogState();
}

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

///编辑职称弹窗
class _BuildEditRankDialog extends FisView<OrgPesonnelController> {
  _BuildEditRankDialog({
    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.workTitleName.t,
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                  const FSizedBox(
                    height: 6,
                  ),
                ],
              ),
              const FSizedBox(
                width: 10,
              ),
              FBorderInput(
                contentSize: 16,
                maxLength: 20,
                borderColor: Color.fromRGBO(230, 230, 230, 1),
                height: 38,
                onChanged: (value) => controller.professionalName = value,
                controller: TextEditingController(
                  text: controller.professionalName,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
