import 'package:flutter/material.dart';
import 'package:vitalapp/components/dialog_number.dart';
import 'package:vitalapp/pages/check/models/form.dart';
import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';

// ignore: must_be_immutable
class ExamRadioScore extends StatelessWidget {
  const ExamRadioScore({
    super.key,
    required this.currentFormObject,
    required this.options,
    required this.selectRaidoChange,
    required this.currentSelected,
    required this.changeScore,
    required this.currentScore,
  });
  final FormObject currentFormObject;
  final List<Option> options;
  final Function selectRaidoChange;
  final String currentSelected;
  final Function changeScore;
  final String currentScore;

  Future<void> commonInput() async {
    String? result = await VDialogNumber(
      title: currentFormObject.label,
      initialValue: currentScore,
    ).show();
    if (result?.isNotEmpty ?? false) {
      changeScore(result);
    }
  }

  @override
  Widget build(BuildContext context) {
    return ExamCard(
      title: currentFormObject.label ?? '',
      content: Stack(
        children: [
          Container(
            padding: const EdgeInsets.symmetric(
              horizontal: 5,
            ),
            width: double.infinity,
            child: Wrap(
              children: options
                  .map(
                    (e) => Container(
                      padding: const EdgeInsets.all(8),
                      child: InkWell(
                        onTap: () => selectRaidoChange(e),
                        borderRadius: BorderRadius.circular(50),
                        child: Ink(
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: currentSelected == e.value
                                  ? Colors.blue
                                  : Colors.black26,
                            ),
                            borderRadius: const BorderRadius.all(
                              Radius.circular(50),
                            ),
                            color: currentSelected == e.value
                                ? Colors.blue
                                : Colors.transparent,
                          ),
                          child: Container(
                            padding: const EdgeInsets.all(15),
                            alignment: Alignment.center,
                            width: 250,
                            child: FittedBox(
                              child: Text(
                                e.label ?? '',
                                style: TextStyle(
                                  fontSize: 20,
                                  color: currentSelected == e.value
                                      ? Colors.white
                                      : Colors.black54,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  )
                  .toList(),
            ),
          ),
          if (currentSelected == '2')
            Positioned(
              right: 30,
              child: Container(
                child: Row(
                  children: [
                    const Text(
                      '总分:',
                      style: TextStyle(
                        fontSize: 30,
                      ),
                    ),
                    const SizedBox(
                      width: 16,
                    ),
                    SizedBox(
                      width: 100,
                      child: TextField(
                        readOnly: true,
                        controller: TextEditingController(text: currentScore),
                        style: const TextStyle(fontSize: 30),
                        onTap: () => commonInput(),
                      ),
                    )
                  ],
                ),
              ),
            )
        ],
      ),
    );
  }
}
