import { useState, useCallback } from "react";

interface UseSheetOptions {
  defaultOpen?: boolean;
}

export function useSheet(options: UseSheetOptions = {}) {
  const [isOpen, setIsOpen] = useState(options.defaultOpen ?? false);

  const open = useCallback(() => setIsOpen(true), []);
  const close = useCallback(() => setIsOpen(false), []);
  const toggle = useCallback(() => setIsOpen((prev) => !prev), []);

  return {
    isOpen,
    open,
    close,
    toggle,
    props: {
      opened: isOpen,
      onChange: setIsOpen,
    },
  };
}
