"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = divWrapper;
var _react = _interopRequireDefault(require("react"));
var _parser = require("madwizard/dist/parser");
var _SplitInjector = _interopRequireDefault(require("../../../Views/Terminal/SplitInjector"));
var _tabbed2 = _interopRequireWildcard(require("./tabbed"));
var _KuiFrontmatter = require("../KuiFrontmatter");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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 }; }
/*
 * Copyright 2021 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const Wizard = _react.default.lazy(() => Promise.resolve().then(() => require('./Wizard')));
const ReactCommentary = _react.default.lazy(() => Promise.resolve().then(() => require('../../Commentary')).then(_ => ({
  default: _.ReactCommentary
})));
function divWrapper(mdprops, uuid, choices) {
  const tabbed = (0, _tabbed2.default)(uuid, choices);
  return function div(props) {
    const maximized = props['data-kui-maximized'] === 'true';
    const position = props['data-kui-split'];
    const placeholder = props['data-kui-placeholder'];
    const count = typeof props['data-kui-split-count'] === 'number' ? props['data-kui-split-count'] : props['data-kui-split-count'] ? parseInt(props['data-kui-split-count'], 10) : undefined;
    // Important! Default to `undefined` so that we pick up the
    // *default* behavior from the Terminal component
    const hasActiveInput = position === 'terminal' || undefined;
    const inverseColors = props['data-kui-inverse-colors'] === 'true' || undefined;
    if ((0, _tabbed2.isTabs)(props)) {
      return tabbed(props);
    } else if (!position || ((0, _KuiFrontmatter.isNormalSplit)(position) || position === 'wizard') && count === 0 && !maximized && !placeholder) {
      // don't create a split if a position wasn't indicated, or if
      // this is the first default-positioned section; if it is
      // maximized, we'll have to go through the injector path
      const node = (0, _parser.isWizard)(props) ? _react.default.createElement(Wizard, Object.assign({
        uuid: uuid
      }, props, {
        choices: choices
      })) : _react.default.createElement("div", {
        "data-is-maximized": maximized || undefined
      }, props.children);
      if (!maximized && (!mdprops.tab || hasActiveInput !== true && hasActiveInput !== false)) {
        return node;
      } else {
        // modify the current split to have the desired properties
        return _react.default.createElement(_SplitInjector.default.Consumer, null, injector => injector.modify(mdprops.tab.uuid, node, {
          hasActiveInput,
          inverseColors,
          maximized
        }));
      }
    } else {
      // then we have a section that targets a given split position
      return _react.default.createElement(_SplitInjector.default.Consumer, null, injector => {
        const node = _react.default.createElement(ReactCommentary, null, _react.default.createElement("div", {
          className: "padding-content marked-content page-content",
          "data-is-nested": true
        }, (0, _parser.isWizard)(props) ? _react.default.createElement(Wizard, Object.assign({
          uuid: uuid
        }, props, {
          choices: choices
        })) : props.children || (placeholder ? _react.default.createElement("span", {
          className: "italic sub-text"
        }, placeholder) : '')));
        const positionForView = position === 'terminal' || position === 'wizard' ? 'default' : position;
        setTimeout(() => injector.inject([{
          uuid,
          node,
          position: positionForView + ((0, _KuiFrontmatter.isNormalSplit)(positionForView) ? '' : '-strip'),
          count,
          opts: {
            inverseColors,
            hasActiveInput,
            maximized
          }
        }]));
        return _react.default.createElement(_react.default.Fragment, null);
      });
    }
  };
}