import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/presentation/utils/color_utils.dart';
import 'package:rasadyar_core/presentation/widget/tabs/new_tab.dart';
import 'logic.dart';

class LocationDetailsPage extends GetView<LocationDetailsLogic> {
  const LocationDetailsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.lightGreyLight,
      appBar: RAppBar(title: 'جزئیات محل'),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 22),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                headerInfo(description: 'ایداگل محمدی', title: 'نام مالک'),

                headerInfo(
                  description: '09415115545',
                  title: 'شماره همراه',
                  background: AppColor.green1Light,
                ),

                headerInfo(description: '183کیلوگرم', title: 'موجودی'),
              ],
            ),
          ),

          Padding(
            padding: const EdgeInsets.fromLTRB(22, 13, 22, 4),
            child: Text(
              'نوع دریافت',
              textAlign: TextAlign.center,
              style: AppFonts.yekan13.copyWith(color: AppColor.blueNormal),
            ),
          ),

          ObxValue((data) {
            return NewCupertinoSegmentedControl<int>(
              padding: EdgeInsetsDirectional.symmetric(
                horizontal: 20,
                vertical: 10,
              ),
              children: controller.segments,
              groupValue: data.value,
              selectedColor: AppColor.blueNormal,
              unselectedColor: Colors.white,
              borderColor: Colors.grey.shade300,
              onValueChanged: (int value) {
                data.value = value;
              },
            );
          }, controller.selectedSegment),
          Container(
            height: 32,
            margin: EdgeInsets.only(top: 10, left: 22, right: 22),

            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              spacing: 10,
              children: [
                Expanded(
                  child: ROutlinedElevatedIcon(
                    icon: FaIcon(FontAwesomeIcons.calendar),
                    onPressed:() async {

                      Jalali? picked = await showPersianDatePicker(
                        context: context,
                        initialDate: Jalali.now(),
                        firstDate: Jalali(1385, 8),
                        lastDate: Jalali(1450, 9),

                        initialEntryMode:
                        PersianDatePickerEntryMode.calendarOnly,
                        initialDatePickerMode: PersianDatePickerMode.day,
                      );
                    },
                    text: 'از تاریخ',
                    textStyle: AppFonts.yekan16.copyWith(
                      color: AppColor.blueNormal,
                    ),
                  ),
                ),
                Expanded(
                  child: ROutlinedElevatedIcon(
                    icon: FaIcon(FontAwesomeIcons.calendar),
                    onPressed: () async {

                      Jalali? picked = await showPersianDatePicker(
                        context: context,
                        initialDate: Jalali.now(),
                        firstDate: Jalali(1385, 8),
                        lastDate: Jalali(1450, 9),

                        initialEntryMode:
                        PersianDatePickerEntryMode.calendarOnly,
                        initialDatePickerMode: PersianDatePickerMode.day,
                      );
                    },
                    text: 'تا تاریخ',
                    textStyle: AppFonts.yekan16.copyWith(
                      color: AppColor.blueNormal,
                    ),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(height: 20),
          Row(
            children: [
              Expanded(child: Divider()),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 10, vertical: 6),
                margin: EdgeInsets.symmetric(horizontal: 2),
                clipBehavior: Clip.antiAlias,
                decoration: ShapeDecoration(
                  color: AppColor.blueNormal.disabledColor,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(60),
                  ),
                ),
                child: Text(
                  'تعداد کل تراکنش ها : 0',
                  textAlign: TextAlign.center,
                  style: AppFonts.yekan10,
                ),
              ),
              Expanded(child: Divider()),
            ],
          ),

          Expanded(
            child: GridView.builder(
              itemCount: 51,
              physics: BouncingScrollPhysics(),
              padding: EdgeInsets.fromLTRB(20, 14, 20, 50),
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: 8,
                mainAxisSpacing: 8,
              ),
              itemBuilder:
                  (context, index) => Container(
                    clipBehavior: Clip.antiAlias,
                    decoration: ShapeDecoration(
                      color: Colors.white,
                      shape: RoundedRectangleBorder(
                        side: BorderSide(
                          width: 1,
                          color: const Color(0xFFEFEFEF),
                        ),
                        borderRadius: BorderRadius.circular(16),
                      ),
                    ),
                    child: Padding(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 22,
                        vertical: 21,
                      ),
                      child: Column(
                        spacing: 6,
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            '${index + 1}- تراکنش موفق',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan10,
                          ),
                          SizedBox(height: 2),
                          Text(
                            '1403/12/12',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan12,
                          ),

                          Text(
                            'محصول : مرغ',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan12.copyWith(
                              color: AppColor.lightGreyNormalActive,
                            ),
                          ),
                          Text(
                            'وزن : 5555 گرم',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan12.copyWith(
                              color: AppColor.lightGreyNormalActive,
                            ),
                          ),
                          Text(
                            'مبلغ : 14،000،000',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan12.copyWith(
                              color: AppColor.lightGreyNormalActive,
                            ),
                          ),

                          Text(
                            'سرویس سامان کیش',
                            textAlign: TextAlign.center,
                            style: AppFonts.yekan12.copyWith(
                              color: AppColor.blueNormal,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
            ),
          ),
        ],
      ),
    );
  }

  Container headerInfo({
    required String title,
    required String description,
    Color? background,
  }) {
    return Container(
      clipBehavior: Clip.antiAlias,
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      decoration: ShapeDecoration(
        color: background ?? AppColor.blueLight,
        shape: RoundedRectangleBorder(
          side: BorderSide(width: 1, color: AppColor.blackLightHover),
          borderRadius: BorderRadius.circular(8),
        ),
      ),
      alignment: AlignmentDirectional.center,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        spacing: 10,
        children: [
          Text(title, style: AppFonts.yekan10),

          Text(description, style: AppFonts.yekan12),
        ],
      ),
    );
  }
}
