/* eslint-disable @typescript-eslint/no-explicit-any */

import styles from './profile.module.scss'
import { useForm } from '@inertiajs/react'
import PersonalAccountInfo from './personal-info'
import { router } from '@inertiajs/react'

const Profile = ({ user }: any) => {

  const { data, setData, post } = useForm({
    name: user?.name || "",
    username: user?.username || "",
    email: user?.email || "",
    phone: user?.phone || "",
    gender: user?.gender || "",
    country: user?.country || "",
  })


const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
  e.preventDefault()

  const onSuccess = () => {
    router.reload({ only: ["flash"] })
  }

  post(route("dashboard.profile.update"), { onSuccess })
}

  return (
    <div className={styles['profile']}>
      <form onSubmit={handleSubmit}>
          <PersonalAccountInfo value={data} setData={setData} />
      </form>
    </div>
  )
}

export default Profile
