import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/notifications_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';
import 'package:flutter/material.dart';

class NotificationsDetailsPage extends StatelessWidget {
  final GetNotificationsResponseModel notification;

  NotificationsDetailsPage({this.notification});

  getDateForm(String date) {
    DateTime d = DateUtil.convertStringToDate(date);
    String monthName = DateUtil.getMonth(d.month).toString();
    TimeOfDay timeOfDay = TimeOfDay(hour: d.hour, minute: d.minute);
    String minute = timeOfDay.minute < 10
        ? timeOfDay.minute.toString().padLeft(2, '0')
        : timeOfDay.minute.toString();

    String hour = '${timeOfDay.hourOfPeriod}:$minute';
    if (timeOfDay.period == DayPeriod.am) {
      hour = hour + "AM";
    } else {
      {
        hour = hour + "PM";
      }
    }
    return monthName + ',${d.day},${d.year}, $hour';
  }

  @override
  Widget build(BuildContext context) {
    return BaseView<NotificationViewModel>(
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).notificationDetails,
        body: SingleChildScrollView(
          child: Center(
            child: FractionallySizedBox(
              widthFactor: 0.9,
              child: Column(
                children: [
                  SizedBox(
                    height: 25,
                  ),
                  Container(
                    // margin: EdgeInsets.only(left: 30),
                    width: double.infinity,
                    color: Colors.grey[400],
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Texts(
                        getDateForm(notification.createdOn),
                        fontSize: 16,
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 15,
                  ),
                  if (notification.messageTypeData.length != 0)
                    FractionallySizedBox(
                        widthFactor: 0.9,
                        child: Image.network(notification.messageTypeData,
                            loadingBuilder: (BuildContext context, Widget child,
                                ImageChunkEvent loadingProgress) {
                          if (loadingProgress == null) return child;
                          return Center(
                            child: SizedBox(
                              width: 40.0,
                              height: 40.0,
                              child: AppCircularProgressIndicator(),
                            ),
                          );
                        },
                            fit: BoxFit
                                .fill) //Image.network(notification.messageTypeData),
                        ),
                  SizedBox(
                    height: 15,
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: Center(
                          child: Texts(notification.message),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
