"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.ButtonGroup = void 0;

var _style = _interopRequireDefault(require("styled-jsx/style"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _jsxRuntime = require("react/jsx-runtime");

// Generated with util/create-component.js
const ButtonGroup = props => {
  const {
    children,
    shape = "round",
    orientation = "horizontal",
    variant = "contained",
    size = "medium",
    fullWidth = false,
    fullHeight = false,
    backgroundColor = "primary",
    hoverBackgroundColor = null,
    color = null,
    className = null,
    ...otherProps
  } = props;

  const childrenWithProps = _react.default.Children.map(children, child => {
    // Checking isValidElement is the safe way and avoids a typescript
    // error too.
    if ( /*#__PURE__*/_react.default.isValidElement(child)) {
      return /*#__PURE__*/_react.default.cloneElement(child, {
        groupVariant: variant,
        groupShape: shape,
        groupSize: size,
        groupBackgroundColor: backgroundColor,
        groupHoverBackgroundColor: hoverBackgroundColor,
        groupColor: color
      });
    }

    return child;
  });

  function handleShapeFirstHorizontal() {
    switch (shape) {
      case "round":
        return "border-radius: 10em 0px 0px 10em; border-left-width: 1px;";

      case "rounded":
        return "border-radius: 0.7em 0px 0px 0.7em; border-left-width: 1px;";

      case "square":
        return "border-radius: 0em; border-left-width: 1px;";

      default:
        return "border-radius: 0.7em 0px 0px 0.7em; border-left-width: 1px;";
    }
  }

  function handleShapeLastHorizontal() {
    switch (shape) {
      case "round":
        return "border-radius: 0px 10em 10em 0px; border-right-width: 1px;";

      case "rounded":
        return "border-radius: 0px 0.7em 0.7em 0px; border-right-width: 1px;";

      case "square":
        return "border-radius: 0em; border-right-width: 1px;";

      default:
        return "border-radius: 0px 0.7em 0.7em 0px; border-right-width: 1px;";
    }
  }

  function handleShapeFirstVertical() {
    switch (shape) {
      case "round":
        return "border-radius: 10em 10em 0px 0px; border-top-width: 1px;";

      case "rounded":
        return "border-radius: 0.7em 0.7em 0px 0px; border-top-width: 1px;";

      case "square":
        return "border-radius: 0em; border-top-width: 1px;";

      default:
        return "border-radius: 0.7em 0.7em 0px 0px; border-top-width: 1px;";
    }
  }

  function handleShapeLastVertical() {
    switch (shape) {
      case "round":
        return "border-radius: 0px 0px 10em 10em; border-bottom-width: 1px;";

      case "rounded":
        return "border-radius: 0px 0px 0.7em 0.7em; border-bottom-width: 1px;";

      case "square":
        return "border-radius: 0em; border-bottom-width: 1px;";

      default:
        return "border-radius: 0px 0px 0.7em 0.7em; border-bottom-width: 1px;";
    }
  }

  function handleOrientation() {
    switch (orientation) {
      case "vertical":
        return "flex-direction: column;";

      case "horizontal":
      default:
        return "flex-direction: row;";
    }
  }

  function handleOrientationBorder() {
    switch (orientation) {
      case "vertical":
        return "border-top-width: 0.5px; border-bottom-width: 0.5px;";

      case "horizontal":
      default:
        return "border-left-width: 0.5px; border-right-width: 0.5px;";
    }
  }

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    "data-testid": "Wps-ButtonGroup",
    ...otherProps,
    className: _style.default.dynamic([["1136197057", [fullWidth ? "100%" : "max-content", fullHeight ? "100%" : "max-content", handleOrientation(), orientation === "vertical" ? "width: 100%;" : "", handleOrientationBorder(), orientation === "horizontal" ? handleShapeFirstHorizontal() : handleShapeFirstVertical(), orientation === "horizontal" ? handleShapeLastHorizontal() : handleShapeLastVertical()]]]) + " " + (otherProps && otherProps.className != null && otherProps.className || (0, _classnames.default)("Wps-ButtonGroup", className) || ""),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_style.default, {
      id: "1136197057",
      dynamic: [fullWidth ? "100%" : "max-content", fullHeight ? "100%" : "max-content", handleOrientation(), orientation === "vertical" ? "width: 100%;" : "", handleOrientationBorder(), orientation === "horizontal" ? handleShapeFirstHorizontal() : handleShapeFirstVertical(), orientation === "horizontal" ? handleShapeLastHorizontal() : handleShapeLastVertical()],
      children: `.Wps-ButtonGroup.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;width:${fullWidth ? "100%" : "max-content"};height:${fullHeight ? "100%" : "max-content"};${handleOrientation()};position:relative;}.Wps-ButtonGroup.__jsx-style-dynamic-selector button{border-radius:0;-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;min-width:-webkit-max-content;min-width:-moz-max-content;min-width:max-content;height:auto;${orientation === "vertical" ? "width: 100%;" : ""} ${handleOrientationBorder()};}.Wps-ButtonGroup.__jsx-style-dynamic-selector button:first-child{${orientation === "horizontal" ? handleShapeFirstHorizontal() : handleShapeFirstVertical()};}.Wps-ButtonGroup.__jsx-style-dynamic-selector button:last-child{${orientation === "horizontal" ? handleShapeLastHorizontal() : handleShapeLastVertical()};}`
    }), childrenWithProps]
  });
};

exports.ButtonGroup = ButtonGroup;