import 'package:cargocalculaterapp/core/extension/build_context_extension.dart';
import 'package:flutter/cupertino.dart';

class ProfileInfoFieldWidget extends StatelessWidget {
  const ProfileInfoFieldWidget({
    super.key,
    required this.title,
    this.inputType,
    this.controller,
    this.readOnly = false,
    this.hasError,
    this.errorText,
    required this.isValid,
  });

  final String title;
  final TextInputType? inputType;
  final TextEditingController? controller;
  final bool readOnly;
  final bool? hasError;
  final bool isValid;
  final String? errorText;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CupertinoTextFormFieldRow(
          readOnly: readOnly,
          cursorColor: context.color.accentColor,
          prefix: SizedBox(
            width: 90,
            child: Text(
              title,
              style: context.text.profileCategory.copyWith(
                fontWeight: FontWeight.w700,
                fontSize: 16,
              ),
            ),
          ),
          controller: controller,
          style: context.text.profileCategory,
          textAlign: TextAlign.left,
          keyboardType: inputType,
        ),
        if ((controller?.text.isNotEmpty ?? false) &&
            (hasError ?? false) &&
            (!isValid))
          Padding(
            padding: const EdgeInsets.only(left: 16.0, top: 0),
            child: Text(
              errorText ?? "",
              style: const TextStyle(
                color: CupertinoColors.systemRed,
                fontSize: 14,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
      ],
    );
  }
}
