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

const NewFilamentSku = ({ onOk, reset, defaultValues }) => {
  return (
    <NewObjectForm
      type='filamentSku'
      reset={reset}
      defaultValues={{
        overrideCost: false,
        color: '#ff0000',
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        console.log('objectData', objectData)
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='filamentSku'
                column={1}
                labelWidth={80}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{
                  description: false,
                  cost: false,
                  costWithTax: false,
                  costTaxRate: false,
                  overrideCost: false,
                  vendor: false
                }}
              />
            )
          },
          {
            title: 'Cost',
            key: 'cost',
            content: (
              <ObjectInfo
                type='filamentSku'
                column={1}
                labelWidth={120}
                required={true}
                visibleProperties={{
                  overrideCost: true,
                  cost: true,
                  costTaxRate: true,
                  costWithTax: true
                }}
                bordered={false}
                isEditing={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='filamentSku'
                column={1}
                labelWidth={110}
                visibleProperties={{
                  barcode: true,
                  description: true
                }}
                bordered={false}
                isEditing={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='filamentSku'
                column={1}
                visibleProperties={{
                  createdAt: false,
                  updatedAt: false,
                  _id: false,
                  _reference: false
                }}
                bordered={false}
                isEditing={false}
                labelWidth={120}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Filament SKU'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewFilamentSku
