import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/material.dart';
import 'package:fis_jsonrpc/services/index.dart';
import 'package:fis_theme/theme.dart';

class MobileTitleView extends FStatefulWidget implements FPage {
  final RecordProcessStateEnum recordProcessState;
  final void Function(RecordProcessStateEnum) onPressed;
  final FWidget? searchInput;
  MobileTitleView({
    required this.recordProcessState,
    required this.onPressed,
    this.searchInput,
  });
  @override
  FState<FStatefulWidget> createState() {
    return MobileTitleViewState();
  }

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

class MobileTitleViewState extends FState<MobileTitleView> {
  RecordProcessStateEnum _recordProcessState = RecordProcessStateEnum.All;

  @override
  void initState() {
    _recordProcessState = widget.recordProcessState;
    super.initState();
  }

  @override
  void didUpdateWidget(MobileTitleView oldWidget) {
    if (_recordProcessState != widget.recordProcessState) {
      setState(() {
        _recordProcessState = widget.recordProcessState;
      });
    }
    super.didUpdateWidget(oldWidget);
  }

  @override
  FWidget build(BuildContext context) {
    var source = <FSelectOptionModel<RecordProcessStateEnum>>[
      FSelectOptionModel(
        title: i18nBook.remedical.pending.t,
        value: RecordProcessStateEnum.Wait,
      ),
      FSelectOptionModel(
        title: i18nBook.remedical.completed.t,
        value: RecordProcessStateEnum.Done,
      ),
      FSelectOptionModel(
        title: i18nBook.remedical.transferredOut.t,
        value: RecordProcessStateEnum.ReferralOut,
      ),
    ];
    return FColumn(
      children: [
        FSelect(
          source: source,
          fontFamily: FTheme.ins.localeSetting.fontFamily,
          value: _recordProcessState,
          optionAlignment: Alignment.center,
          width: i18nBook.isCurrentChinese
              ? 100
              : i18nBook.isCurrentRussian
                  ? 180
                  : 200,
          decoration: BoxDecoration(
              border: Border.all(width: 0, color: Colors.transparent)),
          optionValueExtractor: (data) => data.value,
          optionLabelExtractor: (data) => data.title,
          textColor: Colors.black,
          onSelectChanged: (value, index) {
            widget.onPressed.call(value!);
          },
        ),
        if (widget.searchInput != null) ...[
          widget.searchInput!,
        ],
      ],
    );
  }
}
