import 'package:flutter/material.dart';

import 'package:pweb/pages/settings/profile/account/name/text_line.dart';


class AccountNameViewText extends StatelessWidget {
  const AccountNameViewText({
    super.key,
    required this.hintText,
    required this.inputWidth,
    required this.firstName,
    required this.lastName,
  });

  final String hintText;
  final double inputWidth;
  final String firstName;
  final String lastName;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final trimmedFirstName = firstName.trim();
    final trimmedLastName = lastName.trim();
    final hasFirstName = trimmedFirstName.isNotEmpty;
    final hasLastName = trimmedLastName.isNotEmpty;

    final firstLineStyle = theme.textTheme.headlineMedium?.copyWith(
      fontWeight: FontWeight.bold,
    );
    final secondLineStyle = theme.textTheme.headlineMedium?.copyWith(
      fontWeight: FontWeight.bold,
    );

    if (!hasFirstName && !hasLastName) {
      return SizedBox(
        width: inputWidth,
        child: AccountNameSingleLineText(
          text: hintText,
          style: firstLineStyle,
          textAlign: TextAlign.center,
        ),
      );
    }

    if (!hasFirstName || !hasLastName) {
      final singleLineName = hasFirstName ? trimmedFirstName : trimmedLastName;
      return SizedBox(
        width: inputWidth,
        child: AccountNameSingleLineText(
          text: singleLineName,
          style: firstLineStyle,
          textAlign: TextAlign.center,
        ),
      );
    }

    return SizedBox(
      width: inputWidth,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          AccountNameSingleLineText(
            text: trimmedFirstName,
            style: firstLineStyle,
            textAlign: TextAlign.center,
          ),
          AccountNameSingleLineText(
            text: trimmedLastName,
            style: secondLineStyle,
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}
