// ignore_for_file: sized_box_for_whitespace

import 'package:byod/helper/prefs.dart';
import 'package:flutter/material.dart';
import 'package:timeline_tile/timeline_tile.dart';

import '../../helper/helper.dart';
import '../../helper/widget/style.dart';
import '../../models/bill.dart';

class DeliveryPickupStatus extends StatelessWidget {
  const DeliveryPickupStatus({
    Key? key,
    required this.dataBill,
  }) : super(key: key);

  final List<Bill> dataBill;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      color: backgroundWhite.withOpacity(0.9),
      padding: const EdgeInsets.only(
        bottom: 10,
      ),
      // height: 134,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          (getIsCustomerDelivery())
              ? (dataBill[0].state == orderStateDone)
                  ? Container(
                      padding: const EdgeInsets.only(
                        top: 20,
                        bottom: 20,
                      ),
                      child: defaultText(
                        context,
                        'Delivery Status',
                        style: viewbillStyle(),
                      ),
                    )
                  : const SizedBox()
              : Container(
                  padding: const EdgeInsets.only(
                    top: 20,
                    bottom: 20,
                  ),
                  child: defaultText(
                    context,
                    'Pickup Status',
                    style: viewbillStyle(),
                  ),
                ),
          (getIsCustomerDelivery())
              ? (dataBill[0].state == orderStateDone)
                  ? DeliveryState(dataBill: dataBill)
                  : const SizedBox()
              : PickUpState(dataBill: dataBill)
        ],
      ),
    );
  }
}

class DeliveryState extends StatelessWidget {
  const DeliveryState({
    Key? key,
    required this.dataBill,
  }) : super(key: key);

  final List<Bill> dataBill;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            axis: TimelineAxis.horizontal,
            isFirst: true,
            endChild: defaultText(
              context,
              'Order Processing',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: const BoxDecoration(
                  color: successColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/processing_order.png'),
                  ),
                ),
                // child: ,
              ),
            ),
          ),
        ),
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            axis: TimelineAxis.horizontal,
            endChild: defaultText(
              context,
              'Looking for Driver',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              // height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  color: (dataBill[0].state == orderStateDone)
                      ? successColor
                      : disabledColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/looking_driver.png'),
                  ),
                ),
              ),
            ),
          ),
        ),
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            axis: TimelineAxis.horizontal,
            endChild: defaultText(
              context,
              'Order on the way',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              // height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  color: (dataBill[0].state == orderStateDone &&
                          (dataBill[0].deliveryState ==
                                  orderDeliveryStateInDelivery ||
                              dataBill[0].deliveryState ==
                                  orderDeliveryStateDelivered))
                      ? successColor
                      : disabledColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/otw_pickup.png'),
                  ),
                ),
              ),
            ),
          ),
        ),
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            isLast: true,
            axis: TimelineAxis.horizontal,
            endChild: defaultText(
              context,
              'Order delivered',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              // height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  color: (dataBill[0].state == orderStateDone &&
                          dataBill[0].deliveryState ==
                              orderDeliveryStateDelivered)
                      ? successColor
                      : disabledColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/order_delivered.png'),
                  ),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

class PickUpState extends StatelessWidget {
  const PickUpState({
    Key? key,
    required this.dataBill,
  }) : super(key: key);

  final List<Bill> dataBill;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            axis: TimelineAxis.horizontal,
            isFirst: true,
            endChild: defaultText(
              context,
              'Order Processing',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: const BoxDecoration(
                  color: successColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/processing_order.png'),
                  ),
                ),
                // child: ,
              ),
            ),
          ),
        ),
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            axis: TimelineAxis.horizontal,
            endChild: defaultText(
              context,
              'Ready For Pickup',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              // height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  color: getColorStatusPickUp(dataBill[0].state),
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/otw_pickup.png'),
                  ),
                ),
              ),
            ),
          ),
        ),
        Container(
          width: 80,
          height: 80,
          child: TimelineTile(
            isLast: true,
            axis: TimelineAxis.horizontal,
            endChild: defaultText(
              context,
              'Order Picked Up',
              maxLines: 2,
              textAlign: TextAlign.center,
              overFlow: TextOverflow.ellipsis,
              style: viewbillStyle(font: 14),
            ),
            beforeLineStyle: const LineStyle(color: successColor),
            afterLineStyle: const LineStyle(color: successColor),
            indicatorStyle: IndicatorStyle(
              width: 42,
              height: 42,
              // height: 42,
              indicator: Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  color: (dataBill[0].state == orderStateDone)
                      ? successColor
                      : disabledColor,
                  shape: BoxShape.circle,
                ),
                child: const Center(
                  child: Image(
                    width: 23,
                    image: AssetImage('assets/icons/order_delivered.png'),
                  ),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

Color getColorStatusPickUp(int orderState) {
  if (orderState == orderStateReady || orderState == orderStateDone) {
    return successColor;
  } else {
    return disabledColor;
  }
}
