import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

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

class ComponentNameUser extends StatelessWidget {
  const ComponentNameUser({
    Key? key,
    required this.isDeliveryPickuup,
    this.dataBill = const [],
    required this.backgroundColorComponent,
    this.isFromMenu = false,
    required this.isdelivery,
  }) : super(key: key);

  final bool isDeliveryPickuup;
  final List<Bill> dataBill;
  final Color backgroundColorComponent;
  final bool isFromMenu;
  final bool isdelivery;

  @override
  Widget build(BuildContext context) {
    String customerName;
    if (dataBill.isEmpty) {
      customerName = getCustomerName();
    } else {
      customerName = dataBill[0].customerName;
    }
    return Container(
      width: double.infinity,
      color: backgroundColorComponent.withOpacity(0.9),
      padding: const EdgeInsets.symmetric(vertical: 10),
      // height: 40,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                padding: (isFromMenu)
                    ? null
                    : const EdgeInsets.symmetric(horizontal: paddingLeftRight),
                child: defaultText(
                    context,
                    (isDeliveryPickuup)
                        ? (isdelivery)
                            ? 'Delivery'
                            : 'Pickup'
                        : 'Meja ${dataBill[0].tableName}',
                    style: viewbillStyle()),
              ),
              Container(
                padding: (isFromMenu)
                    ? null
                    : const EdgeInsets.only(
                        left: paddingLeftRight,
                        right: paddingLeftRight,
                        // bottom: 18,
                      ),
                child: defaultText(context, customerName,
                    style: customerNameViewbill()),
              ),
            ],
          ),
          (isDeliveryPickuup)
              ? GestureDetector(
                  onTap: () {
                    if (getIsCanChangeDeliveryPickup()) {
                      modalBottomSelectOption(context);
                    } else {
                      EasyLoading.showToast(
                          'Tidak dapat ganti tipe order karena status orderan sedang diproses / telah selesai');
                    }
                  },
                  child: Container(
                    height: 30,
                    width: 69,
                    margin: (isFromMenu)
                        ? null
                        : const EdgeInsets.only(
                            right: 20,
                          ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(40),
                      color: buttonColor,
                    ),
                    child: Center(
                      child: defaultText(
                        context,
                        'Ganti',
                        style: addButton(
                          font: 8,
                        ),
                      ),
                    ),
                  ),
                )
              : const SizedBox()
        ],
      ),
    );
  }
}
