/*
 * @Author: ChenYaJin
 * @Date: 2021-11-04 18:01:26
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2021-11-26 17:30:05
 * @Description: 
 */
part of '../index.dart';

class _BottomConsultComponent extends StatefulWidget {
  _BottomConsultComponent({Key? key}) : super(key: key);

  @override
  __BottomConsultComponentState createState() =>
      __BottomConsultComponentState();
}

class __BottomConsultComponentState extends State<_BottomConsultComponent> {
  final modalformKey = GlobalKey<FormState>();
  FocusNode? myFocusNode;
  TextEditingController? _selectionController = TextEditingController();

  @override
  void initState() {
    super.initState();

    myFocusNode = FocusNode();
  }

  @override
  void dispose() {
    // Clean up the focus node when the Form is disposed.
    myFocusNode!.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    RepairDetailStore _store = Provider.of<RepairDetailStore>(context);
    if (_store.repairDetail?.status == 'accept' ||
        _store.repairDetail?.status == 'hangUp')
      return BottomAppBar(
        elevation: 0,
        color: Color(0xFFF8F8F8),
        child: Wisdom.row(
          height: 54.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          children: <Widget>[
            Wisdom(
              onTap: () => _store.onTakePic(),
              child: Icon(
                Icons.camera_alt,
                color: Color(0xff888888),
                size: 32.pt,
              ),
            ),
            Wisdom(
              margin: EdgeInsets.symmetric(horizontal: 8.pt, vertical: 5.pt),
              borderRadius: BorderRadius.circular(8.pt),
              color: Colors.white,
              child: Form(
                key: modalformKey,
                child: TextFormField(
                  controller: _selectionController,
                  maxLength: 150,
                  focusNode: myFocusNode,
                  onChanged: (v) => {
                    // _selectionController!.text = v,
                    _selectionController!.selection =
                        TextSelection.fromPosition(TextPosition(
                            offset: _selectionController!.text.length)),
                    setState(() {}),
                    _store.inputDialog(v),
                  },
                  validator: (value) {
                    if (value == null || value == '') {
                      return '内容不能为空';
                    } else {
                      return null;
                    }
                  },
                  decoration: InputDecoration(
                    filled: true,
                    fillColor: Color(0xfff7f7f7),
                    counterText: '',
                    hintText: '内容至多输入150字',
                  ),
                ),
              ),
            ).asExpanded(),
            Wisdom(
              onTap: () => {
                _store.sendDialogText(),
                _selectionController!.text = '',
              },
              child: Image.asset(
                'lib/assets/send.png',
                height: 28.pt,
                width: 28.pt,
                package: 'repair_package',
              ),
            ),
          ],
        ),
      );
    else if (_store.repairDetail?.status == 'solve' ||
        _store.repairDetail?.status == 'evaluate')
      return BottomAppBar(
        elevation: 0,
        color: Color(0xFFF8F8F8),
        child: Wisdom(
            alignment: Alignment.center,
            height: 30.pt,
            child: Text(
              '当前事项${_store.repairDetail?.statusName}，沟通渠道已关闭',
              style: TextStyle(
                color: Colors.grey,
                fontSize: 12.pt,
              ),
            )),
      );
    else {
      return Wisdom(
        height: 0.pt,
      );
    }
  }
}
