import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_translate/generated/assets.dart';
import 'package:flutter_translate/manager/translate.dart';
import 'package:flutter_translate/pages/translated_text/translated_text_controller.dart';
import 'package:get/get.dart';

class LanguageTextBar extends GetView<TranslatedTextController> {
  const LanguageTextBar({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        _fromLanguage(),
        _convertIcon(),
        _toLanguage(),
      ],
    );
  }

  Widget _fromLanguage() {
    return Expanded(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Flexible(
            child: Text(
              controller.isHistory
                  ? (controller.fromLanguageName ?? '')
                  : Translate().fromLanguageEntity.value.name,
              style: const TextStyle(
                color: Color(0xff435561),
                fontSize: 14,
                fontWeight: FontWeight.w500,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _convertIcon() {
    return Container(
      width: 26.w,
      height: 18.w,
      margin: const EdgeInsets.symmetric(horizontal: 10).w,
      decoration: BoxDecoration(
        color: const Color(0xff7FD5AA),
        borderRadius: BorderRadius.circular(9),
      ),
      padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 6).w,
      child: Image.asset(Assets.iconConvert, color: Colors.white),
    );
  }

  Widget _toLanguage() {
    return Expanded(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Flexible(
            child: Text(
              controller.isHistory
                  ? (controller.toLanguageName ?? '')
                  : Translate().toLanguageEntity.value.name,
              style: TextStyle(
                color: const Color(0xff435561),
                fontSize: 14.sp,
                fontWeight: FontWeight.w500,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
