const { assign, join } = require('lodash')

const labels = require('../labels')
const {
  contact,
  provider,
  service,
  subject,
  notes,
  date,
  adviser,
} = require('./fields')

module.exports = function ({
  returnLink,
  contacts = [],
  advisers = [],
  services = [],
  tapServices = [],
  statuses = [],
  teams = [],
  events = [],
  hiddenFields,
}) {
  return {
    returnLink,
    buttonText: 'Save',
    returnText: 'Cancel',
    hiddenFields,
    children: [
      contact(contacts),
      provider(teams),
      adviser(advisers),
      // TODO this will be going once interactions are within events
      {
        macroName: 'MultipleChoiceField',
        type: 'radio',
        name: 'is_event',
        optional: true,
        modifier: 'inline',
        options: [
          {
            label: 'Yes',
            value: 'true',
          },
          {
            label: 'No',
            value: 'false',
          },
        ],
      },
      {
        macroName: 'MultipleChoiceField',
        name: 'event',
        initialOption: '-- Select event --',
        options: events,
        modifier: 'subfield',
        condition: {
          name: 'is_event',
          value: 'true',
        },
      },
      service(services),
      {
        macroName: 'MultipleChoiceField',
        name: 'service_delivery_status',
        initialOption: '-- Select service status --',
        options: statuses,
        optional: true,
        modifier: ['subfield', 'medium'],
        condition: {
          name: 'service',
          value: tapServices.join('||'),
        },
      },
      subject,
      notes,
      date,
    ].map(field => {
      return assign(field, {
        label: labels.serviceDelivery[field.name],
      })
    }),
  }
}

@@ -11,14 +11,8 @@
 sign
-, join
  %7D =
@@ -1588,24 +1588,277 @@
 %7D,%0A      %7D,%0A
+      %7B%0A        macroName: 'TextField',%0A        name: 'grant_amount_offered',%0A        optional: true,%0A        modifier: %5B'subfield', 'medium'%5D,%0A        condition: %7B%0A          name: 'service',%0A          value: tapServices.join('%7C%7C'),%0A        %7D,%0A      %7D,%0A
       subjec

Add grant offered form element to service delivery edit form