import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/presentation/pages/steward/buy_in_province_all/view.dart';
import 'package:rasadyar_chicken/presentation/pages/steward/buy_in_province_waiting/view.dart';
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/steward/inventory_widget.dart';
import 'package:rasadyar_core/core.dart';

import 'logic.dart';

class BuyInProvincePage extends GetView<BuyInProvinceLogic> {
  const BuyInProvincePage({super.key});

  @override
  Widget build(BuildContext context) {
    return ChickenBasePage(
      routesWidget: ContainerBreadcrumb(rxRoutes: controller.routesName),
      onSearchChanged: (data) => controller.setSearchValue(data),
      hasBack: true,
      backId: stewardFirstKey,

      onFilterTap: () {
        Get.bottomSheet(filterBottomSheet());
      },
        onRefresh: controller.onRefresh,
      child: Column(
        children: [
          inventoryWidget(controller.rootLogic),
          segmentWidget(),
          ObxValue((index) {
            return Expanded(
              child: index.value == 0 ? BuyInProvinceWaitingPage() : BuyInProvinceAllPage(),
            );
          }, controller.selectedSegmentIndex),
        ],
      )
    );
  }

  Padding segmentWidget() {
    return Padding(
      padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
      child: Row(
        children: [
          Expanded(
            child: RSegment(
              children: ['در انتظار', 'کل خریدها'],
              selectedIndex: 0,
              borderColor: const Color(0xFFB4B4B4),
              selectedBorderColor: AppColor.blueNormal,
              selectedBackgroundColor: AppColor.blueLight,
              onSegmentSelected: (index) => controller.selectedSegmentIndex.value = index,
              backgroundColor: AppColor.whiteGreyNormal,
            ),
          ),
        ],
      ),
    );
  }

  Widget filterBottomSheet() {
    return BaseBottomSheet(
      height: 200,
      child: Column(
        spacing: 16,
        children: [
          Text('فیلترها', style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal)),
          Row(
            spacing: 8,
            children: [
              Expanded(
                child: dateFilterWidget(
                  date: controller.fromDateFilter,
                  onChanged: (jalali) => controller.fromDateFilter.value = jalali,
                ),
              ),
              Expanded(
                child: dateFilterWidget(
                  isFrom: false,
                  date: controller.toDateFilter,
                  onChanged: (jalali) => controller.toDateFilter.value = jalali,
                ),
              ),
            ],
          ),

          RElevated(
            text: 'اعمال فیلتر',

            isFullWidth: true,
            backgroundColor: AppColor.greenNormal,
            onPressed: () {
              controller.submitFilter();
              Get.back();
            },
            height: 40,
          ),
          SizedBox(height: 16),
        ],
      ),
    );
  }
}
