import 'package:track_common/widget/prelude.dart';

class LogoWidget extends StatelessWidget {
  const LogoWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const SizedBox(height: 60),
          Image.asset(Assets.imagesIcLoginLogo, package: package, height: 54),
          const SizedBox(
            height: 23,
          )
        ],
      ),
    );
  }
}

class TextDecoration extends InputDecoration {
  const TextDecoration({required String hintText})
      : super(
          hintText: hintText,
          border: const OutlineInputBorder(),
          isDense: true,
        );
}

class GetCodeButton extends StatelessWidget {
  final Duration codeRetryLeft;
  final VoidCallback onPressed;

  const GetCodeButton(
      {super.key, required this.codeRetryLeft, required this.onPressed});

  @override
  Widget build(BuildContext context) {
    final isEnable = codeRetryLeft.inSeconds <= 0;
    final onPressed = isEnable ? this.onPressed : () {};

    final bkColor =
        isEnable ? const Color(0xff19be30) : const Color(0xffc2c2c2);
    final foregroundColor = isEnable ? Colors.white : Colors.white;
    final text = isEnable ? '获取验证码' : '请稍后(${codeRetryLeft.inSeconds})';

    return ElevatedButton(
        onPressed: onPressed,
        style: ElevatedButton.styleFrom(
            backgroundColor: bkColor,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(2.0)),
            foregroundColor: foregroundColor,
            padding: EdgeInsets.zero),
        child: Text(text));
  }
}

class SignInButton extends StatelessWidget {
  final double? height;
  final double? width;
  final VoidCallback? onPressed;
  final Widget? child;
  final Color color1;
  final Color color2;

  const SignInButton({
    super.key,
    required this.onPressed,
    required this.child,
    required this.color1,
    required this.color2,
    this.width,
    this.height,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onPressed,
        child: Container(
          height: height,
          width: width,
          alignment: Alignment.center,
          decoration: BoxDecoration(
              gradient: LinearGradient(colors: [
                color1,
                color2,
              ]),
              borderRadius: BorderRadius.circular(6.0)),
          child: child,
        ));
  }
}
