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 { arrayOf, node, oneOf, oneOfType, string, bool } from "prop-types";
import React from "react";
import { Attention, Delayed, Information, Success } from "@gympass/yoga-icons";
import Icon from "../../Icon";
import Box from "../../Box";
import Text from "../../Text";
import {
  Actions,
  Content,
  Title,
  PrimaryButton,
  SecondaryButton,
  TextContainer,
  Caption
} from "./StyledFeedback";
import parseDescription from "../../utils/parseDescription";
const ICON_SIZE = 64;
const VARIANT_ICONS = {
  success: {
    as: Success
  },
  informative: {
    as: Information
  },
  attention: {
    as: Attention
  },
  delayed: {
    as: Delayed
  }
};
function isChildFromComponent(child, component) {
  return child.type.displayName === component.displayName;
}
function Feedback(_a) {
  var _b = _a, {
    variant,
    title,
    description,
    children,
    center = true
  } = _b, props = __objRest(_b, [
    "variant",
    "title",
    "description",
    "children",
    "center"
  ]);
  const descriptionArray = parseDescription(description);
  const iconProps = VARIANT_ICONS[variant];
  let primaryButton;
  let secondaryButton;
  let captionElement;
  let titleElement = /* @__PURE__ */ jsx(Title, { children: title });
  function defineCompoundComponents() {
    React.Children.forEach(children, (child) => {
      if (isChildFromComponent(child, PrimaryButton))
        primaryButton = child;
      if (isChildFromComponent(child, SecondaryButton))
        secondaryButton = child;
      if (isChildFromComponent(child, Title))
        titleElement = child;
      if (isChildFromComponent(child, Caption))
        captionElement = child;
    });
  }
  defineCompoundComponents();
  return /* @__PURE__ */ jsx(
    Box,
    __spreadProps(__spreadValues({
      display: "flex",
      alignItems: "flex-end",
      bg: "white",
      width: "100%"
    }, center && {
      ph: "medium",
      pv: "xxlarge",
      minHeight: "100%"
    }), {
      children: /* @__PURE__ */ jsxs(Content, __spreadProps(__spreadValues({}, props), { children: [
        /* @__PURE__ */ jsx(
          Icon,
          __spreadProps(__spreadValues({}, iconProps), {
            size: ICON_SIZE,
            mb: "large",
            "data-testid": `feedback-icon-${variant}`
          })
        ),
        /* @__PURE__ */ jsxs(TextContainer, { children: [
          titleElement,
          /* @__PURE__ */ jsx(Box, { display: "flex", flexDirection: "column", gap: "large", mt: "small", children: descriptionArray.map((paragraph) => /* @__PURE__ */ jsx(Text.Body1, { color: "deep", children: paragraph }, paragraph == null ? void 0 : paragraph.toString().slice(0, 10))) })
        ] }),
        captionElement ? /* @__PURE__ */ jsx(Box, { mt: "medium", children: captionElement }) : null,
        /* @__PURE__ */ jsxs(Actions, { mt: "xxxlarge", children: [
          primaryButton,
          secondaryButton
        ] })
      ] }))
    })
  );
}
Feedback.propTypes = {
  variant: oneOf(Object.keys(VARIANT_ICONS)).isRequired,
  title: string,
  description: oneOfType([string, arrayOf(string)]).isRequired,
  children: oneOfType([arrayOf(node), node]),
  /** Center the component vertically */
  center: bool
};
var Feedback_default = Feedback;
export {
  Feedback_default as default
};
