import { ArrowChevronUpSmall16BlueIcon, ArrowChevronDownSmall16BlueIcon, XmarkRemove16RegularTertiaryCapsOffIcon, XmarkRemove16RegularPrimaryCapsOffIcon } from '@cloudtower/icons-react';
import Icon from '../Icon/index.js';
import Link from '../Link/index.js';
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import { Alert as Alert$2 } from 'antd';
import cs from 'classnames';
import React__default, { useState, useCallback } from 'react';
import { AlertStyle, MessageWrapperStyle } from './alert.style.js';
import { getAlertIcon } from '../../utils/icon.js';

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;
};
const Alert = (_a) => {
  var _b = _a, {
    type,
    icon,
    showIcon = true,
    className,
    onClose,
    closeText,
    action,
    message,
    description,
    closable,
    expandConfig,
    "data-testid": dataTestId
  } = _b, props = __objRest(_b, [
    "type",
    "icon",
    "showIcon",
    "className",
    "onClose",
    "closeText",
    "action",
    "message",
    "description",
    "closable",
    "expandConfig",
    "data-testid"
  ]);
  var _a2;
  const { t } = useParrotTranslation();
  const _icon = /* @__PURE__ */ React__default.createElement(Icon, { alt: type, src: getAlertIcon(type) });
  const _type = type === "normal" ? "info" : type;
  const _closable = closable || Boolean(onClose) || Boolean(closeText);
  const [internalExpanded, setInternalExpanded] = useState(
    (_a2 = expandConfig == null ? void 0 : expandConfig.defaultExpanded) != null ? _a2 : false
  );
  const isControlled = (expandConfig == null ? void 0 : expandConfig.expanded) !== void 0;
  const expanded = isControlled ? expandConfig.expanded : internalExpanded;
  const handleToggle = useCallback(() => {
    var _a3;
    const next = !expanded;
    if (!isControlled) {
      setInternalExpanded(next);
    }
    (_a3 = expandConfig == null ? void 0 : expandConfig.onExpandChange) == null ? void 0 : _a3.call(expandConfig, next);
  }, [expanded, isControlled, expandConfig == null ? void 0 : expandConfig.onExpandChange]);
  const showExpandToggle = expandConfig && description;
  const expandToggle = showExpandToggle ? /* @__PURE__ */ React__default.createElement(
    Link,
    {
      onClick: handleToggle,
      "data-testid": "alert-expand-toggle",
      suffixIcon: /* @__PURE__ */ React__default.createElement(
        Icon,
        {
          src: expanded ? ArrowChevronUpSmall16BlueIcon : ArrowChevronDownSmall16BlueIcon
        }
      )
    },
    expanded ? t("components.alert_collapse") : t("components.alert_expand")
  ) : null;
  return /* @__PURE__ */ React__default.createElement(
    Alert$2,
    __spreadProps(__spreadValues({}, props), {
      "data-testid": dataTestId,
      className: cs(AlertStyle, type ? `alert-${type}` : "", className, {
        action: action || expandToggle
      }),
      type: _type,
      message: /* @__PURE__ */ React__default.createElement("div", { className: MessageWrapperStyle }, /* @__PURE__ */ React__default.createElement("div", { style: { flex: 1 } }, message, showExpandToggle && expanded ? /* @__PURE__ */ React__default.createElement("div", null, description) : null), action ? /* @__PURE__ */ React__default.createElement("span", { className: cs("action") }, action) : null, expandToggle ? /* @__PURE__ */ React__default.createElement("span", { className: cs("action") }, expandToggle) : null),
      description: expandConfig ? void 0 : description,
      icon: icon || _icon,
      showIcon,
      onClose,
      closeText: closeText || _closable && /* @__PURE__ */ React__default.createElement(
        Icon,
        {
          src: XmarkRemove16RegularTertiaryCapsOffIcon,
          hoverSrc: XmarkRemove16RegularPrimaryCapsOffIcon
        }
      ),
      closable: _closable
    })
  );
};
var Alert$1 = Alert;

export { AlertStyle, MessageWrapperStyle, Alert$1 as default };
