export function pluralize(word, capitalizeFirst = false) {
  const irregularPlurals = {
    child: "children",
    person: "people",
    mouse: "mice",
    foot: "feet",
    tooth: "teeth",
    goose: "geese",
  };

  let pluralWord = irregularPlurals[word] || `${word}s`;

  if (capitalizeFirst) {
    pluralWord = pluralWord.charAt(0).toUpperCase() + pluralWord.slice(1);
  }

  return pluralWord;
}

export function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

export function singularize(word, capitalizeFirst = false) {
  const irregularSingulars = {
    children: "child",
    people: "person",
    mice: "mouse",
    feet: "foot",
    teeth: "tooth",
    geese: "goose",
  };

  word = word.replace(/_/g, ' ');

  // Check if the word is in the irregular singulars dictionary
  let singularWord = Object.keys(irregularSingulars).find(
    (plural) => plural === word
  )
    ? irregularSingulars[word]
    : word.endsWith("s")
      ? word.slice(0, -1) // Remove the trailing "s" for regular pluralization
      : word;

  // Capitalize the first letter if the option is enabled
  if (capitalizeFirst) {
    singularWord = singularWord.charAt(0).toUpperCase() + singularWord.slice(1);
  }

  return singularWord;
}

export function parseName(str, capitalizeFirst = true) {
  if (!str) return '';
  const lastWord = str.split('_').pop();
  if (capitalizeFirst) {
    return capitalize(lastWord);
  }

  return lastWord;
}

// Format URL
export function formatUrl(url) {
  return url?.startsWith("http") ? url : `//${url}`;
}