import 'package:flutter/material.dart';

import '../../../../../utils/color_manager.dart';

class SpaceNameTextfieldWidget extends StatelessWidget {
  SpaceNameTextfieldWidget({
    super.key,
    required this.isNameFieldExist,
    required this.isNameFieldInvalid,
    required this.onChange,
    required this.screenWidth,
    required this.nameController,
  });
  TextEditingController nameController;
  final void Function(String value) onChange;
  final double screenWidth;
  bool isNameFieldExist;
  bool isNameFieldInvalid;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(
          width: screenWidth * 0.25,
          child: TextField(
            controller: nameController,
            onChanged: onChange,
            style: Theme.of(context).textTheme.bodyMedium,
            decoration: InputDecoration(
              hintText: 'Please enter the name',
              hintStyle: Theme.of(context)
                  .textTheme
                  .bodyMedium!
                  .copyWith(color: ColorsManager.lightGrayColor),
              filled: true,
              fillColor: ColorsManager.boxColor,
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(10),
                borderSide: BorderSide(
                  color: isNameFieldInvalid || isNameFieldExist
                      ? ColorsManager.red
                      : ColorsManager.boxColor,
                  width: 1.5,
                ),
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(10),
                borderSide: const BorderSide(
                  color: ColorsManager.boxColor,
                  width: 1.5,
                ),
              ),
            ),
          ),
        ),
        if (isNameFieldInvalid)
          Padding(
            padding: const EdgeInsets.only(top: 8.0),
            child: Text(
              '*Space name should not be empty.',
              style: Theme.of(context)
                  .textTheme
                  .bodySmall
                  ?.copyWith(color: ColorsManager.red),
            ),
          ),
        if (isNameFieldExist)
          Padding(
            padding: const EdgeInsets.only(top: 8.0),
            child: Text(
              '*Name already exist',
              style: Theme.of(context)
                  .textTheme
                  .bodySmall
                  ?.copyWith(color: ColorsManager.red),
            ),
          ),
      ],
    );
  }
}
