import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';

class InfoTextWidget extends StatelessWidget {
  String? value;
  final String label;
  final bool showEmptyValue;
  final bool showArrow;
  final bool copyValue;
  final bool isMsg;

  InfoTextWidget({required this.label, this.value, this.showEmptyValue = false, this.copyValue = false, this.showArrow = false, this.isMsg = false, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget text;
    String aLabel = label + (isMsg ? "" : ":");
    if (showEmptyValue) {
      text = Text('$aLabel ${value ?? ""}', style: AppTextStyles.bodyText2.copyWith(color: AppColor.lightTextColor(context)));
    } else if (value?.isNotEmpty ?? false) {
      text = Text('$aLabel $value', style: AppTextStyles.bodyText2.copyWith(color: AppColor.lightTextColor(context)));
    } else {
      text = const SizedBox();
    }
    if (showArrow) {
      text = Row(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          text.expanded,
          const SizedBox(width: 4),
          "arrow_right".toSvgAsset(width: 17, color: AppColor.primary10),
        ],
      );
    } else if (copyValue && (value?.isNotEmpty ?? false)) {
      text = Row(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Flexible(child: text),
          8.width,
          const Icon(Icons.copy_rounded, color: AppColor.primary10, size: 14).onPress(() {
            Clipboard.setData(ClipboardData(text: value!)).then((value) {
              if (Platform.isIOS) {
                "Copied.".addTranslation.showToast;
              }
            });
          }),
        ],
      );
    }
    return text;
  }
}

class InfoTextLabelWidget extends StatelessWidget {
  final String label;
  final Color? color;
  final TextStyle? textStyle;

  const InfoTextLabelWidget({required this.label, this.color, this.textStyle, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget text;
    text = Text(label, style: (textStyle ?? AppTextStyles.bodyText2).copyWith(color: color ?? AppColor.lightTextColor(context)));
    return text;
  }
}
