"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useEditedEntityRecord;
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _editor = require("@wordpress/editor");
var _htmlEntities = require("@wordpress/html-entities");
var _store = require("../../store");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function useEditedEntityRecord(postType, postId) {
  const {
    record,
    title,
    description,
    isLoaded,
    icon
  } = (0, _data.useSelect)(select => {
    const {
      getEditedPostType,
      getEditedPostId
    } = select(_store.store);
    const {
      getEditedEntityRecord,
      hasFinishedResolution
    } = select(_coreData.store);
    const {
      __experimentalGetTemplateInfo: getTemplateInfo
    } = select(_editor.store);
    const usedPostType = postType !== null && postType !== void 0 ? postType : getEditedPostType();
    const usedPostId = postId !== null && postId !== void 0 ? postId : getEditedPostId();
    const _record = getEditedEntityRecord('postType', usedPostType, usedPostId);
    const _isLoaded = usedPostId && hasFinishedResolution('getEditedEntityRecord', ['postType', usedPostType, usedPostId]);
    const templateInfo = getTemplateInfo(_record);
    return {
      record: _record,
      title: templateInfo.title,
      description: templateInfo.description,
      isLoaded: _isLoaded,
      icon: templateInfo.icon
    };
  }, [postType, postId]);
  return {
    isLoaded,
    icon,
    record,
    getTitle: () => title ? (0, _htmlEntities.decodeEntities)(title) : null,
    getDescription: () => description ? (0, _htmlEntities.decodeEntities)(description) : null
  };
}
//# sourceMappingURL=index.js.map