import 'package:flutter/material.dart';

import '../../../../common/extension/extension.dart';
import '../../../../common/theme/theme.dart';
import '../../../components/field/field.dart';
import '../../../components/page/page_title.dart';
import '../../../components/picker/date_range_picker.dart';
import '../../../components/spaces/space.dart';

class OrderTitle extends StatelessWidget {
  final String title;
  final DateTime startDate;
  final DateTime endDate;
  final Function(String) onChanged;
  final void Function(DateTime? start, DateTime? end) onDateRangeChanged;
  final int totalOrder;
  const OrderTitle({
    super.key,
    required this.title,
    required this.startDate,
    required this.endDate,
    required this.onChanged,
    required this.onDateRangeChanged,
    required this.totalOrder,
  });

  @override
  Widget build(BuildContext context) {
    return PageTitle(
      title: title,
      bottom: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
        decoration: const BoxDecoration(
          color: AppColor.white,
          border: Border(
            bottom: BorderSide(color: AppColor.border, width: 1.0),
          ),
        ),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  startDate.toFormattedDate() == endDate.toFormattedDate()
                      ? startDate.toFormattedDate()
                      : '${startDate.toFormattedDate()} - ${endDate.toFormattedDate()}',
                  style: AppStyle.md.copyWith(fontWeight: FontWeight.w600),
                ),
                Text(
                  '$totalOrder Pesanan',
                  style: AppStyle.md.copyWith(fontWeight: FontWeight.w600),
                ),
              ],
            ),
            const SpaceHeight(16),
            Row(
              children: [
                Expanded(
                  child: AppTextFormField(
                    onChanged: onChanged,
                    label: 'Cari Pesanan',
                    showLabel: false,
                  ),
                ),
                const SpaceWidth(12),
                GestureDetector(
                  onTap: () => DateRangePickerModal.show(
                    context: context,
                    initialStartDate: startDate,
                    initialEndDate: endDate,
                    primaryColor: AppColor.primary,
                    onChanged: onDateRangeChanged,
                  ),
                  child: Container(
                    padding: const EdgeInsets.all(12),
                    decoration: BoxDecoration(
                      color: AppColor.primary,
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: const Icon(
                      Icons.filter_list_outlined,
                      color: AppColor.white,
                      size: 24,
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
