import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/chicken.dart';
import 'package:rasadyar_chicken/data/models/response/steward_free_bar_dashboard/steward_free_bar_dashboard.dart';
import 'package:rasadyar_core/core.dart';

import 'logic.dart';

class OutOfProvincePage extends GetView<OutOfProvinceLogic> {
  OutOfProvincePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.bgLight,
      appBar: RAppBar(
        title: 'رصدطیور',
        iconTitle: Assets.vec.chickenSvg.path,
        titleTextStyle: AppFonts.yekan16Bold.copyWith(color: Colors.white),
        centerTitle: true,
        hasBack: false,
        leadingWidth: 130,
        leading: Row(
          mainAxisSize: MainAxisSize.min,
          spacing: 6,
          children: [
            Assets.vec.cubeSearchSvg.svg(
              width: 24,
              height: 24,
              colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
            ),
            Text('خارج استان', style: AppFonts.yekan16Bold.copyWith(color: Colors.white)),
          ],
        ),
      ),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              spacing: 8,
              children: [
                Expanded(
                  child: _typeOuterInfoCard(
                    title: 'خرید',
                    iconPath: Assets.vec.cubeBottomRotationSvg.path,
                    foregroundColor: AppColor.blueNormal,
                    onTap: () {
                      Get.toNamed(ChickenRoutes.buysOutOfProvince, id: 1);
                    },
                  ),
                ),
                Expanded(
                  child: _typeOuterInfoCard(
                    title: 'فروش',
                    iconPath: Assets.vec.cubeTopRotationSvg.path,
                    foregroundColor: AppColor.greenDark,
                    onTap: () {
                      iLog('فروش');
                      Get.toNamed(ChickenRoutes.salesOutOfProvince, id: 1);
                    },
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget addSaleOutOfTheProvinceBottomSheet() {
    return BaseBottomSheet(
      child: Column(
        children: [
          const SizedBox(height: 20),
          Align(
            alignment: Alignment.centerRight,
            child: Text('ثبت فروش خارج استان', style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal)),
          ),
          SizedBox(height: 4),
          RElevated(text: 'ثبت توزیع/ فروش', onPressed: () {}),
        ],
      ),
    );
  }

  Widget _typeOuterInfoCard({
    required String title,
    required String iconPath,
    required Color foregroundColor,
    VoidCallback? onTap,
  }) {
    return InkWell(
      onTap: onTap,
      child: Container(
        height: 180,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8),
          border: Border.all(width: 1, color: foregroundColor),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Stack(
              clipBehavior: Clip.none,
              alignment: Alignment.center,
              children: [
                Positioned(
                  top: -41,
                  child: SvgGenImage.vec(
                    iconPath,
                  ).svg(width: 45, height: 45, colorFilter: ColorFilter.mode(foregroundColor, BlendMode.srcIn)),
                ),

                Assets.vec.shoppingBasketSvg.svg(
                  width: 55,
                  height: 60,
                  colorFilter: ColorFilter.mode(foregroundColor, BlendMode.srcIn),
                  fit: BoxFit.cover,
                ),
              ],
            ),
            const SizedBox(height: 15),

            Text(
              title,
              textAlign: TextAlign.right,
              style: AppFonts.yekan16Bold.copyWith(color: foregroundColor),
            ),
          ],
        ),
      ),
    );
  }

  Widget summaryOfInformation(StewardFreeBarDashboard? model) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8),
          child: Row(
            children: [Text('خلاصه اطلاعات', style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal))],
          ),
        ),
        Container(
          height: 140,
          margin: const EdgeInsets.all(8),
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8),
            border: Border.all(color: AppColor.blueNormal, width: 1),
          ),
          child: model == null
              ? const Center(child: CircularProgressIndicator())
              : Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  spacing: 10,
                  children: [
                    const SizedBox(height: 12),
                    buildRow('تعداد کل بارها', model.totalQuantity?.toString() ?? '0'),
                    buildRow('تعداد کل', model.totalBars?.toString() ?? '0'),
                    buildRow('وزن کل (کیلوگرم)', model.totalWeight?.toString() ?? '0'),
                  ],
                ),
        ),
      ],
    );
  }

  Widget buildRow(String title, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Flexible(
            flex: 2,
            child: Text(
              title,
              textAlign: TextAlign.right,
              style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
            ),
          ),
          Flexible(
            flex: 2,
            child: Text(
              value,
              textAlign: TextAlign.left,
              style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
            ),
          ),
        ],
      ),
    );
  }
}
