"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = PostAuthorCombobox;
var _compose = require("@wordpress/compose");
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _store = require("../../store");
var _hook = require("./hook");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function PostAuthorCombobox() {
  const [fieldValue, setFieldValue] = (0, _element.useState)();
  const {
    editPost
  } = (0, _data.useDispatch)(_store.store);
  const {
    authorId,
    authorOptions,
    isLoading
  } = (0, _hook.useAuthorsQuery)(fieldValue);

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