import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/presentation/pages/sales_out_of_province_buyers/view.dart';
import 'package:rasadyar_chicken/presentation/pages/sales_out_of_province_sales_list/view.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/filter_bottom_sheet.dart';
import 'package:rasadyar_chicken/presentation/widget/inventory_widget.dart';
import 'package:rasadyar_chicken/presentation/widget/page_route.dart';
import 'package:rasadyar_core/core.dart';

import 'logic.dart';

class SalesOutOfProvincePage extends GetView<SalesOutOfProvinceLogic> {
  const SalesOutOfProvincePage({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      routesWidget: ObxValue((route) => buildPageRoute(route), controller.routesName),
      onBackPressed: () => Get.back(id: 1),
      onSearchChanged: (data) => controller.setSearchValue(data),
      filteringWidget: filterBottomSheet(),
      widgets: [
        inventoryWidget(controller.rootLogic),
        segmentWidget(),
        Expanded(
          child: ObxValue((index) {
            return index.value == 0
                ? SalesOutOfProvinceSalesListPage()
                : SalesOutOfProvinceBuyersPage();
          }, controller.selectedSegmentIndex),
        ),
      ],
    );
  }

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

  Widget filterBottomSheet() => filterBottomSheetWidget(
    fromDate: controller.fromDateFilter,
    onChangedFromDate: (jalali) => controller.fromDateFilter.value = jalali,
    toDate: controller.toDateFilter,
    onChangedToDate: (jalali) => controller.toDateFilter.value = jalali,
    onSubmit: () => controller.submitFilter(),
  );

}
