import { ValueProcessorItem } from '..'
import { Element } from '../../'
import helpers from '@/helpers'

export default class AutofillProcessor implements ValueProcessorItem {
  public processValue(element: Element, index: number, rootState: any, rootGetters: any) {
    if (element.autofill) {
      let locator = rootState
      let module = null
      let path = null

      if (element.autofill.startsWith('details.')) {
        module = 'memberModule'
        path = element.autofill.replace('details.', 'member.')
      }

      if (module && path) {
        element.autofill = helpers.getValue(locator, module + '.' + path)
      }
    }

    return element
  }
}
