import { Wrapper } from './wrapper'
const { h, matter } = globalThis.ami

function getDatetimeFieldType (field) {
  if (field.date_format && field.time_format) {
    return 'datetime-local'
  } else if (field.time_format) {
    return 'time'
  } else {
    return 'date'
  }
}

export function DateTime ({ field }) {
  return h(Wrapper, { field },
    h(matter.Input, {
      ...field.attrs,
      type: getDatetimeFieldType(field),
      'data-label': field.label
    })
  )
}
