part of 'extension.dart';

extension StringX on String {
  String toTitleCase() {
    if (isEmpty) return '';
    return split(' ')
        .map((word) {
          if (word.isEmpty) return '';
          return word[0].toUpperCase() + word.substring(1).toLowerCase();
        })
        .join(' ');
  }

  int get toIntegerFromText {
    final cleanedText = replaceAll(RegExp(r'[^0-9]'), '');
    final parsedValue = int.tryParse(cleanedText) ?? 0;
    return parsedValue;
  }

  String get currencyFormatRpV2 {
    final parsedValue = int.tryParse(this) ?? 0;
    return NumberFormat.currency(
      locale: 'id',
      symbol: 'Rp ',
      decimalDigits: 0,
    ).format(parsedValue);
  }

  TableStatusType toTableStatusType() {
    switch (this) {
      case 'available':
        return TableStatusType.available;
      case 'occupied':
        return TableStatusType.occupied;
      default:
        return TableStatusType.unknown;
    }
  }

  VoidType toVoidType() {
    switch (this) {
      case 'ALL':
        return VoidType.all;
      case 'ITEM':
        return VoidType.item;
      default:
        return VoidType.unknown;
    }
  }

  SplitType toSplitType() {
    switch (this) {
      case 'AMOUNT':
        return SplitType.amount;
      case 'ITEM':
        return SplitType.item;
      default:
        return SplitType.unknown;
    }
  }
}
