import config from 'config/general';

const eventType = [
  { value: 'formation', label: 'Formation' },
  { value: 'conference', label: 'Conference' },
  { value: 'webinar', label: 'Webinar' },
  { value: 'hybrid', label: 'Hybride' },
];

const eventFormat = [
  { value: 'online', label: 'Online' },
  { value: 'offline', label: 'Offline' },
];

const marketingInfoPlateform = [{ value: 'ac', label: 'Active Campaign' }];

function renderListLanguage() {
  const array = [];
  if (config && config.availableLanguages) {
    config.availableLanguages.forEach(element => {
      array.push({
        value: element,
        label: element,
      });
    });
  }

  return array;
}

// PARTNER MODEL
const modelPartner = {
  section: {
    type: 'section',
    label: 'Partner',
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true, noMutation: true, noCreate: true },
      // {
      //   type: 'select',
      //   apollo:true,
      //   label: 'Organisation',
      //   name: 'organisationId',
      //   noDetail: true,
      //   api: {
      //     resource: 'articleCategories',
      //   },
      //   modelValues: {
      //     value: '_id',
      //     text: { value: 'title', translatable: true },
      //   },
      //   noFilterApi: true,
      // },
      {
        type: 'date',
        label: 'createdAt',
        name: 'createdAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'date',
        label: 'updatedAt',
        name: 'updatedAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      { type: 'string', label: 'name', name: 'name', required: true },
      { type: 'string', label: 'website (url)', name: 'websiteUrl' },
      { type: 'string', label: 'linkedin (url)', name: 'linkedinUrl' },
      {
        type: 'picture',
        label: 'image',
        name: 'image',
        displayValue: 'large',
        asObject: true,
        apollo: true,
      },
      { type: 'multiwysiwyg', label: 'Bio', name: 'bio' },
    ],
  },
};

// SPEAKER MODEL
const speakerModel = [
  {
    type: 'section',
    label: 'Speaker',
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true, noMutation: true, noCreate: true },
      // {
      //   type: 'select',
      //   apollo:true,
      //   label: 'Organisation',
      //   name: 'organisationId',
      //   noDetail: true,
      //   api: {
      //     resource: 'articleCategories',
      //   },
      //   modelValues: {
      //     value: '_id',
      //     text: { value: 'title', translatable: true },
      //   },
      //   noFilterApi: true,
      // },
      {
        type: 'date',
        label: 'createdAt',
        name: 'createdAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'date',
        label: 'updatedAt',
        name: 'updatedAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      { type: 'string', label: 'firstName', name: 'firstName', required: true },
      { type: 'string', label: 'lastName', name: 'lastName', required: true },
      {
        type: 'picture',
        label: 'profile Picture',
        name: 'profilePicture',
        displayValue: 'large',
        asObject: true,
        apollo: true,
      },
      { type: 'string', label: 'website (url)', name: 'website' },
      { type: 'string', label: 'linkedIn (url)', name: 'linkedIn' },
      { type: 'multi', label: 'job', name: 'jobTitle' },
      { type: 'string', label: 'company', name: 'companyName' },
      { type: 'multiwysiwyg', label: 'Bio', name: 'content' },
    ],
  },
  {
    type: 'section',
    label: 'Settings',
    side: true,
    fields: [{ type: 'multi', label: 'urls', name: 'urls' }],
  },
  {
    type: 'section',
    label: 'SEO',
    side: true,
    fields: [
      { type: 'multi', label: 'title', name: 'seo.title' },
      { type: 'multi', label: 'description', name: 'seo.description' },
      { type: 'multi', label: 'keywords', name: 'seo.keywords' },
    ],
  },
];

