import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class BoxAddition extends StatefulWidget {
  final Carton box;
  BoxAddition({this.box});

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

class _BoxAdditionState extends State<BoxAddition> {
  Carton _box = new Carton();
  bool _isLoading = false;

  @override
  void initState() {
    super.initState();
    if (widget.box != null) {
      _box = widget.box;
    }
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var boxModel = Provider.of<CartonModel>(context);
    return LocalProgress(
      inAsyncCall: _isLoading,
      child: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          leading: new IconButton(
            icon: new Icon(CupertinoIcons.back),
            onPressed: () => Navigator.of(context).pop(),
          ),
          backgroundColor: primaryColor,
          title: Text(AppTranslations.of(context).text("box.edit.title")),
        ),
        body: Card(
          child: Column(
            children: <Widget>[
              Expanded(
                  child: Padding(
                padding: const EdgeInsets.all(10.0),
                child: ListView(children: <Widget>[
                  DropdownButtonFormField(
                    decoration: InputDecoration(
                        fillColor: Colors.white,
                        labelText: 'Box Number',
                        icon: Icon(Icons.pages)),
                    items: boxModel.processed
                        .map((e) => DropdownMenuItem(
                            child: Text(
                                '${e.shipmentNumber}-${e.receiverNumber} #${e.boxNumber}'),
                            value: e))
                        .toList(),
                    onChanged: (map) => {},
                  ),
                ]),
              )),
              widget.box == null
                  ? Align(
                      alignment: Alignment.bottomCenter,
                      child: Center(
                          child: Container(
                        width: 250,
                        child: FlatButton(
                          child: Text('Add box'),
                          color: primaryColor,
                          textColor: Colors.white,
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        ),
                      )))
                  : Align(
                      alignment: Alignment.bottomCenter,
                      child: Center(
                          child: Container(
                        width: 250,
                        child: FlatButton(
                          child: Text('Save box'),
                          color: primaryColor,
                          textColor: Colors.white,
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        ),
                      ))),
              SizedBox(
                height: 30,
              )
            ],
          ),
        ),
      ),
    );
  }
}
