import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.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 AppScaffold(
      isShowAppBar: true,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      appBarTitle: TranslationBase.of(context).notificationDetails,
      body: ListView(
        physics: BouncingScrollPhysics(),
        padding: EdgeInsets.all(21),
        children: [
          Text(
            DateUtil.getDayMonthYearDateFormatted(DateUtil.convertStringToDate(notification.createdOn)) +
                " " +
                DateUtil.formatDateToTimeLang(DateUtil.convertStringToDate(notification.createdOn), false),
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w600,
              color: Color(0xff2E303A),
              letterSpacing: -0.64,
            ),
          ),

          if (notification.messageTypeData.length != 0)
            Padding(
              padding: const EdgeInsets.only(top: 18),
              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),
            ),

          SizedBox(height: 18),
          Text(
            notification.message.trim(),
            style: TextStyle(
              fontSize: 12,
              fontWeight: FontWeight.w600,
              color: Color(0xff575757),
              letterSpacing: -0.48,
            ),
          ),

        ],
      ),
    );
  }
}
