import 'package:intl/intl.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart';

extension XString on String {
  String get separatedByComma {
    final formatter = NumberFormat('#,###');
    final number = num.tryParse(this);
    return number != null ? formatter.format(number) : this;
  }

  String get clearComma {
    return replaceAll(RegExp(r'\D'), '');
  }

  String get addCountEXT {
    return '$this قطعه';
  }

  String get addDayEXT {
    return '$thisروزه';
  }

  String get addKgEXT {
    return '$this کیلوگرم';
  }

  DateTime get toDateTime => DateTime.parse(this);

  String get formattedJalaliDate {
    String tmp = contains("/") ? replaceAll("/", "-") : this;
    final dateTime = DateTime.parse(tmp);
    final jalaliDate = Jalali.fromDateTime(dateTime);
    return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
  }

  String get formattedJalaliDateYHMS {
    final dateTime = DateTime.parse(this);
    final jalaliDate = Jalali.fromDateTime(dateTime);
    return "${jalaliDate.hour.toString().padLeft(2, '0')}:${jalaliDate.minute.toString().padLeft(2, '0')} - ${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
  }

  String get formattedYHMS {
    return DateFormat('yyyy-MM-dd HH:mm:ss').format(toDateTime);
  }

  Jalali get toJalali {
    final dateTime = DateTime.parse(this);
    return Jalali.fromDateTime(dateTime);
  }

  int get versionNumber => int.parse(replaceAll(".", ''));
}