// VENUE MODEL
const venueModel = {
  section: {
    type: 'section',
    label: 'Venue',
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true, noMutation: true, noCreate: true },
      // {
      //   type: 'select',
      //   apollo:true,
      //   label: 'Organisation',
      //   name: 'organisationId',
      //   noDetail: true,
      //   api: {
      //     resource: 'articleCategories',
      //   },
      //   modelValues: {
      //     value: '_id',
      //     text: { value: 'title', translatable: true },
      //   },
      //   noFilterApi: true,
      // },
      {
        type: 'date',
        label: 'createdAt',
        name: 'createdAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'date',
        label: 'updatedAt',
        name: 'updatedAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      { type: 'string', label: 'name', name: 'name', required: true },
      { type: 'string', label: 'number', name: 'address.number' },
      { type: 'string', label: 'street', name: 'address.street' },
      { type: 'string', label: 'zip', name: 'address.zip', required: true },
      { type: 'string', label: 'state', name: 'address.state' },
      { type: 'string', label: 'city', name: 'address.city', required: true },
      { type: 'string', label: 'country', name: 'address.country', required: true },
    ],
  },
};

// CATEGORIE MODEL
const categorieModel = [
  {
    type: 'section',
    label: 'Categorie',
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true },
      {
        type: 'text',
        label: 'type',
        name: 'ressourceType',
        initialValue: 'events',
      },
      { type: 'multi', label: 'title', name: 'title', required: true },
      { type: 'color', label: 'Color', name: 'colorCode', saveValue: 'hex' },
      { type: 'multiwysiwyg', label: 'Content', name: 'content' },
    ],
  },
];

