
import 'package:diplomaticquarterapp/core/model/prescriptions/prescriptions_order.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

final _item_content_seperator = Container(height: 0.25, padding: EdgeInsets.all(10), color: Colors.grey.withOpacity(0.5));

class RRTLogListItem extends StatelessWidget{
  final PrescriptionsOrder order;
  final Function(PrescriptionsOrder) onCancel;
  RRTLogListItem(this.order, {this.onCancel});

  BuildContext _context;

  TranslationBase localize;
  @override
  Widget build(BuildContext context) {
    _context = context;
    localize = TranslationBase.of(context);

    return Container(
      padding: EdgeInsets.all(15), margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(15),
          boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.25), spreadRadius: 1, blurRadius: 3)]
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          _contentItem(label: localize.reqId, value: order.iD.toString()),
          _item_content_seperator,
          _contentItem(label: localize.status, value: order.getStatusName(localize)),
          _item_content_seperator,
          _contentItem(label: localize.pickupDate, value: order.getFormattedDateTime()),
          _item_content_seperator,
          _contentItem(label: localize.location, value: order.getNearestProjectDescription()),
          _item_content_seperator,
          SizedBox(height: 10),

          if(onCancel != null)
            FractionallySizedBox(child: cancelButton())
        ],
      ),
    );
  }

  Widget _contentItem({@required String label, String value}){
    return Container(
      padding: EdgeInsets.symmetric(vertical: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(label, style: TextStyle(color: Theme.of(_context).appBarTheme.color, fontSize: 9, letterSpacing: 1),),
          SizedBox(height: 5,),
          Text(value, style: TextStyle(color: Theme.of(_context).appBarTheme.color,fontWeight: FontWeight.bold, fontSize: 14),),
        ],
      ),
    );
  }

  Widget cancelButton() => MaterialButton(
    height: 45,
    color: Color(0xFFc5272d),
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10) ),
    onPressed: () => onCancel(order),
    child: Text(localize.cancel, style: TextStyle(color: Colors.white, fontSize: 13),),

  );
}
