import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../blocs/experience_bloc.dart';

class ExperienceCustomInput extends StatefulWidget {
  const ExperienceCustomInput({super.key});

  @override
  State<ExperienceCustomInput> createState() => _ExperienceCustomInputState();
}

class _ExperienceCustomInputState extends State<ExperienceCustomInput> {
  final TextEditingController _controller = TextEditingController();

  void _addSkill() {
    final skill = _controller.text.trim();
    if (skill.isNotEmpty) {
      BlocProvider.of<ExperienceBloc>(context).add(ExperienceCustomSkillAdded(skill));
      _controller.clear();
    }
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: UiTextField(
            controller: _controller,
            onSubmitted: (_) => _addSkill(),
            hintText: t.staff.onboarding.experience.custom_skill_hint,
          ),
        ),
        SizedBox(width: UiConstants.space2),
        UiIconButton.primary(
          icon: UiIcons.add,
          onTap: _addSkill,
        ),
      ],
    );
  }
}
