"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = EntityRecordItem;
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _htmlEntities = require("@wordpress/html-entities");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
var _getTemplateInfo = require("../../utils/get-template-info");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function EntityRecordItem({
  record,
  checked,
  onChange
}) {
  const {
    name,
    kind,
    title,
    key
  } = record;

  // Handle templates that might use default descriptive titles.
  const {
    entityRecordTitle,
    hasPostMetaChanges
  } = (0, _data.useSelect)(select => {
    var _select$getEntityReco;
    if ('postType' !== kind || 'wp_template' !== name) {
      return {
        entityRecordTitle: title,
        hasPostMetaChanges: (0, _lockUnlock.unlock)(select(_store.store)).hasPostMetaChanges(name, key)
      };
    }
    const template = select(_coreData.store).getEditedEntityRecord(kind, name, key);
    const {
      default_template_types: templateTypes = []
    } = (_select$getEntityReco = select(_coreData.store).getEntityRecord('root', '__unstableBase')) !== null && _select$getEntityReco !== void 0 ? _select$getEntityReco : {};
    return {
      entityRecordTitle: (0, _getTemplateInfo.getTemplateInfo)({
        template,
        templateTypes
      }).title,
      hasPostMetaChanges: (0, _lockUnlock.unlock)(select(_store.store)).hasPostMetaChanges(name, key)
    };
  }, [name, kind, title, key]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.PanelRow, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CheckboxControl, {
        __nextHasNoMarginBottom: true,
        label: (0, _htmlEntities.decodeEntities)(entityRecordTitle) || (0, _i18n.__)('Untitled'),
        checked: checked,
        onChange: onChange
      })
    }), hasPostMetaChanges && /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
      className: "entities-saved-states__changes",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
        children: (0, _i18n.__)('Post Meta.')
      })
    })]
  });
}
//# sourceMappingURL=entity-record-item.js.map