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.find<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.height(25)),
              ),
              Obx(
                () => Text(
                  AuthStore.to.userInfo.value.nickname ?? '',
                  style: Theme.of(context).textTheme.titleMedium!.copyWith(
                      color: Colors.black,
                      fontWeight: FontWeight.bold,
                      letterSpacing: 2,
                      height: 0,
                      fontSize: ScreenAdaper.height(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(
              initialDate: controller.endTime.value,
              endDate: controller.endTime.value,
              onDateTimeChanged: (date) {
                controller.setEndTime(DateTime.parse(date));
              },
            );
          },
        );
      },
      child: Container(
        height: ScreenAdaper.height(70),
        width: ScreenAdaper.height(70),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20),
            color: AppTheme.primaryColorLight,
            gradient: const 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.height(40),
          color: Colors.white,
        ),
      ),
    );
  }
}
