import 'package:flutter/material.dart';

import '../../../controllers/localization/localization.dart';
import '../../../controllers/validator/validator.dart';
import '../../../models/gas_refill/gas_refill_details.dart';
import '../../../models/subtitle.dart';
import '../app_text_form_field.dart';
import '../requests/info_row.dart';
import '../titles/app_sub_title.dart';
import '../titles/app_title.dart';

class GasRefillUpdateDetailsItem extends StatelessWidget {
  final GasRefillDetails details;
  final bool? enableEdit;
  final bool? validate;

  const GasRefillUpdateDetailsItem({Key? key, required 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?.label ?? ""),
        RequestInfoRow(
          title: "Cylinder Size",
          info: details.cylinderSize?.label ?? "",
        ),
        RequestInfoRow(
          title: "Requested Quantity",
          info: details.requestedQuantity?.toStringAsFixed(0) ?? "",
        ),
        (enableEdit ?? false)
            ? Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  ASubTitle(subtitle?.quantity ?? ""),
                  if ((validate ?? false) && 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!) ? "" : "allow numbers only",
                    textInputType: TextInputType.number,
                    onSaved: (value) {
                      details.deliveredQuantity = int.tryParse(value!);
                    },
                  ),
                ],
              )
            : RequestInfoRow(
                title: "Delivered Quantity",
                info: details.deliveredQuantity?.toStringAsFixed(0) ?? "",
              ),
        //SizedBox(height: 16,)
      ],
    );
  }
}
