import dayjs from 'dayjs';
import _ from 'lodash';

export default {
  filesFormatter(arr) {
    if (!arr || !arr.length) return [];
    return arr.map((item) => item);
  },
  imageFormatter(arr) {
    if (!arr || !arr.length) return [];
    return arr.map((item) => ({
      publicUrl: item.publicUrl || '',
    }));
  },
  oneImageFormatter(arr) {
    if (!arr || !arr.length) return '';
    return arr[0].publicUrl || '';
  },
  dateFormatter(date) {
    if (!date) return '';
    return dayjs(date).format('YYYY-MM-DD');
  },
  dateTimeFormatter(date) {
    if (!date) return '';
    return dayjs(date).format('YYYY-MM-DD HH:mm');
  },
  booleanFormatter(val) {
    return val ? 'Yes' : 'No';
  },
  dataGridEditFormatter(obj) {
    return _.transform(obj, (result, value, key) => {
      if (_.isArray(value)) {
        result[key] = _.map(value, 'id');
      } else if (_.isObject(value)) {
        result[key] = value.id;
      } else {
        result[key] = value;
      }
    });
  },

  usersManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.firstName);
  },
  usersOneListFormatter(val) {
    if (!val) return '';
    return val.firstName;
  },
  usersManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.firstName };
    });
  },
  usersOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.firstName, id: val.id };
  },

  applicationsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.status);
  },
  applicationsOneListFormatter(val) {
    if (!val) return '';
    return val.status;
  },
  applicationsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.status };
    });
  },
  applicationsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.status, id: val.id };
  },

  benefit_plansManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.carrier);
  },
  benefit_plansOneListFormatter(val) {
    if (!val) return '';
    return val.carrier;
  },
  benefit_plansManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.carrier };
    });
  },
  benefit_plansOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.carrier, id: val.id };
  },

  billsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.invoice_no);
  },
  billsOneListFormatter(val) {
    if (!val) return '';
    return val.invoice_no;
  },
  billsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.invoice_no };
    });
  },
  billsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.invoice_no, id: val.id };
  },

  candidatesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  candidatesOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  candidatesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  candidatesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },

  compensationsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.base_pay);
  },
  compensationsOneListFormatter(val) {
    if (!val) return '';
    return val.base_pay;
  },
  compensationsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.base_pay };
    });
  },
  compensationsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.base_pay, id: val.id };
  },

  devicesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.serial);
  },
  devicesOneListFormatter(val) {
    if (!val) return '';
    return val.serial;
  },
  devicesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.serial };
    });
  },
  devicesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.serial, id: val.id };
  },

  documentsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.doc_type);
  },
  documentsOneListFormatter(val) {
    if (!val) return '';
    return val.doc_type;
  },
  documentsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.doc_type };
    });
  },
  documentsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.doc_type, id: val.id };
  },

  employeesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.user);
  },
  employeesOneListFormatter(val) {
    if (!val) return '';
    return val.user;
  },
  employeesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.user };
    });
  },
  employeesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.user, id: val.id };
  },

  employmentsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.employment_type);
  },
  employmentsOneListFormatter(val) {
    if (!val) return '';
    return val.employment_type;
  },
  employmentsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.employment_type };
    });
  },
  employmentsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.employment_type, id: val.id };
  },

  expense_reportsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.status);
  },
  expense_reportsOneListFormatter(val) {
    if (!val) return '';
    return val.status;
  },
  expense_reportsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.status };
    });
  },
  expense_reportsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.status, id: val.id };
  },

  job_requisitionsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.title);
  },
  job_requisitionsOneListFormatter(val) {
    if (!val) return '';
    return val.title;
  },
  job_requisitionsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.title };
    });
  },
  job_requisitionsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.title, id: val.id };
  },

  learning_coursesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.title);
  },
  learning_coursesOneListFormatter(val) {
    if (!val) return '';
    return val.title;
  },
  learning_coursesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.title };
    });
  },
  learning_coursesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.title, id: val.id };
  },

  payroll_runsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.country);
  },
  payroll_runsOneListFormatter(val) {
    if (!val) return '';
    return val.country;
  },
  payroll_runsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.country };
    });
  },
  payroll_runsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.country, id: val.id };
  },

  positionsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.title);
  },
  positionsOneListFormatter(val) {
    if (!val) return '';
    return val.title;
  },
  positionsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.title };
    });
  },
  positionsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.title, id: val.id };
  },

  review_cyclesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  review_cyclesOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  review_cyclesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  review_cyclesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },

  timecardsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.period);
  },
  timecardsOneListFormatter(val) {
    if (!val) return '';
    return val.period;
  },
  timecardsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.period };
    });
  },
  timecardsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.period, id: val.id };
  },

  vendorsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  vendorsOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  vendorsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  vendorsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },

  rolesManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  rolesOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  rolesManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  rolesOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },

  permissionsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  permissionsOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  permissionsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  permissionsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },

  organizationsManyListFormatter(val) {
    if (!val || !val.length) return [];
    return val.map((item) => item.name);
  },
  organizationsOneListFormatter(val) {
    if (!val) return '';
    return val.name;
  },
  organizationsManyListFormatterEdit(val) {
    if (!val || !val.length) return [];
    return val.map((item) => {
      return { id: item.id, label: item.name };
    });
  },
  organizationsOneListFormatterEdit(val) {
    if (!val) return '';
    return { label: val.name, id: val.id };
  },
};
