import 'package:common_pub/common_pub.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:track_offical/generated/assets.dart';

class AppTopBar extends StatelessWidget implements PreferredSizeWidget {
  const AppTopBar(
      {super.key,
      required this.title,
      required this.hasBackText,
      required this.height});

  final double height;
  final String title;
  final bool hasBackText;

  Widget bkText(
    String text,
    double fontSizeRpx,
    double alpha,
    BuildContext context,
    double xP,
    double yP,
  ) {
    return Positioned(
        left: context.width * xP,
        top: height * yP,
        child: Text(text,
            style: TextStyle(
              color: const Color(0xFFade0ff).withAlpha((alpha * 255).round()),
              fontWeight: FontWeight.w500,
              fontSize:  context.wp(fontSizeRpx),
            )));
  }

  @override
  Widget build(BuildContext context) {
    final children = <Widget>[];
    if (hasBackText) {
      children.addAll([
        bkText('Orienting', 47.92, 0.6, context, 0.1, 0.2),
        bkText('定目标', 37.5, 0.58, context, 0.7, 0.18),
        bkText('Targeting', 56.25, 0.2, context, 0.52, 0.26),
        bkText('定向', 54.17, 0.6, context, 0.3, 0.33),
        bkText('定位', 31.25, 0.5, context, 0.08, 0.4),
        bkText('Locating', 45.83, 0.4, context, 0.12, 0.52),
        bkText('到达目标', 37.5, 0.5, context, 0.53, 0.48),
        bkText('Reaching', 33.33, 0.5, context, 0.6, 0.6),
      ]);
    }

    children.add(Positioned(
        left: context.wp(54.17),
        bottom: context.wp(58.33),
        child: Text(title,
            style: TextStyle(
              color: Colors.white,
              fontSize: context.wp(58.33),
              fontWeight: FontWeight.w400,
            ))));

    return Container(
      width: double.infinity,
      height: height,
      decoration: const BoxDecoration(
          image: DecorationImage(
              image: AssetImage(Assets.imagesBkLogin),
              alignment: Alignment.topCenter,
              fit: BoxFit.fitWidth)),
      child: Stack(
        children: children,
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(height);
}

Widget button(BuildContext context ,String text, VoidCallback onPressed) {
  return SizedBox(
      width: double.infinity,
      height: context.wp(3.19),
      child: FilledButton(
        style: FilledButton.styleFrom(
            backgroundColor: const Color(0xffffb40b),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(context.wp(0.42)))
        ),
          onPressed: onPressed,
          child: Text(
            text,
            style: const TextStyle(color: Colors.black, fontSize: 15),
          )));
}

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(0xffefefef): const Color(0xffc2c2c2);
    final foregroundColor = isEnable? Colors.black: 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));
  }

}