// EVENT MODEL
const eventModel = [
  {
    type: 'section',
    label: 'Event Info',
    fields: [
      { type: 'text', label: 'Id', name: '_id', noUpdate: true, noMutation: true, noCreate: true },
      // {
      //   type: 'select',
      //   apollo:true,
      //   label: 'Organisation',
      //   name: 'organisationId',
      //   noDetail: true,
      //   api: {
      //     resource: 'articleCategories',
      //   },
      //   modelValues: {
      //     value: '_id',
      //     text: { value: 'title', translatable: true },
      //   },
      //   noFilterApi: true,
      // },
      {
        type: 'date',
        label: 'createdAt',
        name: 'createdAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'date',
        label: 'updatedAt',
        name: 'updatedAt',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'date',
        label: 'publication date',
        name: 'publicationDate',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'bool',
        label: 'published',
        name: 'published',
        noCreate: true,
        noUpdate: true,
        noMutation: true,
      },
      {
        type: 'bool',
        label: 'private',
        name: 'private',
      },
      { type: 'multi', label: 'title', name: 'title', required: true },
      { type: 'multiarea', label: 'teaser', name: 'teaser' },
      { type: 'multiwysiwyg', label: 'content', name: 'content' },
      { type: 'string', label: 'accreditation', name: 'accreditation' },
      {
        type: 'picture',
        label: 'Cover',
        name: 'cover',
        apollo: true,
        asObject: true,
        displayValue: 'large',
      },
      {
        type: 'picture',
        label: 'thumbnail',
        name: 'thumbnail',
        apollo: true,
        asObject: true,
        displayValue: 'large',
      },
      {
        type: 'select',
        apollo: true,
        label: 'type',
        name: 'type',
        list: eventType,
        required: true,
      },
      {
        type: 'select',
        apollo: true,
        label: 'format',
        name: 'format',
        list: eventFormat,
        required: true,
      },
      {
        type: 'datetime',
        dateFormat: 'DD/MM/YYYY',
        timeFormat: 'HH:mm',
        label: 'start Date',
        name: 'startDate',
      },
      {
        type: 'datetime',
        dateFormat: 'DD/MM/YYYY',
        timeFormat: 'HH:mm',
        label: 'end Date',
        name: 'endDate',
      },
      { type: 'multiarea', label: 'testimonial', name: 'testimonials' },
      {
        type: 'file',
        apollo: true,
        accept: 'application/*',
        label: 'Support',
        name: 'supports',
        displayValue: 'large',
        asObject: true,
      },
      {
        type: 'file',
        apollo: true,
        accept: 'application/*',
        label: 'Program',
        name: 'program',
        displayValue: 'large',
        asObject: true,
      },
    ],
  },
  {
    type: 'section',
    label: 'Partners',
    fields: [
      {
        type: 'select',
        apollo: true,
        label: 'partners',
        name: 'partnerIds',
        noDetail: true,
        multiple: true,
        api: {
          resource: 'partnersGetMany',
        },
        modelValues: {
          value: '_id',
          text: 'name',
        },
        noFilterApi: true,
      },
      {
        noUpdate: true,
        noCreate: true,
        noMutation: true,
        type: 'list',
        name: 'getPartners',
        noLabel: true,
        fields: [
          {
            noMargin: true,
            type: 'string',
            name: 'name',
            label: 'name',
          },
        ],
      },
    ],
  },
  {
    type: 'section',
    label: 'Tickets',
    fields: [
      {
        type: 'select',
        apollo: true,
        label: 'tickets',
        name: 'ticketIds',
        noDetail: true,
        multiple: true,
        api: {
          resource: 'productsGetMany',
        },
        inputs: {
          productType: 'tickets',
        },
        modelValues: {
          value: '_id',
          text: 'title.en',
        },
        noFilterApi: true,
      },
      {
        noUpdate: true,
        noCreate: true,
        type: 'list',
        noMutation: true,
        name: 'getTickets',
        noLabel: true,
        fields: [
          {
            type: 'string',
            name: '_id',
            noCreate: true,
            noUpdate: true,
            noDetail: true,
          },
          {
            noMargin: true,
            type: 'multi',
            name: 'title',
            label: 'title',
          },
          {
            type: 'string',
            name: 'price',
            label: 'price',
          },
        ],
      },
    ],
  },
  {
    type: 'section',
    label: 'Speakers',
    fields: [
      {
        type: 'select',
        apollo: true,
        label: 'speakers',
        name: 'speakerIds',
        noDetail: true,
        multiple: true,
        api: {
          resource: 'speakersGetMany',
        },
        modelValues: {
          value: '_id',
          text: 'firstName',
          complementary: 'lastName',
        },
        noFilterApi: true,
      },
      {
        noUpdate: true,
        noCreate: true,
        type: 'list',
        name: 'getSpeakers',
        noMutation: true,
        noLabel: true,
        fields: [
          {
            noMargin: true,
            type: 'string',
            name: 'firstName',
            label: 'firstName',
          },
          {
            type: 'string',
            name: 'lastName',
            label: 'lastName',
          },
          {
            type: 'multi',
            name: 'jobTitle',
            label: 'job',
          },
        ],
      },
    ],
  },
  {
    type: 'section',
    label: 'Venue',
    fields: [
      {
        type: 'select',
        apollo: true,
        label: 'venue',
        name: 'venueId',
        noDetail: true,
        api: {
          resource: 'venuesGetMany',
        },
        modelValues: {
          value: '_id',
          text: 'name',
        },
        noFilterApi: true,
      },
      {
        type: 'string',
        name: 'getVenue.name',
        label: 'name',
        noUpdate: true,
        noCreate: true,
      },
    ],
  },
  {
    type: 'section',
    label: 'Categorie',
    fields: [
      {
        type: 'select',
        apollo: true,
        label: 'Categories',
        name: 'categoryIds',
        noDetail: true,
        multiple: true,
        api: {
          resource: 'categoriesGetMany',
        },
        inputs: {
          ressourceType: 'events',
        },
        modelValues: {
          value: '_id',
          text: { value: 'title', translatable: true },
        },
        noFilterApi: true,
      },
      {
        noUpdate: true,
        noCreate: true,
        noLabel: true,
        type: 'list',
        name: 'getCategories',
        fields: [
          {
            noMargin: true,
            type: 'multi',
            name: 'title',
            label: 'title',
          },
        ],
      },
    ],
  },
  {
    type: 'section',
    label: 'Settings',
    side: true,
    fields: [
      { type: 'multi', label: 'urls', name: 'urls' },
      { type: 'string', label: 'code', name: 'eventCode' },
      {
        type: 'select',
        apollo: true,
        label: 'languages',
        name: 'language',
        list: renderListLanguage(),
      },
      {
        type: 'string',
        inputType: 'number',
        label: 'credits',
        name: 'credits',
      },
      {
        type: 'select',
        apollo: true,
        label: 'platform',
        name: 'marketingInfo.platform',
        list: marketingInfoPlateform,
      },
      { type: 'string', label: 'participant List Id', name: 'marketingInfo.participantListId' },
      {
        type: 'string',
        label: 'download Ressources List Id',
        name: 'marketingInfo.downloadRessourcesListId',
      },
    ],
  },
  {
    type: 'section',
    label: 'SEO',
    side: true,
    fields: [
      { type: 'multi', label: 'title', name: 'seo.title' },
      { type: 'multi', label: 'description', name: 'seo.description' },
      { type: 'multi', label: 'keywords', name: 'seo.keywords' },
      {
        type: 'picture',
        label: 'thumbnail',
        name: 'seo.thumbnail',
        displayValue: 'large',
        asObject: true,
        apollo: true,
      },
    ],
  },
];

