import 'package:app_hit_a_wod/src/models/box.model.dart';
import 'package:app_hit_a_wod/src/models/new.model.dart';
import 'package:app_hit_a_wod/src/models/subscription_selection.model.dart';
import 'package:app_hit_a_wod/src/pages/my_orders/my_order_detail.page.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../styles.dart';

class NewsDetailPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    Map<String, dynamic> arguments = ModalRoute.of(context).settings.arguments;
    final New n = arguments["new"];
    final SubscriptionSelection ss = arguments["ss"];

    return neuScaffoldDetail(
      context: context,
      title: Text("Leer noticia", style: Theme.of(context).textTheme.subhead.copyWith(fontWeight: FontWeight.w500, fontSize: 18)),
      action: FlatButton(
        child: shaderContainer(Image.asset('assets/icon/logo.png', height: 35, width: 35,),'in'),
        onPressed: () {
          Navigator.of(context).popUntil(ModalRoute.withName('home'));
        }
      ),
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.all(20),
          child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
            neuContainer(Row(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
              Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
                ClipRRect(borderRadius: BorderRadius.circular(8), child: CachedNetworkImage(imageUrl: ss.company.logo_url, placeholder: (_, __) => neuSkeletonCard(55, 55), width: 55, height: 55, fit: BoxFit.cover,)),
                SizedBox(height: 10),
                Text(DateFormat('dd/MM/yy\nHH:mm').format(n.created_at), style: Theme.of(context).textTheme.body1.copyWith(fontStyle: FontStyle.italic, fontSize: 14), textAlign: TextAlign.center,)
              ]),
              SizedBox(width: 20),
              Expanded(child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
                Text(n.title, style: Theme.of(context).textTheme.body1.copyWith(fontWeight: FontWeight.w500), overflow: TextOverflow.clip,),
                SizedBox(height: 10),
                Text(n.description, style: Theme.of(context).textTheme.body1, overflow: TextOverflow.clip,),
              ]))
            ]),),
            SizedBox(height: 20),
            neuContainer(Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
              Text("Más información sobre la noticia", style: Theme.of(context).textTheme.subtitle),
              SizedBox(height: 20),
              Text(n.box_id!=null ? "Esta noticia fue escrita a nivel de box, a continuación tienes acceso para contactar con ellos:" : "Esta noticia fue escrita para todos los boxes de la empresa, a continuación tienes acceso para contactar con la empresa.", style: Theme.of(context).textTheme.body1),
              SizedBox(height: 20),
              MyOrderDetailPage.contactButtons(context, ss.box)
            ]), width: double.infinity, )
          ])
        )
      )
    );
  }

}