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

class StatefulTextField extends StatefulWidget {
  const StatefulTextField({
    super.key,
    required this.title,
    this.hintText = 'Please enter',
    required this.width,
    this.elevation = 0,
    required this.controller,
  });

  final String title;
  final String hintText;
  final double width;
  final double elevation;
  final TextEditingController controller;

  @override
  State<StatefulTextField> createState() => _StatefulTextFieldState();
}

class _StatefulTextFieldState extends State<StatefulTextField> {
  @override
  Widget build(BuildContext context) {
    return CustomTextField(
      title: widget.title,
      controller: widget.controller,
      hintText: widget.hintText,
      width: widget.width,
      elevation: widget.elevation,
    );
  }
}

class CustomTextField extends StatelessWidget {
  const CustomTextField({
    super.key,
    required this.title,
    required this.controller,
    this.hintText = 'Please enter',
    required this.width,
    this.elevation = 0,
  });

  final String title;
  final TextEditingController controller;
  final String hintText;
  final double width;
  final double elevation;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Text(
          title,
          style: context.textTheme.bodyMedium!.copyWith(
            fontSize: 13,
            fontWeight: FontWeight.w600,
            color: const Color(0xff000000),
          ),
        ),
        const SizedBox(height: 8),
        Material(
          elevation: elevation,
          borderRadius: BorderRadius.circular(8),
          child: Container(
            width: width,
            height: 45,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(8),
            ),
            child: TextFormField(
              controller: controller,
              style: const TextStyle(color: Colors.black),
              decoration: InputDecoration(
                hintText: hintText,
                hintStyle: const TextStyle(fontSize: 12),
                contentPadding:
                    const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
                border: InputBorder.none,
              ),
            ),
          ),
        ),
      ],
    );
  }
}
