'use client';

import { useState } from 'react';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import useAuth from '@/hooks/useAuth';
import FeedComposer from './FeedComposer';

export default function FeedWriteButton() {
	const { loginCheck } = useAuth();
	const [open, setOpen] = useState(false);

	const handleClick = () => {
		if (!loginCheck()) {
			return;
		}
		setOpen(true);
	};

	return (
		<>
			<button type="button" className="feed__write-fab" onClick={handleClick}>
				글쓰기
			</button>

			<Dialog open={open} onOpenChange={setOpen}>
				<DialogContent className="feed__composer-dialog">
					<DialogHeader>
						<DialogTitle>피드 작성</DialogTitle>
					</DialogHeader>
					<FeedComposer onSubmitted={() => setOpen(false)} />
				</DialogContent>
			</Dialog>
		</>
	);
}