import PropTypes from 'prop-types'
import ObjectInfo from '../../common/ObjectInfo'
import NewObjectForm from '../../common/NewObjectForm'
import WizardView from '../../common/WizardView'

const NewListing = ({ onOk, defaultValues }) => {
  return (
    <NewObjectForm
      type={'listing'}
      defaultValues={{ status: 'draft', ...defaultValues }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='listing'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                labelWidth={133}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='listing'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='listing'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: false,
                  createdAt: false,
                  updatedAt: false,
                  lastSyncedAt: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Listing'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

NewListing.propTypes = {
  onOk: PropTypes.func.isRequired,
  reset: PropTypes.bool,
  defaultValues: PropTypes.object
}

export default NewListing
