text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.CreateDocumentDialog = void 0;
  
  var _keyBy2 = _interopRequireDefault(require("lodash/keyBy"));
  
  var _react = _interopRequireWildcard(require("react"));
  
  var _ui = require("@sanity/ui");
  
  var _components = require("@sanity/base/components");
  
  var _hooks = require("@sanity/base/hooks");
  
  var _internal = require("@sanity/base/_internal");
  
  var _styledComponents = _interopRequireDefault(require("styled-components"));
  
  var _CreateDocumentItem = require("./CreateDocumentItem");
  
  var _templateObject;
  
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
  
  var List = _styledComponents.default.ul(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n  margin: 0;\n  padding: 0;\n  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));\n"])));
  
  var newDocumentOptions = (0, _internal.getNewDocumentOptions)();
  var CreateDocumentDialog = /*#__PURE__*/(0, _react.memo)(_ref => {
    var templatePermissions = _ref.templatePermissions,
        isTemplatePermissionsLoading = _ref.isTemplatePermissionsLoading,
        onClose = _ref.onClose;
    var keyedPermissions = (0, _react.useMemo)(() => (0, _keyBy2.default)(templatePermissions, 'id'), [templatePermissions]); // note: this hook is called once in this component and passed via props for
    // performance reasons
  
    var _useCurrentUser = (0, _hooks.useCurrentUser)(),
        currentUser = _useCurrentUser.value;
  
    var content = newDocumentOptions.length <= 0 ? /*#__PURE__*/_react.default.createElement(_ui.Box, {
      paddingY: 5
    }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
      weight: "semibold",
      align: "center"
    }, "No initial value templates are configured.")) : /*#__PURE__*/_react.default.createElement(_ui.Grid, {
      gap: 3,
      as: List
    }, newDocumentOptions.map(item => {
      var _keyedPermissions$ite;
  
      var granted = Boolean(!isTemplatePermissionsLoading && ((_keyedPermissions$ite = keyedPermissions[item.id]) === null || _keyedPermissions$ite === void 0 ? void 0 : _keyedPermissions$ite.granted));
      return /*#__PURE__*/_react.default.createElement(_ui.Box, {
        as: "li",
        key: item.id
      }, /*#__PURE__*/_react.default.createElement(_CreateDocumentItem.CreateDocumentItem, _extends({}, item, {
        granted: granted,
        currentUser: currentUser,
        onClick: onClose
      })));
    }));
    return /*#__PURE__*/_react.default.createElement(_components.LegacyLayerProvider, {
      zOffset: "navbarDialog"
    }, /*#__PURE__*/_react.default.createElement(_ui.Dialog, {
      "data-testid": "default-layout-global-create-dialog",
      id: "create-document-dialog",
      onClickOutside: onClose,
      onClose: onClose,
      width: 2,
      header: "Create new document"
    }, /*#__PURE__*/_react.default.createElement(_ui.Box, {
      padding: 4
    }, content)));
  });
  exports.CreateDocumentDialog = CreateDocumentDialog;
  CreateDocumentDialog.displayName = 'CreateDocumentDialog';