import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/controllers/validator/validator.dart';
import 'package:test_sa/models/gas_refill/gas_refill_details.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/widgets/app_text_form_field.dart';
import 'package:test_sa/views/widgets/requests/info_row.dart';
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
import 'package:test_sa/views/widgets/titles/app_title.dart';
class GasRefillUpdateDetailsItem extends StatelessWidget {

  final GasRefillDetails details;
  final bool enableEdit;
  final bool validate;

  const GasRefillUpdateDetailsItem({Key key, this.details, this.enableEdit, this.validate}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Subtitle subtitle = AppLocalization.of(context).subtitle;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ATitle(details.type.name),
        RequestInfoRow(
          title:  "Cylinder Size",
          info: details.cylinderSize.name,
        ),
        RequestInfoRow(
          title:  "Requested Quantity",
          info: details.requestedQuantity.toStringAsFixed(0),
        ),
        enableEdit ?
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ASubTitle(subtitle.quantity),
            if(validate && details.deliveredQuantity == null)
              ASubTitle(subtitle.requiredWord,color: Colors.red,),
            SizedBox(height: 4,),
            ATextFormField(
              initialValue: (details.deliveredQuantity ?? "").toString(),
              textAlign: TextAlign.center,
              style: Theme.of(context).textTheme.subtitle1,
              validator: (value) =>
              Validator.isNumeric(value)
                  ? null : "allow numbers only",
              textInputType: TextInputType.number,
              onSaved: (value){
                details.deliveredQuantity = double.tryParse(value);
              },
            ),
          ],
        ):
        RequestInfoRow(
          title:  "Delivered Quantity",
          info: details.deliveredQuantity?.toStringAsFixed(0),
        ),
        //SizedBox(height: 16,)
      ],
    );
  }
}
