import 'package:fcs/domain/entities/pickup.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';

import '../main/util.dart';
import 'shipment_editor.dart';

class ShipmentListRow extends StatefulWidget {
  final Shipment pickUp;
  const ShipmentListRow({this.pickUp});

  @override
  _ShipmentListRowState createState() => _ShipmentListRowState();
}

class _ShipmentListRowState extends State<ShipmentListRow> {
  final double dotSize = 15.0;
  Shipment _pickUp = new Shipment();

  @override
  void initState() {
    super.initState();
    // PickUpModel pickUpModel = Provider.of<PickUpModel>(context, listen: false);
    if (widget.pickUp != null) {
      _pickUp = widget.pickUp;
      // pickUpModel.pickups.forEach((b) {
      //   if (widget.pickUp.id == b.id) {
      //     _pickUp = b;
      //   }
      // });
    }
  }

  @override
  Widget build(BuildContext context) {
    print('_pickup $_pickUp');
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      child: InkWell(
        onTap: () {
          Navigator.of(context)
              .push(BottomUpPageRoute(ShipmentEditor(pickUp: _pickUp)));
        },
        child: Row(
          children: <Widget>[
            Expanded(
              child: new Padding(
                padding: const EdgeInsets.symmetric(vertical: 16.0),
                child: new Row(
                  children: <Widget>[
                    Padding(
                        padding: EdgeInsets.all(5.0),
                        child: Icon(
                          SimpleLineIcons.direction,
                          color: primaryColor,
                        )),
                    new Expanded(
                      child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.only(left: 8.0),
                            child: new Text(
                              _pickUp.id == null ? '' : _pickUp.id,
                              style: new TextStyle(
                                  fontSize: 15.0, color: Colors.black),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(left: 10.0, top: 10),
                            child: new Text(
                              _pickUp.id == null
                                  ? ''
                                  : "Last ${_pickUp.last} days",
                              style: new TextStyle(
                                  fontSize: 15.0, color: Colors.grey),
                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(0),
                  child: getStatus(_pickUp.status),
                ),
                Padding(
                  padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
                  child: Row(
                    children: <Widget>[
                      new Text(
                        _pickUp.weight == null
                            ? ''
                            : _pickUp.weight.toString() + 'lb - ',
                        style:
                            new TextStyle(fontSize: 15.0, color: Colors.grey),
                      ),
                      new Text(
                        _pickUp.numberOfPackage == null
                            ? ""
                            : _pickUp.numberOfPackage.toString() + ' packages',
                        style:
                            new TextStyle(fontSize: 15.0, color: Colors.grey),
                      ),
                    ],
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
