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

Widget buildRow({
  required String title,
  required String value,
  TextStyle? titleStyle,
  TextStyle? valueStyle,
}) {
  return Padding(
    padding: const EdgeInsets.symmetric(vertical: 4.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Flexible(
          flex: 2,
          child: Text(
            title,
            textAlign: TextAlign.right,
            style: titleStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
          ),
        ),
        Flexible(
          flex: 2,
          child: Text(
            value,
            textAlign: TextAlign.left,
            style: valueStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
          ),
        ),
      ],
    ),
  );
}

Widget buildRowOnTapped({
  String? title,
  String? value,
  Widget? titleWidget,
  Widget? valueWidget,
  TextStyle? titleStyle,
  TextStyle? valueStyle,
  required VoidCallback onTap,
}) {
  return Padding(
    padding: const EdgeInsets.symmetric(vertical: 4.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Flexible(
          flex: 2,
          child:
              titleWidget ??
              Text(
                title ?? 'N/A',
                textAlign: TextAlign.right,
                style: titleStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
              ),
        ),
        Flexible(
          flex: 2,
          child: GestureDetector(
            onTap: onTap,
            child:
                valueWidget ??
                Text(
                  value ?? 'N/A',
                  textAlign: TextAlign.left,
                  style: valueStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
                ),
          ),
        ),
      ],
    ),
  );
}

Widget buildUnitRow({
  required String title,
  String? value,
  required String unit,
  TextStyle? titleStyle,
  TextStyle? valueStyle,
  TextStyle? unitStyle,
  EdgeInsetsGeometry? padding,
}) {
  return Padding(
    padding: padding ?? const EdgeInsets.symmetric(vertical: 4.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Flexible(
          flex: 2,
          child: Text(
            title,
            textAlign: TextAlign.right,
            style: titleStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
          ),
        ),
        Flexible(
          flex: 2,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            spacing: 5,
            children: [
              Text(
                value == null || value.isEmpty ? '-' : value,
                textAlign: TextAlign.left,
                style: valueStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
              ),
              Visibility(
                visible: value != null ||( value?.isNotEmpty ?? false),
                child: Text(
                  unit,
                  textAlign: TextAlign.left,
                  style: valueStyle ?? AppFonts.yekan14.copyWith(color: AppColor.darkGreyDarkHover),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}
