"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _utils = require("@teamix/utils");

var _excluded = ["sticky", "container", "onAffix"];

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var initializeButton = function initializeButton(item) {
  var component = item.component,
      _item$props = item.props,
      props = _item$props === void 0 ? {} : _item$props;
  var buttonTextMap = {
    Submit: (0, _utils.getMessage)('submit'),
    Reset: (0, _utils.getMessage)('reset')
  };
  return _objectSpread(_objectSpread({}, item), {}, {
    component: component,
    props: _objectSpread({
      children: buttonTextMap[component]
    }, props)
  });
};

var initialize = function initialize(item) {
  var component = item.component,
      _item$props2 = item.props,
      props = _item$props2 === void 0 ? {} : _item$props2,
      _item$decoratorProps = item.decoratorProps,
      decoratorProps = _item$decoratorProps === void 0 ? {} : _item$decoratorProps;

  var sticky = props.sticky,
      container = props.container,
      onAffix = props.onAffix,
      otherProps = _objectWithoutProperties(props, _excluded); // 单个按钮


  if (component && ['Submit', 'Reset'].includes(component)) {
    return initializeButton(item);
  }

  var commonMode = _objectSpread(_objectSpread({}, item), {}, {
    component: component,
    props: otherProps,
    decorator: 'FormButtonGroup.FormItem',
    decoratorProps: _objectSpread({
      inset: false,
      fullness: true,
      className: (0, _utils.cls)('teamix-button-group-item', decoratorProps === null || decoratorProps === void 0 ? void 0 : decoratorProps.className)
    }, decoratorProps)
  }); // 吸底模式


  if (['auto', 'always'].includes(sticky)) {
    var stickyProps = {};

    if (sticky === 'auto') {
      stickyProps = {
        className: 'teamix-pro-form-button-affix-auto',
        offsetBottom: 0
      };
    }

    if (sticky === 'always') {
      stickyProps = {
        className: 'teamix-pro-form-button-affix-always',
        offsetBottom: 9999
      };
    }

    return {
      component: 'Affix',
      props: _objectSpread({
        container: container,
        onAffix: onAffix
      }, stickyProps),
      children: [commonMode]
    };
  } // 普通模式


  return commonMode;
};

var _default = initialize;
exports.default = _default;