import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';

class CreateCommunityNameTextField extends StatelessWidget {
  const CreateCommunityNameTextField({
    required this.nameController,
    super.key,
  });

  final TextEditingController nameController;

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      controller: nameController,
      validator: _validator,
      style: context.textTheme.bodyMedium,
      decoration: InputDecoration(
        hintText: 'Please enter the community name',
        filled: true,
        fillColor: ColorsManager.boxColor,
        enabledBorder: _buildBorder(ColorsManager.boxColor),
        focusedBorder: _buildBorder(),
        focusedErrorBorder: _buildBorder(Theme.of(context).colorScheme.error),
        errorBorder: _buildBorder(Theme.of(context).colorScheme.error),
      ),
    );
  }

  String? _validator(String? value) {
    if (value == null || value.isEmpty) {
      return '*Name should not be empty.';
    }

    return null;
  }

  InputBorder _buildBorder([Color? color]) {
    return OutlineInputBorder(
      borderRadius: BorderRadius.circular(10),
      borderSide: BorderSide(
        color: color ?? ColorsManager.vividBlue.withValues(alpha: 0.5),
        width: 1,
      ),
    );
  }
}
