"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.li = li;
exports.list = list;
var _react = _interopRequireDefault(require("react"));
var _List = require("@patternfly/react-core/dist/esm/components/List");
var _ProgressStepper = require("../../ProgressStepper");
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.
 */

function li(props) {
  if ((0, _ProgressStepper.isProgressStepCompatible)(props)) {
    return _react.default.createElement(_ProgressStepper.ProgressStep, {
      className: props.className,
      title: props.children[0],
      liveStatusChannel: (0, _ProgressStepper.liveStatusChannel)(props),
      defaultStatus: props.children[2].props.children[0]
    }, props.children.slice(3));
  } else {
    return _react.default.createElement(_List.ListItem, {
      className: props.className
    }, props.children);
  }
}
function list(props) {
  if (Array.isArray(props.children) && props.children.length > 0) {
    // react-markdown v7 seems to add newlines between list items. weird
    const children = props.children.filter(_ => _ !== '\n');
    const lastIncompatibleIdx = children.findIndex(_ => {
      if (typeof _ === 'object' && (0, _ProgressStepper.isProgressStepCompatible)(_['props'])) {
        // this is a true ProgressStep, created in the <a> handler below
        return false; // compatible
      } else {
        return true; // incompatible with ProgressStepper component
      }
    });

    if (lastIncompatibleIdx === -1) {
      return _react.default.createElement(_ProgressStepper.ProgressStepper, {
        layout: props.ordered ? 'horizontal' : 'vertical',
        className: "kui--markdown-major-paragraph"
      }, props.children);
    } else if (lastIncompatibleIdx >= 0) {
      return _react.default.createElement(_react.default.Fragment, null, lastIncompatibleIdx > 0 && _react.default.createElement(_ProgressStepper.ProgressStepper, {
        layout: props.ordered ? 'horizontal' : 'vertical'
      }, props.children.slice(0, lastIncompatibleIdx)), _react.default.createElement(_List.List, {
        start: props['start'],
        component: props.ordered ? _List.ListComponent.ol : _List.ListComponent.ul
      }, props.children.slice(lastIncompatibleIdx)));
    }
  }
  return _react.default.createElement(_List.List, {
    start: props['start'],
    component: props.ordered ? _List.ListComponent.ol : _List.ListComponent.ul
  }, props.children);
}