import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/constants/constants.dart';
import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart';
import 'package:sk_base_mobile/store/auth.store.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
import 'package:sk_base_mobile/widgets/core/zt_base_date_picker.dart';

class CustomAppBar extends StatelessWidget {
  CustomAppBar({super.key});
  final controller = Get.put(InventoryInoutController());
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: ScreenAdaper.width(30)),
      child: Row(
        children: [
          if (ScreenAdaper.isLandspace()) const Spacer(),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                TextEnum.homeWelcomeText,
                style: Theme.of(context).textTheme.titleMedium!.copyWith(
                    color: Colors.black87,
                    fontWeight: FontWeight.w400,
                    height: 0,
                    letterSpacing: 2,
                    fontSize: ScreenAdaper.sp(25)),
              ),
              Obx(
                () => Text(
                  AuthStore.to.userInfo.value.username ?? '',
                  style: Theme.of(context).textTheme.titleMedium!.copyWith(
                      color: Colors.black,
                      fontWeight: FontWeight.bold,
                      letterSpacing: 2,
                      height: 0,
                      fontSize: ScreenAdaper.sp(30)),
                ),
              )
            ],
          ),
          const Spacer(
            flex: 10,
          ),
          buildDatePicker(),
          if (ScreenAdaper.isLandspace()) const Spacer(),
        ],
      ),
    );
  }

  Widget buildDatePicker() {
    return InkWell(
      onTap: () async {
        showCupertinoModalPopup(
          context: Get.overlayContext!,
          builder: (BuildContext context) {
            return ZtBaseDatePicker();
          },
        );
        // showCupertinoModalPopup(
        //   context: Get.overlayContext!,
        //   builder: (BuildContext context) {
        //     return Container(
        //       height: 200,
        //       color: Colors.white,
        //       child: CupertinoDatePicker(
        //         mode: CupertinoDatePickerMode.date,
        //         initialDateTime: DateTime.now(),
        //         onDateTimeChanged: (DateTime newDateTime) {
        //           // 处理用户选择的日期
        //         },
        //       ),
        //     );
        //   },
        // );
        // final picker = await CupertinoDatePicker(
        //     context: Get.overlayContext!,
        //     initialDate: DateTime.now(),
        //     helpText: '选择的日期',
        //     confirmText: '确定',
        //     cancelText: '取消',
        //     firstDate: DateTime(2000, 1, 1),
        //     lastDate: DateTime.now().add(const Duration(days: 7)));
      },
      child: Container(
        height: ScreenAdaper.height(70),
        width: ScreenAdaper.width(70),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20),
            color: AppTheme.primaryColorLight,
            gradient: LinearGradient(colors: [
              AppTheme.primaryColorLight,
              AppTheme.primaryColor,
            ]),
            boxShadow: [
              BoxShadow(
                  color: AppTheme.primaryColor,
                  blurRadius: ScreenAdaper.sp(20),
                  offset: Offset(0, ScreenAdaper.height(10)))
            ]),
        child: Icon(
          Icons.calendar_month_outlined,
          size: ScreenAdaper.sp(40),
          color: Colors.white,
        ),
      ),
    );
  }
}
