
import '../../../../../../food_delivery_client.dart';

class WelcomeText extends StatelessWidget {
  final String text;

  const WelcomeText({Key? key, required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final voltIndex = text.toLowerCase().indexOf(
      AppLocaleKeys.appName.toLowerCase(),
    );

    if (voltIndex == -1) {
      return Text(
        text,
        style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
      );
    }

    final before = text.substring(0, voltIndex);
    final volt = text.substring(
      voltIndex,
      voltIndex + AppLocaleKeys.appName.length,
    );
    final after = text.substring(voltIndex + AppLocaleKeys.appName.length);

    return Text.rich(
      TextSpan(
        children: [
          TextSpan(text: before, style: context.appThemeTextStyles.size24Bold),
          WidgetSpan(
            alignment: PlaceholderAlignment.baseline,
            baseline: TextBaseline.alphabetic,
            child: ShaderMask(
              shaderCallback: (bounds) =>
                  AppUtils.kGradient.createShader(bounds),
              child: Text(
                volt,
                style: context.appThemeTextStyles.size24Bold.copyWith(
                  color: AppColors.cFFFFFF,
                ),
              ),
            ),
          ),
          // "Volt" dan keyingi text
          TextSpan(text: after, style: context.appThemeTextStyles.size24Bold),
        ],
      ),
    );
  }
}
