import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_color.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:niogu_app/core/enums/delivery_type.dart';
import 'package:sizer/sizer.dart';

class DeliveryInfoCard extends StatelessWidget {
  final DeliveryType deliveryType;
  final String customerName;
  final String phoneNumber;
  final String fullAddress;
  final String preference;
  const DeliveryInfoCard({
    super.key,
    required this.deliveryType,
    required this.customerName,
    required this.phoneNumber,
    required this.fullAddress,
    required this.preference,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;

    final isDelivery = deliveryType == DeliveryType.delivery;
    return Container(
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(4.w),
        border: Border.all(color: Colors.grey.shade200),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.02),
            blurRadius: 10,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Icon(
                deliveryType == DeliveryType.pick_up
                    ? Icons.store_outlined
                    : Icons.local_shipping_outlined,
                size: 5.w,
                color: AppColor.primaryColor,
              ),
              SizedBox(width: 2.w),
              Text(
                deliveryType == DeliveryType.pick_up
                    ? "Ambil Ditoko"
                    : "Informasi Pengiriman",
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: (AppFontSize.medium - (isTablet ? 0 : 1.25)).sp,
                  color: Colors.black87,
                ),
              ),
            ],
          ),
          SizedBox(height: 2.h),
          _buildInfoRow(isTablet, "Pembeli", customerName),
          _buildInfoRow(isTablet, "Telepon", phoneNumber),

          if (isDelivery) ...[
            Divider(height: 3.h),
            _buildInfoRow(isTablet, "Alamat", fullAddress),
          ],
          _buildInfoRow(
            isTablet,
            isDelivery ? "Preferensi" : "Diambil Pukul",
            preference,
            isBold: true,
          ),
        ],
      ),
    );
  }

  Widget _buildInfoRow(
    bool isTablet,
    String label,
    String value, {
    bool isBold = false,
  }) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 0.8.h),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            width: 25.w,
            child: Text(
              label,
              style: TextStyle(
                fontSize: isTablet
                    ? (AppFontSize.medium - 1.25).sp
                    : (AppFontSize.small - 1.25).sp,
                color: Colors.grey[600],
              ),
            ),
          ),
          Expanded(
            child: Text(
              value,
              style: TextStyle(
                fontSize: isTablet
                    ? (AppFontSize.medium - 1.25).sp
                    : (AppFontSize.small - 1.25).sp,
                fontWeight: isBold ? FontWeight.bold : FontWeight.normal,
                color: Colors.black87,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
