import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class DiscountByWeightEditor extends StatefulWidget {
  final Discount discount;
  DiscountByWeightEditor({this.discount});

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

class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
  TextEditingController _weightController = new TextEditingController();
  TextEditingController _rateController = new TextEditingController();

  bool _isLoading = false;
  Discount _discount = new Discount();

  @override
  void initState() {
    super.initState();
    if (widget.discount != null) {
      _discount = widget.discount;
      _weightController.text = _discount.weight.toString();
      _rateController.text = _discount.discountRate.toString();
    }
  }

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

  @override
  Widget build(BuildContext context) {

     final weightBox = InputText(
        labelTextKey: 'rate.discount.weight',
        iconData: FontAwesomeIcons.weightHanging,
        controller: _weightController);
    final discountRateBox = InputText(
        labelTextKey: 'rate.discount.rate',
        iconData: Icons.attach_money,
        controller: _rateController);

    return LocalProgress(
      inAsyncCall: _isLoading,
      child: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          leading: new IconButton(
            icon: new Icon(
              Icons.close,
            ),
            onPressed: () => Navigator.of(context).pop(),
          ),
          backgroundColor: primaryColor,
          title: Text(AppTranslations.of(context).text("discount.new")),
        ),
        body: Container(
          padding: EdgeInsets.all(18),
          child: Column(
            children: <Widget>[
              Expanded(
                child: ListView(
                  children: <Widget>[
                    weightBox,
                    discountRateBox,
                    SizedBox(height: 30),
                  ],
                ),
              ),
              widget.discount == null
                  ? fcsButton(context, "Create", callack: () {})
                  : fcsButton(context, "Save", callack: () {}),
              SizedBox(height: 10)
            ],
          ),
        ),
      ),
    );
  }
}