const participantFields = [
  {
    label: 'title',
    name: 'title',
    type: 'select',
    required: true,
    values: ['ms', 'mrs', 'mr'],
  },
  {
    label: 'firstName',
    name: 'firstName',
    type: 'string',
    required: true,
  },
  {
    label: 'lastName',
    name: 'lastName',
    type: 'string',
    required: true,
  },
  {
    label: 'company',
    name: 'company',
    type: 'string',
    required: true,
  },
  {
    label: 'function',
    name: 'function',
    type: 'string',
    required: true,
  },
  {
    label: 'email',
    name: 'email',
    type: 'string',
    required: true,
  },
  {
    label: 'phone',
    name: 'phone',
    type: 'string',
    required: true,
  },
];

export default {
  participantFields,
  partners: {
    listMethod: 'partnersGetMany',
    detailMethod: 'partnersGetOne',
    addMethod: 'partnersAddOne',
    editMethod: 'partnersEditOne',
    deleteMethod: 'partnersDeleteOne',
    titleList: 'Partners',
    headers: [{ title: 'Name', key: 'name' }],
    model: modelPartner,
  },
  categories: {
    detailMethod: 'categoriesGetOne',
    addMethod: 'categoriesAddOne',
    editMethod: 'categoriesEditOne',
    deleteMethod: 'categoriesDeleteOne',
    listMethod: 'categoriesGetMany',
    titleList: 'Categories',
    inputModel: {
      ressourceType: 'events',
    },
    headers: [{ title: 'Title', key: `title.${config.defaultLanguage}` }],
    model: categorieModel,
  },
  speakers: {
    listMethod: 'speakersGetMany',
    detailMethod: 'speakersGetOne',
    addMethod: 'speakersAddOne',
    editMethod: 'speakersEditOne',
    deleteMethod: 'speakersDeleteOne',
    titleList: 'Speakers',
    headers: [
      { title: 'First Name', key: 'firstName' },
      { title: 'Last Name', key: 'lastName' },
      { title: 'Job', key: `jobTitle.${config.defaultLanguage}` },
    ],
    model: speakerModel,
  },
  venues: {
    listMethod: 'venuesGetMany',
    detailMethod: 'venuesGetOne',
    addMethod: 'venuesAddOne',
    editMethod: 'venuesEditOne',
    deleteMethod: 'venuesDeleteOne',
    titleList: 'Venues',
    headers: [{ title: 'Name', key: 'name' }],
    model: venueModel,
  },
  events: {
    listMethod: 'eventsGetMany',
    detailMethod: 'eventsGetOne',
    addMethod: 'eventsAddOne',
    editMethod: 'eventsEditOne',
    deleteMethod: 'eventsDeleteOne',
    titleList: 'Events',
    editTitle: 'Edit Event',
    addTitle: 'Add Event',
    sort: 'startDate DESC',
    headers: [
      { title: 'Title', key: `title.${config.defaultLanguage}` },
      { title: 'Published', key: 'published' },
      { title: 'Private', key: 'private' },
      { title: 'Start Date', key: 'startDate', type: 'date' },
    ],
    treatData: data => {
      if (data.credits) data.credits = parseInt(data.credits, 10);
      return data;
    },
    model: eventModel,
  },
};
