export const createFilterData = (filters) => {
  return (item) => {
    return Object.entries(filters).every(([key, value]) => {
      if (value === undefined || value === '') {
        return true;
      }

      switch (key) {
        case 'search':
          return (
            item.full_name?.toLowerCase().includes(value.toLowerCase()) ||
            item.email?.toLowerCase().includes(value.toLowerCase()) ||
            item.name?.toLowerCase().includes(value.toLowerCase()) ||
            item.title?.toLowerCase().includes(value.toLowerCase())
          );
        case 'is_active':
          return !value || item[key] === value;

        case 'ssp_id': {
          const orgUnits = item.org_units ?? [];
          const ssp_ids = orgUnits.map((s) => s.id);
          return ssp_ids.length > 0
            ? ssp_ids.includes(value)
            : value === null;
        }

        default:
          if (value === null) return true;
          return item[key] === value;
      }
    });
  };
};
