import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';

abstract class Breadcrumb extends StatelessWidget {
  const Breadcrumb({super.key, this.routes});

  final List<String>? routes;
}

class TextBreadcrumb extends Breadcrumb {
  const TextBreadcrumb({super.key, super.routes});

  @override
  Widget build(BuildContext context) {
    if (routes?.isEmpty ?? true) {
      return SizedBox.shrink();
    }
    return Padding(
      padding: const EdgeInsets.fromLTRB(0, 4, 7, 4),
      child: Text(routes!.join(" > "), style: AppFonts.yekan14.copyWith(color: AppColor.bgDark)),
    );
  }
}

class ContainerBreadcrumb extends Breadcrumb {
  const ContainerBreadcrumb({super.key, super.routes});

  @override
  Widget build(BuildContext context) {
    if (routes?.isEmpty ?? true) {
      return SizedBox.shrink();
    }
    return buildContainerPageRoute(routes!);
  }

  Widget buildContainerPageRoute(List<String> route) {
    return Row(
      children: [
        Container(
          height: 24.h,
          margin: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
          decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(2.r)),
          padding: EdgeInsets.symmetric(horizontal: 6.w),
          child: ListView.separated(
            scrollDirection: Axis.horizontal,
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            itemBuilder: (context, index) => Center(
              child: Text(
                route[index],
                style: AppFonts.yekan14.copyWith(color: AppColor.labelTextColor),
              ),
            ),
            separatorBuilder: (context, index) => Assets.vec.arrowLeftSvg.svg(
              height: 24.h,
              fit: BoxFit.fitHeight,
              colorFilter: ColorFilter.mode(Color(0xFFD6DEEE), BlendMode.srcIn),
            ),
            itemCount: route.length,
          ),
        ),
      ],
    );
  }
}
