import { useEffect } from "react"
import { usePage } from "@inertiajs/react"
import useFormBuilder from "@/utils/useFormBuilder"
import FormBuilder from "@/Components/FormBuilder"
import { slugify, useSearchParams } from "@/utils/format"

function MainForm({ isEdit = false, formOptions = {}, BackButton = null }) {
  const formConfig = { isEdit, getProperties, formOptions }
  const builderProps = useFormBuilder(formConfig)
  const { data, setData } = builderProps.form

  return <FormBuilder {...builderProps} BackButton={BackButton} />
}

const getProperties = (state) => {
  const { props, data, setData } = state
  const { params } = useSearchParams(props.location)

  const properties = [
    [
      {
        form: "input",
        props: {
          name: "code",
          label: "Kode Bank",
          type: "text",
        },
      },
      {
        form: "input",
        props: {
          name: "name",
          label: "Nama Bank",
          type: "text",
        },
      },
      {
        form: "select",
        props: {
          name: "status",
          label: "Status",
          options: props.status,
          prefix: "bank.status",
        },
      },
      {
        form: "input",
        isHidden: true,
        props: {
          name: "limit_transfer_amount",
          label: "Limit Transfer",
          type: "tel",
        },
      },
    ],
    [
      {
        form: 'checkbox',
        props: {
          name: 'bi_fast',
          label: 'Mendukung BI Fast',
        }
      },
    ]
  ]

  return properties
}

const PropertiesProvider = ({ children }) => {
  return children(getProperties)
}

MainForm.PropertiesProvider = PropertiesProvider

const BankMainForm = MainForm
export default BankMainForm
