/**
 * WordPress dependencies
 */
import { debounce } from '@wordpress/compose';
import { useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { ComboboxControl } from '@wordpress/components';

/**
 * Internal dependencies
 */
import { store as editorStore } from '../../store';
import { useAuthorsQuery } from './hook';
import { jsx as _jsx } from "react/jsx-runtime";
export default function PostAuthorCombobox() {
  const [fieldValue, setFieldValue] = useState();
  const {
    editPost
  } = useDispatch(editorStore);
  const {
    authorId,
    authorOptions,
    isLoading
  } = useAuthorsQuery(fieldValue);

  /**
   * Handle author selection.
   *
   * @param {number} postAuthorId The selected Author.
   */
  const handleSelect = postAuthorId => {
    if (!postAuthorId) {
      return;
    }
    editPost({
      author: postAuthorId
    });
  };
  return /*#__PURE__*/_jsx(ComboboxControl, {
    __nextHasNoMarginBottom: true,
    __next40pxDefaultSize: true,
    label: __('Author'),
    options: authorOptions,
    value: authorId,
    onFilterValueChange: debounce(setFieldValue, 300),
    onChange: handleSelect,
    allowReset: false,
    hideLabelFromVision: true,
    isLoading: isLoading
  });
}
//# sourceMappingURL=combobox.js.map