// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:qadirneyriz/config/config.dart';
import 'package:qadirneyriz/screens/meeting/state.dart';
import 'package:qadirneyriz/screens/private_meeting/screen.dart';

class CustomCardMeeting extends StatelessWidget {
  final String titel;
  final String date;
  final String location;
  final String fromTime;
  final String toTime;
  final int status;
  final int cardId;
  final void Function(String)? onSelectedMoreButton;
  final List<PopupMenuEntry<String>> Function(BuildContext)?
      itemBuilderMoreButton;
  const CustomCardMeeting({
    Key? key,
    required this.titel,
    required this.date,
    required this.status,
    required this.location,
    required this.fromTime,
    required this.toTime,
    required this.cardId,
    this.onSelectedMoreButton,
    this.itemBuilderMoreButton,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      child: Consumer<MeetingsState>(
        builder: (context, value, child) {
          return Container(
            width: 350,
            decoration: BoxDecoration(
                color: const Color(0xffF4F9F6),
                boxShadow: [
                  BoxShadow(
                      color: config.ui.mainGray.withOpacity(.1),
                      spreadRadius: .1,
                      offset: const Offset(0, 2),
                      blurRadius: 6)
                ],
                borderRadius: const BorderRadius.all(Radius.circular(12))),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Flexible(
                  child: Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Icon(
                              Icons.check,
                              color: config.ui.mainGreen,
                            ),
                            const SizedBox(
                              width: 8,
                            ),
                            Flexible(
                              fit: FlexFit.loose,
                              child: Text(
                                titel,
                                maxLines: 1,
                                style: const TextStyle(fontSize: 13),
                                overflow: TextOverflow.ellipsis,
                              ),
                            )
                          ],
                        ),
                        const SizedBox(
                          height: 8,
                        ),
                        Row(
                          children: [
                            Icon(
                              Icons.location_city_outlined,
                              color: config.ui.mainGreen,
                            ),
                            const SizedBox(
                              width: 8,
                            ),
                            Flexible(
                              fit: FlexFit.loose,
                              child: Text(
                                location,
                                maxLines: 1,
                                style: const TextStyle(fontSize: 13),
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                          ],
                        ),
                        const SizedBox(
                          height: 8,
                        ),
                        Row(
                          children: [
                            Icon(
                              Icons.date_range,
                              color: config.ui.mainGreen,
                            ),
                            const SizedBox(
                              width: 8,
                            ),
                            Flexible(
                              fit: FlexFit.loose,
                              child: Text(
                                date,
                                maxLines: 1,
                                style: const TextStyle(fontSize: 13),
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                          ],
                        ),
                        const SizedBox(
                          height: 8,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Icon(
                                  Icons.alarm,
                                  color: config.ui.mainGreen,
                                ),
                                const SizedBox(
                                  width: 8,
                                ),
                                Text(
                                  '$fromTime ${AppLocalizations.of(context)!.to} $toTime',
                                  maxLines: 1,
                                  style: const TextStyle(fontSize: 13),
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ],
                            ),
                            if (this.status != 0)
                              PrivateMeetingLabel(
                                status: this.status,
                              )
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
                itemBuilderMoreButton != null
                    ? _moreButton(context, value)
                    : Container(),
              ],
            ),
          );
        },
      ),
    );
  }

  Widget _moreButton(BuildContext context, MeetingsState state) {
    return PopupMenuButton<String>(
      color: Colors.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(10.0),
        ),
      ),
      onSelected: onSelectedMoreButton,
      itemBuilder: itemBuilderMoreButton!,
      icon: const Icon(Icons.more_horiz),
    );
  }
}
