"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Segmented = void 0;
var _tslib = require("tslib");
var _classnames = _interopRequireDefault(require("classnames"));
var _rcSegmented = _interopRequireDefault(require("rc-segmented"));
var React = _interopRequireWildcard(require("react"));
var _nativeProps = require("../../utils/native-props");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function isSegmentedLabeledOptionWithIcon(option) {
  return typeof option === 'object' && !!(option === null || option === void 0 ? void 0 : option.icon);
}
const classPrefix = `adm-segmented`;
const Segmented = exports.Segmented = React.forwardRef((props, ref) => {
  const {
      prefixCls: customizePrefixCls,
      className,
      block,
      options = []
    } = props,
    restProps = (0, _tslib.__rest)(props
    // syntactic sugar to support `icon` for Segmented Item
    , ["prefixCls", "className", "block", "options"]);
  // syntactic sugar to support `icon` for Segmented Item
  const extendedOptions = React.useMemo(() => options.map(option => {
    if (isSegmentedLabeledOptionWithIcon(option)) {
      const {
          icon,
          label
        } = option,
        restOption = (0, _tslib.__rest)(option, ["icon", "label"]);
      return Object.assign(Object.assign({}, restOption), {
        label: React.createElement(React.Fragment, null, React.createElement("span", {
          className: `${classPrefix}-item-icon`
        }, icon), label && React.createElement("span", null, label))
      });
    }
    return option;
  }), [options, classPrefix]);
  return (0, _nativeProps.withNativeProps)(props, React.createElement(_rcSegmented.default, Object.assign({}, restProps, {
    className: (0, _classnames.default)(className, {
      [`${classPrefix}-block`]: block
    }),
    options: extendedOptions,
    ref: ref,
    prefixCls: classPrefix
  })));
});
if (process.env.NODE_ENV !== 'production') {
  Segmented.displayName = 'Segmented';
}