import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { genComponentStyleHook, mergeToken } from '../../theme';
import { resetComponent, textEllipsis } from '../../style';
// ============================== Mixins ==============================
function segmentedDisabledItem(cls, token) {
  return _defineProperty({}, "".concat(cls, ", ").concat(cls, ":hover, ").concat(cls, ":focus"), {
    color: token.colorTextDisabled,
    cursor: 'not-allowed'
  });
}
function getSegmentedItemSelectedStyle(token) {
  return {
    backgroundColor: token.bgColorSelected,
    boxShadow: token.boxShadow
  };
}
var segmentedTextEllipsisCss = _extends({
  overflow: 'hidden'
}, textEllipsis);
// ============================== Styles ==============================
var genSegmentedStyle = function genSegmentedStyle(token) {
  var _$concat, _lg, _sm, _extends2, _extends4;
  var componentCls = token.componentCls;
  return _defineProperty({}, componentCls, _extends(_extends(_extends(_extends(_extends({}, resetComponent(token)), (_extends2 = {
    display: 'inline-block',
    padding: token.segmentedContainerPadding,
    color: token.labelColor,
    backgroundColor: token.bgColor,
    borderRadius: token.borderRadius,
    transition: "all ".concat(token.motionDurationFast, " ").concat(token.motionEaseInOut)
  }, _defineProperty(_extends2, "".concat(componentCls, "-group"), {
    position: 'relative',
    display: 'flex',
    alignItems: 'stretch',
    justifyItems: 'flex-start',
    width: '100%'
  }), _defineProperty(_extends2, '&&-rtl', {
    direction: 'rtl'
  }), _defineProperty(_extends2, '&&-block', {
    display: 'flex'
  }), _defineProperty(_extends2, "&&-block ".concat(componentCls, "-item"), {
    flex: 1,
    minWidth: 0
  }), _defineProperty(_extends2, "".concat(componentCls, "-item"), (_$concat = {
    position: 'relative',
    textAlign: 'center',
    cursor: 'pointer',
    transition: "color ".concat(token.motionDurationFast, " ").concat(token.motionEaseInOut),
    borderRadius: token.borderRadiusSM,
    '&-selected': _extends(_extends({}, getSegmentedItemSelectedStyle(token)), {
      color: token.labelColorHover
    }),
    '&::after': {
      content: '""',
      position: 'absolute',
      width: '100%',
      height: '100%',
      top: 0,
      insetInlineStart: 0,
      borderRadius: token.borderRadiusSM,
      transition: "background-color ".concat(token.motionDurationFast)
    }
  }, _defineProperty(_$concat, "&:hover:not(".concat(componentCls, "-item-selected):not(").concat(componentCls, "-item-disabled)"), {
    color: token.labelColorHover,
    '&::after': {
      backgroundColor: token.bgColorHover
    }
  }), _defineProperty(_$concat, '&-label', _extends({
    minHeight: token.controlHeight - token.segmentedContainerPadding * 2,
    lineHeight: "".concat(token.controlHeight - token.segmentedContainerPadding * 2, "px"),
    padding: "0 ".concat(token.segmentedPaddingHorizontal, "px")
  }, segmentedTextEllipsisCss)), _defineProperty(_$concat, '&-icon + *', {
    marginInlineEnd: token.marginSM / 2
  }), _defineProperty(_$concat, '&-input', {
    position: 'absolute',
    insetBlockStart: 0,
    insetInlineStart: 0,
    width: 0,
    height: 0,
    opacity: 0,
    pointerEvents: 'none'
  }), _$concat)), _defineProperty(_extends2, '&&-lg', (_lg = {
    borderRadius: token.borderRadiusLG
  }, _defineProperty(_lg, "".concat(componentCls, "-item-label"), {
    minHeight: token.controlHeightLG - token.segmentedContainerPadding * 2,
    lineHeight: "".concat(token.controlHeightLG - token.segmentedContainerPadding * 2, "px"),
    padding: "0 ".concat(token.segmentedPaddingHorizontal, "px"),
    fontSize: token.fontSizeLG
  }), _defineProperty(_lg, "".concat(componentCls, "-item-selected"), {
    borderRadius: token.borderRadius
  }), _lg)), _defineProperty(_extends2, '&&-sm', (_sm = {
    borderRadius: token.borderRadiusSM
  }, _defineProperty(_sm, "".concat(componentCls, "-item-label"), {
    minHeight: token.controlHeightSM - token.segmentedContainerPadding * 2,
    lineHeight: "".concat(token.controlHeightSM - token.segmentedContainerPadding * 2, "px"),
    padding: "0 ".concat(token.segmentedPaddingHorizontalSM, "px")
  }), _defineProperty(_sm, "".concat(componentCls, "-item-selected"), {
    borderRadius: token.borderRadiusXS
  }), _sm)), _extends2)), segmentedDisabledItem("&-disabled ".concat(componentCls, "-item"), token)), segmentedDisabledItem("".concat(componentCls, "-item-disabled"), token)), (_extends4 = {}, _defineProperty(_extends4, "".concat(componentCls, "-thumb"), _extends(_extends({}, getSegmentedItemSelectedStyle(token)), _defineProperty({
    position: 'absolute',
    insetBlockStart: 0,
    insetInlineStart: 0,
    width: 0,
    height: '100%',
    padding: "".concat(token.paddingXXS, "px 0"),
    borderRadius: token.borderRadiusSM
  }, "& ~ ".concat(componentCls, "-item:not(").concat(componentCls, "-item-selected):not(").concat(componentCls, "-item-disabled)::after"), {
    backgroundColor: 'transparent'
  }))), _defineProperty(_extends4, "".concat(componentCls, "-thumb-motion-appear-active"), {
    transition: "transform ".concat(token.motionDurationSlow, " ").concat(token.motionEaseInOut, ", width ").concat(token.motionDurationSlow, " ").concat(token.motionEaseInOut),
    willChange: 'transform, width'
  }), _extends4)));
};
// ============================== Export ==============================
export default genComponentStyleHook('Segmented', function (token) {
  var lineWidthBold = token.lineWidthBold,
    lineWidth = token.lineWidth,
    colorTextLabel = token.colorTextLabel,
    colorText = token.colorText,
    colorFillSecondary = token.colorFillSecondary,
    colorBgLayout = token.colorBgLayout,
    colorBgElevated = token.colorBgElevated;
  var segmentedToken = mergeToken(token, {
    segmentedPaddingHorizontal: token.controlPaddingHorizontal - lineWidth,
    segmentedPaddingHorizontalSM: token.controlPaddingHorizontalSM - lineWidth,
    segmentedContainerPadding: lineWidthBold,
    labelColor: colorTextLabel,
    labelColorHover: colorText,
    bgColor: colorBgLayout,
    bgColorHover: colorFillSecondary,
    bgColorSelected: colorBgElevated
  });
  return [genSegmentedStyle(segmentedToken)];
});