// TODO: i18n?
const salutations = [
  'Mr',
  'Mrs',
  'Miss',
  'Dr',
  'Ms',
  'Prof',
  'Rev',
  'Lady',
  'Sir',
  'Capt',
  'Major',
  'Col',
  'Lady',
  'The Hon',
  'Cmdr',
  'Brgdr',
  'Judge',
  'Lord',
  'Group Capt',
  'Revd Canon',
  'Air Cdre',
  'Viscount',
  'Dame',
  'Rear Admrl',
];

RemoveSalutationFilterFactory.$inject = ['$filter'];

export default function RemoveSalutationFilterFactory($filter) {
  return function removeSalutationFilter(str) {
    let nameParts = str.trim().split(' ');

    if (salutations.indexOf($filter('titleCase')(nameParts[0]).replace('.', '')) !== -1) {
      nameParts = nameParts.slice(1, nameParts.length);
    }

    return nameParts.join(' ');
  };
}
