import { config, constants } from 'config/general';
import { insertInModel } from 'store/utils/adminHelpers';
import { addressModel } from './general';

const model = [
  {
    type: 'section',
    label: 'Infos',
    opened: true,
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true },
      {
        type: 'input',
        label: 'firstName',
        name: 'firstName',
      },
      {
        type: 'input',
        label: 'lastName',
        name: 'lastName',
      },
      {
        type: 'input',
        label: 'userName',
        name: 'userName',
      },
      {
        noUpdate: true,
        type: 'input',
        label: 'email',
        name: 'email',
      },
      {
        type: 'input',
        label: 'Phone Number',
        name: 'phoneNumber',
      },
      {
        type: 'select',
        label: 'gender',
        name: 'gender',
        values: ['m', 'f'],
      },
      {
        type: 'select',
        label: 'language',
        name: 'language',
        values: ['en', 'fr', 'nl'],
      },
      // {
      //   type: 'input',
      //   inputType: 'number',
      //   label: 'age',
      //   name: 'age',
      // },
      {
        type: 'picture',
        label: 'Profile Picture',
        name: 'profilePicture',
        asObject: true,
        displayValue: 'large',
        apollo: true,
      },
    ],
  },
  addressModel,
];

const options = {
  titleList: 'Accounts',
  titleDetail: 'Account',
  titleCreate: 'Add Account',
  titleUpdate: 'Edit Account',

  apollo: true,
  resourceList: 'accountsGetMany',
  resource: 'accountsGetOne',
  resourceUpdate: 'accountsEditOne',
  resourceCreate: 'accountsAddOne',
  resourceDelete: 'accountsDeleteOne',

  treatData: data => {
    if (data.age) data.age = parseFloat(data.age);
    // if (data.numberOfDays) data.numberOfDays = parseFloat(data.numberOfDays);
  },
  legend: {
    infos: {
      // info1: 'enabled',
    },
  },
  headers: [
    {
      title: 'firstName',
      key: 'firstName',
    },
    {
      title: 'lastName',
      key: 'lastName',
    },
    {
      title: 'email',
      key: 'email',
    },
  ],

  transformFunction: (obj): object => ({
    infos: {
      info1: obj.enabled,
    },
  }),
  model,
};

export default options;
