import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_dark_colors.dart';
import 'package:flyinsono/lab/env/env.dart';
import 'package:flyinsono/pages/setting/server_setting/view.dart';
import 'package:fis_i18n/i18n.dart';

final _labelStyle = TextStyle(
  fontSize: 16,
  color: kIsLab ? LabColorConfig.text800 : Colors.black,
);

class ProtocolSelect extends FStatefulWidget {
  final void Function(String) onChanged;

  ProtocolSelect(this.onChanged);

  @override
  FState<FStatefulWidget> createState() {
    return _ProtocolSelectState();
  }
}

class _ProtocolSelectState extends FState<ProtocolSelect> {
  String _protocol = httpsProtocol;
  @override
  FWidget build(BuildContext context) {
    return FContainer(
      alignment: Alignment.centerLeft,
      child: FRow(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          FContainer(
            height: 44,
            width: kIsMobile ? 92 : null,
            padding: EdgeInsets.only(top: 7),
            child: FText(i18nBook.auth.protocol.t, style: _labelStyle),
          ),
          FContainer(
            height: 44,
            padding: EdgeInsets.only(top: 7),
            child: FText(httpsProtocol, style: _labelStyle),
          ),
          FContainer(
            alignment: Alignment.center,
            child: FRadio(
              value: _protocol,
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              groupValue: httpsProtocol,
              onChanged: (v) {
                setState(() {
                  _protocol = httpsProtocol;
                });
                widget.onChanged.call(_protocol);
              },
            ),
          ),
          FSizedBox(width: kIsMobile ? 15 : 32),
          FContainer(
            height: 44,
            padding: EdgeInsets.only(top: 7),
            child: FText(httpProtocol, style: _labelStyle),
          ),
          FRadio(
            value: _protocol,
            groupValue: httpProtocol,
            onChanged: (v) {
              setState(() {
                _protocol = httpProtocol;
              });
              widget.onChanged.call(_protocol);
            },
          ),
        ],
      ),
    );
  }
}
