import clsx from 'clsx'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { PlusCircleIcon } from '@heroicons/react/solid'
import { parseWordsAsTags } from '../../../common/util/parse'
import { createFold } from '../../lib/firebase/api-call'
import { foldPath } from '../../lib/firebase/folds'
import { toCamelCase } from '../../../common/util/format'
import { ConfirmationButton } from '../confirmation-button'
import { Col } from '../layout/col'
import { Spacer } from '../layout/spacer'
import { TagsList } from '../tags-list'
import { Title } from '../title'
export function CreateFoldButton() {
const [name, setName] = useState('')
const [about, setAbout] = useState('')
const [otherTags, setOtherTags] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
const router = useRouter()
const tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags)
const updateName = (newName: string) => {
setName(newName)
}
const onSubmit = async () => {
setIsSubmitting(true)
const result = await createFold({
name,
tags,
about,
}).then((r) => r.data || {})
if (result.fold) {
await router.push(foldPath(result.fold)).catch((e) => {
console.log(e)
setIsSubmitting(false)
})
} else {
console.log(result.status, result.message)
setIsSubmitting(false)
}
}
return (