import 'package:flutter/material.dart';
import 'package:intl/intl.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/widgets/custom_text_form_field.dart';
import 'package:niogu_app/features/stock_in/domain/entities/stock_in_transfer.dart';
import 'package:sizer/sizer.dart';

class HeaderStockInTransferSection extends StatelessWidget {
  final DateTime selectedDate;
  final VoidCallback onTap;
  final String? selectedSourceOutlet;
  final List<SourceOutlet> sourceOutlets;
  final void Function(String?) onChanged;
  final TextEditingController refNumberController;

  const HeaderStockInTransferSection({
    super.key,
    required this.selectedDate,
    required this.onTap,
    required this.selectedSourceOutlet,
    required this.sourceOutlets,
    required this.onChanged,
    required this.refNumberController,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return Container(
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(2.5.w),
        border: Border.all(color: Colors.grey.shade200),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.02),
            blurRadius: 5,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          InkWell(
            onTap: onTap,
            child: Row(
              children: [
                Container(
                  padding: EdgeInsets.all(2.w),
                  decoration: BoxDecoration(
                    color: Colors.blue[50],
                    borderRadius: BorderRadius.circular(2.w),
                  ),
                  child: Icon(
                    Icons.calendar_today_rounded,
                    color: AppColor.primaryColor,
                    size: 5.w,
                  ),
                ),
                SizedBox(width: 3.w),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "Tanggal Terima",
                        style: TextStyle(
                          color: Colors.grey[600],
                          fontSize: isTablet
                              ? AppFontSize.medium.sp
                              : AppFontSize.small.sp,
                        ),
                      ),
                      SizedBox(height: 0.5.h),
                      Text(
                        DateFormat('EEEE, dd MMMM yyyy').format(selectedDate),
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: isTablet
                              ? AppFontSize.medium.sp
                              : AppFontSize.small.sp,
                        ),
                      ),
                    ],
                  ),
                ),
                Icon(Icons.edit_outlined, size: 5.w, color: Colors.grey[400]),
              ],
            ),
          ),
          Divider(height: 3.h, color: Colors.grey[100]),
          Text(
            "Terima Dari (Asal)",
            style: TextStyle(
              fontSize: isTablet ? AppFontSize.medium.sp : AppFontSize.small.sp,
              fontWeight: FontWeight.bold,
              color: Colors.grey[700],
            ),
          ),
          SizedBox(height: 1.h),
          DropdownButtonFormField<String>(
            value: selectedSourceOutlet,
            decoration: InputDecoration(
              isDense: true,
              contentPadding: EdgeInsets.symmetric(
                horizontal: 4.w,
                vertical: 1.5.h,
              ),
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(2.5.w),
              ),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(2.5.w),
                borderSide: BorderSide(color: Colors.grey.shade300),
              ),
            ),
            icon: Icon(
              Icons.keyboard_arrow_down_rounded,
              color: Colors.grey[600],
            ),
            items: sourceOutlets.map((outlet) {
              return DropdownMenuItem(
                value: outlet.id,
                child: Text(
                  outlet.name,
                  style: isTablet
                      ? null
                      : TextStyle(fontSize: AppFontSize.small.sp),
                ),
              );
            }).toList(),
            onChanged: onChanged,
          ),

          SizedBox(height: 2.h),

          CustomTextFormField(
            label: "No. Surat Jalan / Referensi",
            labelColor: Colors.grey[700],
            hint: "(Opsional)",
            controller: refNumberController,
            prefixIcon: Icons.receipt_long_outlined,
          ),
        ],
      ),
    );
  }
}
