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/approval_process.dart';
import 'package:niogu_app/core/enums/canceled_by.dart';
import 'package:niogu_app/core/enums/order_status.dart';
import 'package:sizer/sizer.dart';

class OrderHeaderStatus extends StatelessWidget {
  final String outletName;
  final String orderNumber;
  final String orderStatus;
  final Color colorStatus;
  final String orderDate;
  final String? notes;
  final bool isCancellation;
  final bool cancellationAccepted;
  final ApprovalProcess process;
  final OrderStatus status;
  final CanceledBy? canceledBy;
  const OrderHeaderStatus({
    super.key,
    required this.outletName,
    required this.orderNumber,
    required this.orderStatus,
    required this.colorStatus,
    required this.orderDate,
    this.notes,
    this.isCancellation = false,
    this.cancellationAccepted = false,
    required this.process,
    required this.status,
    this.canceledBy,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(3.w),
        border: Border.all(color: Colors.grey.shade200),
      ),
      child: Column(
        children: [
          Container(
            width: 16.w,
            height: 16.w,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.grey[100],
              border: Border.all(color: Colors.grey.shade200),
            ),
            child: Icon(
              Icons.store_rounded,
              color: AppColor.primaryColor,
              size: 8.w,
            ),
          ),
          SizedBox(height: 1.5.h),
          Text(
            outletName,
            style: TextStyle(
              fontSize: AppFontSize.medium.sp,
              fontWeight: FontWeight.bold,
              color: Colors.black87,
            ),
          ),

          SizedBox(height: 0.5.h),

          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "Powered by ",
                style: TextStyle(
                  fontSize: (AppFontSize.small - 2).sp,
                  color: Colors.grey[500],
                ),
              ),
              Text(
                "Niogu",
                style: TextStyle(
                  fontSize: (AppFontSize.small - 2).sp,
                  fontWeight: FontWeight.bold,
                  color: AppColor.primaryColor.withOpacity(0.7),
                ),
              ),
            ],
          ),

          SizedBox(height: 1.5.h),

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                orderNumber,
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: isTablet
                      ? AppFontSize.medium.sp
                      : AppFontSize.small.sp,
                ),
              ),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 3.w, vertical: 0.6.h),
                decoration: BoxDecoration(
                  color: colorStatus.withOpacity(0.1),
                  borderRadius: BorderRadius.circular(5.w),
                  border: Border.all(color: colorStatus.withOpacity(0.2)),
                ),
                child: Text(
                  orderStatus,
                  style: TextStyle(
                    color: colorStatus,
                    fontWeight: FontWeight.bold,
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                  ),
                ),
              ),
            ],
          ),
          Divider(height: 3.h),
          Row(
            children: [
              Icon(
                Icons.calendar_today_outlined,
                size: 4.w,
                color: Colors.grey,
              ),
              SizedBox(width: 2.w),
              Text(
                orderDate,
                style: TextStyle(
                  color: Colors.grey.shade700,
                  fontSize: isTablet
                      ? (AppFontSize.medium - 1.25).sp
                      : (AppFontSize.small - 1.25).sp,
                ),
              ),
            ],
          ),

          if (notes != null && notes!.isNotEmpty) ...[
            SizedBox(height: 2.h),

            Row(
              children: [
                Icon(Icons.note_alt_outlined, size: 4.w, color: Colors.grey),
                SizedBox(width: 2.w),
                Text(
                  "Catatan",
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                  ),
                ),
              ],
            ),
            SizedBox(height: 1.h),
            Row(
              children: [
                Text(
                  notes!,
                  style: TextStyle(
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                    color: Colors.grey[700],
                    fontStyle: FontStyle.italic,
                  ),
                ),
              ],
            ),
          ],

          if (isCancellation) ...[
            SizedBox(height: 2.h),

            Row(
              children: [
                Icon(
                  process == ApprovalProcess.waiting
                      ? Icons.pending_outlined
                      : cancellationAccepted
                      ? Icons.check_outlined
                      : Icons.close_outlined,
                  size: 4.w,
                  color: Colors.grey,
                ),
                SizedBox(width: 2.w),
                Text(
                  process == ApprovalProcess.waiting
                      ? "Menunggu respon persetujuan"
                      : cancellationAccepted
                      ? "Permintaan pembatalan pesanan diterima"
                      : "Permintaan pembatalan pesanan ditolak",
                  style: TextStyle(
                    color: Colors.black87,
                    fontWeight: FontWeight.bold,
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                  ),
                ),
              ],
            ),
          ],

          if (status == OrderStatus.canceled && canceledBy != null) ...[
            SizedBox(height: 2.h),

            Row(
              children: [
                Icon(Icons.person_outlined, size: 4.w, color: Colors.grey),
                SizedBox(width: 2.w),
                Text(
                  "Dibatalkan oleh ${canceledBy == CanceledBy.user ? 'admin' : 'pelanggan'}",
                  style: TextStyle(
                    color: Colors.black87,
                    fontWeight: FontWeight.bold,
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                  ),
                ),
              ],
            ),
          ],
        ],
      ),
    );
  }
}
