var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import { jsx, jsxs } from "react/jsx-runtime";
import React, { forwardRef } from "react";
import styled from "styled-components";
import { borders, margins, paddings } from "@gympass/yoga-system";
import {
  checkPropTypes,
  elementType,
  element,
  func,
  oneOf,
  oneOfType,
  shape,
  string
} from "prop-types";
import Box from "../../Box";
import Button from "../../Button";
import Icon from "../../Icon";
import Text from "../../Text";
const StyledBanner = styled.div`
  display: flex;
  flex: 1;
  flex-direction: column;
  ${({
  variant,
  theme: {
    yoga: {
      components: { banner },
      spacing,
      colors: {
        feedback: {
          [variant]: backgroundColor = {
            light: banner.defaultBackgroundColor
          }
        }
      }
    }
  }
}) => `
    background-color: ${backgroundColor.light};
    padding: ${spacing.xxsmall}px
      ${spacing.small}px;
    border-radius: ${banner.border.radius}px;
  `}

  ${margins}

  ${paddings}

  ${borders}
`;
const BannerActionButton = React.forwardRef(
  (_a, ref) => {
    var _b = _a, { button: { label, action } } = _b, props = __objRest(_b, ["button"]);
    return /* @__PURE__ */ jsx(Box, __spreadProps(__spreadValues({ as: Button.Text, small: true, secondary: true, onClick: action, ref }, props), { children: label }));
  }
);
BannerActionButton.propTypes = {
  button: shape({
    label: string.isRequired,
    action: func.isRequired
  }).isRequired
};
const Banner = forwardRef((props, ref) => {
  const _a = props, {
    icon,
    variant = "informative",
    message,
    primaryButton,
    secondaryButton
  } = _a, rest = __objRest(_a, [
    "icon",
    "variant",
    "message",
    "primaryButton",
    "secondaryButton"
  ]);
  return /* @__PURE__ */ jsxs(StyledBanner, __spreadProps(__spreadValues({ ref, variant }, rest), { children: [
    /* @__PURE__ */ jsxs(Box, { display: "flex", flex: 1, alignItems: "center", children: [
      icon && /* @__PURE__ */ jsx(
        Icon,
        {
          as: icon,
          size: "medium",
          fill: "secondary",
          marginRight: "xxsmall"
        }
      ),
      /* @__PURE__ */ jsx(Text.Body2, { flex: 1, marginVertical: "xxsmall", children: message }),
      primaryButton && !secondaryButton && /* @__PURE__ */ jsx(BannerActionButton, { button: primaryButton, marginLeft: "xxsmall" })
    ] }),
    primaryButton && secondaryButton && /* @__PURE__ */ jsxs(
      Box,
      {
        display: "flex",
        flex: 1,
        justifyContent: "flex-end",
        marginBottom: "xxsmall",
        children: [
          /* @__PURE__ */ jsx(BannerActionButton, { button: primaryButton, marginRight: "xxxsmall" }),
          /* @__PURE__ */ jsx(BannerActionButton, { button: secondaryButton })
        ]
      }
    )
  ] }));
});
const BannerActionButtonType = shape({
  label: string.isRequired,
  action: func.isRequired
});
Banner.propTypes = {
  /** SVG to be rendered. */
  icon: elementType,
  /** style the banner following the theme (success, informative, attention) */
  variant: oneOf(["success", "informative", "attention"]),
  /** the message to display */
  message: oneOfType([string, element]).isRequired,
  /** the label and action fuction are required for banner action buttons  */
  primaryButton: BannerActionButtonType,
  /** the secondary button should only be used assemble the primary button (the label and action fuction are required for banner action buttons).  */
  secondaryButton: (props, propName, componentName) => {
    const { primaryButton } = props;
    if (!primaryButton && !!props[propName]) {
      return new Error(
        `The ${propName} must only be used ensemble with the primaryButton.`
      );
    }
    return checkPropTypes(
      { [propName]: BannerActionButtonType },
      props,
      "prop",
      componentName
    );
  }
};
var Banner_default = Banner;
export {
  Banner_default as default
};
