import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class HomeCard extends StatelessWidget {
  final bool active;
  final String img;
  final int index;
  final String name;
  final Function()? onTap;
  final Color? color;
  const HomeCard({
    super.key,
    required this.name,
    required this.index,
    this.active = false,
    required this.img,
    required this.onTap,
    required this.color,
  });
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: active ? onTap : null,
      child: Container(
        padding: const EdgeInsets.only(left: 10, right: 10, bottom: 10),
        decoration: BoxDecoration(
          color: color,
          borderRadius: BorderRadius.circular(30),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Expanded(
                    child: SpliteNameHelperWidget(
                      name: name,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 10),
            Expanded(
              child: Align(
                alignment: AlignmentDirectional.bottomEnd,
                child: SvgPicture.asset(img),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class SpliteNameHelperWidget extends StatelessWidget {
  final String name;
  const SpliteNameHelperWidget({
    super.key,
    required this.name,
  });

  @override
  Widget build(BuildContext context) {
    List<String> parts = name.split(' ');

    if (parts.length == 2) {
      // Two-word string
      return Padding(
        padding: const EdgeInsetsGeometry.only(top: 10, left: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: FittedBox(
                fit: BoxFit.scaleDown,
                child: Text(
                  parts[0],
                  style: const TextStyle(
                    fontSize: 30,
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
            Expanded(
              child: FittedBox(
                fit: BoxFit.scaleDown,
                child: Text(
                  parts[1],
                  style: const TextStyle(
                    fontSize: 30,
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    } else {
      // One-word string
      return Text(
        name,
        style: const TextStyle(
          fontSize: 30,
          color: Colors.white,
          fontWeight: FontWeight.bold,
        ),
      );
    }
  }
}
// Text(
//                       name,
//                       style: const TextStyle(
//                         fontSize: 32,
//                         color: Colors.white,
//                         fontWeight: FontWeight.bold,
//                       ),
//                     )
