import React, { useState } from 'react'
import { isEmpty } from 'lodash'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import FormInput from '@/Components/FormInput'
import Button from '@/Components/Button'
import { Head, useForm } from '@inertiajs/react'
import FormInputWith from '@/Components/FormInputWith'
import LocationSelectionInput from '../Location/SelectionInput'
import TextArea from '@/Components/TextArea'
import Checkbox from '@/Components/Checkbox'
export default function Import(props) {
const { levels } = props
const [use_level, setUseLevel] = useState(false)
const { data, setData, post, processing, errors } = useForm({
script: '',
discount: 0,
display_price: 0,
price_poin: 0,
expired: '',
expired_unit: 'Hari',
location_id: null,
prices: null,
})
const handleUseLevel = () => {
setUseLevel(!use_level)
if (!use_level === true) {
const prices = levels.map((level) => {
return {
name: level.name,
customer_level_id: level.id,
display_price: '0',
}
})
setData('prices', prices)
return
}
setData('prices', null)
}
const handleSetLevelPrice = (id, value) => {
setData(
'prices',
data.prices.map((price) => {
if (price.customer_level_id === id) {
return {
...price,
display_price: value,
}
}
return price
})
)
}
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleSubmit = () => {
post(route('voucher.import'))
}
return (
{errors.prices}
)}