'use client';
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Toast/index.ts
var Toast_exports = {};
__export(Toast_exports, {
  Toaster: () => Toaster,
  toast: () => toast,
  useToast: () => useToast
});
module.exports = __toCommonJS(Toast_exports);

// src/base/Box/Box.tsx
var import_system = require("@paalan/react-shared/system");
var import_utils = require("@paalan/react-shared/utils");
var import_jsx_runtime = require("react/jsx-runtime");
var Box = (0, import_utils.forwardRef)((props, ref) => {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_system.StyledComponent, { ...props, ref });
});
Box.withComponent = import_system.WithStyledComponent;

// src/base/Center/Center.tsx
var import_lib = require("@paalan/react-shared/lib");
var import_utils2 = require("@paalan/react-shared/utils");
var import_jsx_runtime2 = require("react/jsx-runtime");
var Center = (0, import_utils2.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box, { className: (0, import_lib.cn)("flex items-center justify-center", className), ...restProps, ref, children });
});

// src/base/Container/Container.tsx
var import_lib2 = require("@paalan/react-shared/lib");
var import_utils3 = require("@paalan/react-shared/utils");
var import_jsx_runtime3 = require("react/jsx-runtime");
var Container = (0, import_utils3.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box, { className: (0, import_lib2.cn)("container", className), ...restProps, ref, children });
});

// src/base/Flex/Flex.tsx
var import_lib3 = require("@paalan/react-shared/lib");
var import_utils4 = require("@paalan/react-shared/utils");
var import_jsx_runtime4 = require("react/jsx-runtime");
var Flex = (0, import_utils4.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box, { className: (0, import_lib3.cn)("flex", className), ...restProps, ref, children });
});

// src/base/Grid/Grid.tsx
var import_lib4 = require("@paalan/react-shared/lib");
var import_utils5 = require("@paalan/react-shared/utils");
var import_jsx_runtime5 = require("react/jsx-runtime");
var Grid = (0, import_utils5.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box, { className: (0, import_lib4.cn)("grid", className), ...restProps, ref, children });
});
var GridItem = (0, import_utils5.forwardRef)((props, ref) => {
  const { children, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box, { ...restProps, ref, children });
});

// src/base/HStack/HStack.tsx
var import_lib5 = require("@paalan/react-shared/lib");
var import_utils6 = require("@paalan/react-shared/utils");
var import_jsx_runtime6 = require("react/jsx-runtime");
var HStack = (0, import_utils6.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box, { className: (0, import_lib5.cn)("flex flex-row items-center gap-2", className), ...restProps, ref, children });
});

// src/base/Heading/Heading.tsx
var import_lib6 = require("@paalan/react-shared/lib");
var import_utils7 = require("@paalan/react-shared/utils");
var import_jsx_runtime7 = require("react/jsx-runtime");
var headingSizes = {
  h1: "text-3xl font-bold",
  h2: "text-2xl font-bold",
  h3: "text-xl font-semibold",
  h4: "text-lg font-semibold",
  h5: "text-base font-semibold",
  h6: "text-sm font-semibold"
};
var Heading = (0, import_utils7.forwardRef)((props, ref) => {
  const { children, as: headTag = "h1", className, ...restProps } = props;
  const size = headingSizes[headTag];
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box, { as: headTag, ...restProps, ref, className: (0, import_lib6.cn)(size, className), children });
});

// src/base/Paper/Paper.tsx
var import_lib7 = require("@paalan/react-shared/lib");
var import_utils8 = require("@paalan/react-shared/utils");
var import_class_variance_authority = require("class-variance-authority");
var import_jsx_runtime8 = require("react/jsx-runtime");
var paperVariants = (0, import_class_variance_authority.cva)("bg-background text-foreground", {
  variants: {
    shadow: {
      default: "shadow",
      sm: "shadow-sm",
      md: "shadow-md",
      lg: "shadow-lg",
      xl: "shadow-xl",
      "2xl": "shadow-2xl",
      inner: "shadow-inner",
      none: "shadow-none"
    }
  },
  defaultVariants: {
    shadow: "default"
  }
});
var Paper = (0, import_utils8.forwardRef)(
  ({ withBorder, shadow, className, ...props }, ref) => {
    return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
      Box,
      {
        ref,
        className: (0, import_lib7.cn)(paperVariants({ shadow }), withBorder ? "border border-border" : "", className),
        ...props
      }
    );
  }
);

// src/base/Portal/Portal.tsx
var import_react = require("react");
var import_react_hooks = require("@paalan/react-hooks");
var import_utils9 = require("@paalan/react-shared/utils");
var import_react_dom = require("react-dom");
var import_jsx_runtime9 = require("react/jsx-runtime");
var createPortalNode = (props) => {
  const node = document.createElement("div");
  node.setAttribute("data-portal", "true");
  if (typeof props.className === "string") {
    node.classList.add(...props.className.split(" "));
  }
  if (typeof props.style === "object") {
    Object.assign(node.style, props.style);
  }
  if (typeof props.id === "string") {
    node.setAttribute("id", props.id);
  }
  return node;
};
var defaultProps = {};
var Portal = (0, import_react.forwardRef)((props, ref) => {
  const { children, target, ...others } = { ...defaultProps, ...props };
  const [mounted, setMounted] = (0, import_react.useState)(false);
  const nodeRef = (0, import_react.useRef)(null);
  (0, import_react_hooks.useIsomorphicEffect)(() => {
    setMounted(true);
    nodeRef.current = !target ? createPortalNode(others) : typeof target === "string" ? document.querySelector(target) : target;
    if (!nodeRef.current) return;
    (0, import_utils9.assignRef)(ref, nodeRef.current);
    if (!target && nodeRef.current) {
      document.body.appendChild(nodeRef.current);
    }
    return () => {
      if (!target && nodeRef.current) {
        document.body.removeChild(nodeRef.current);
      }
    };
  }, [target]);
  if (!mounted || !nodeRef.current) {
    return null;
  }
  return (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children }), nodeRef.current);
});
Portal.displayName = "Portal";

// src/base/Stack/Stack.tsx
var import_lib8 = require("@paalan/react-shared/lib");
var import_utils10 = require("@paalan/react-shared/utils");
var import_jsx_runtime10 = require("react/jsx-runtime");
var Stack = (0, import_utils10.forwardRef)((props, ref) => {
  const { children, className, direction, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { className: (0, import_lib8.cn)("flex flex-col gap-2", className), flexDirection: direction, ...restProps, ref, children });
});

// src/base/Text/Text.tsx
var import_lib9 = require("@paalan/react-shared/lib");
var import_utils11 = require("@paalan/react-shared/utils");
var import_jsx_runtime11 = require("react/jsx-runtime");
var Text = (0, import_utils11.forwardRef)((props, ref) => {
  const { children, className, as = "p", ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Box, { as, ref, className: (0, import_lib9.cn)("", className), ...restProps, children });
});

// src/base/Typography/Typography.tsx
var import_lib10 = require("@paalan/react-shared/lib");
var import_utils12 = require("@paalan/react-shared/utils");
var import_jsx_runtime12 = require("react/jsx-runtime");
var H1 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "h1",
    ref,
    className: (0, import_lib10.cn)("scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl", className),
    ...props
  }
));
H1.displayName = "H1";
var H2 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "h2",
    ref,
    className: (0, import_lib10.cn)(
      "mt-10 scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight transition-colors first:mt-0",
      className
    ),
    ...props
  }
));
H2.displayName = "H2";
var H3 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "h3",
    ref,
    className: (0, import_lib10.cn)("mt-8 scroll-m-20 text-2xl font-semibold tracking-tight", className),
    ...props
  }
));
H3.displayName = "H3";
var H4 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "h4", ref, className: (0, import_lib10.cn)("scroll-m-20 text-xl font-semibold tracking-tight", className), ...props }));
H4.displayName = "H4";
var H5 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "h5", ref, className: (0, import_lib10.cn)("scroll-m-20 text-lg font-semibold tracking-tight", className), ...props }));
H5.displayName = "H5";
var H6 = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "h6", ref, className: (0, import_lib10.cn)("scroll-m-20 text-base font-semibold tracking-tight", className), ...props }));
H6.displayName = "H6";
var P = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "p", ref, className: (0, import_lib10.cn)("leading-7 [&:not(:first-child)]:mt-4", className), ...props }));
P.displayName = "P";
var BlockQuote = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
    Box,
    {
      as: "blockquote",
      ref,
      className: (0, import_lib10.cn)(
        "mt-6 border-l-2 border-slate-300 pl-6 italic text-slate-800 dark:border-slate-600 dark:text-slate-200",
        className
      ),
      ...props
    }
  )
);
BlockQuote.displayName = "BlockQuote";
var TableLayout = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "table", ref, className: (0, import_lib10.cn)("w-full", className), ...props })
);
TableLayout.displayName = "Table";
var THead = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "thead", ref, className: (0, import_lib10.cn)("", className), ...props })
);
THead.displayName = "THead";
var TBody = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "tbody", ref, className: (0, import_lib10.cn)("", className), ...props })
);
TBody.displayName = "TBody";
var TR = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "tr",
    ref,
    className: (0, import_lib10.cn)(
      "m-0 border-t border-slate-300 p-0 even:bg-slate-100 dark:border-slate-700 dark:even:bg-slate-800",
      className
    ),
    ...props
  }
));
TR.displayName = "TR";
var TD = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "td",
    ref,
    className: (0, import_lib10.cn)(
      "border border-slate-200 px-4 py-2 text-left dark:border-slate-700 [&[align=center]]:text-center [&[align=right]]:text-right",
      className
    ),
    ...props
  }
));
TD.displayName = "TD";
var TH = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "th",
    ref,
    className: (0, import_lib10.cn)(
      "border border-slate-200 px-4 py-2 text-left font-bold dark:border-slate-700 [&[align=center]]:text-center [&[align=right]]:text-right",
      className
    ),
    ...props
  }
));
TH.displayName = "TH";
var UL = (0, import_utils12.forwardRef)(({ className, unstyled = false, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "ul",
    ref,
    className: (0, import_lib10.cn)(
      {
        "m-4 list-disc [&>li]:mt-2": !unstyled
      },
      className
    ),
    ...props
  }
));
UL.displayName = "UL";
var OL = (0, import_utils12.forwardRef)(({ className, unstyled = false, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "ol",
    ref,
    className: (0, import_lib10.cn)(
      {
        "m-4 list-decimal [&>li]:mt-2": !unstyled
      },
      className
    ),
    ...props
  }
));
OL.displayName = "OL";
var LI = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "li", ref, className: (0, import_lib10.cn)("", className), ...props }));
LI.displayName = "LI";
var Code = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
  Box,
  {
    as: "code",
    ref,
    className: (0, import_lib10.cn)("relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-normal", className),
    ...props
  }
));
Code.displayName = "Code";
var Lead = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "p", ref, className: (0, import_lib10.cn)("text-xl text-muted-foreground", className), ...props }));
Lead.displayName = "Lead";
var Large = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "div", ref, className: (0, import_lib10.cn)("text-lg font-semibold", className), ...props }));
Large.displayName = "Large";
var Small = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "small", ref, className: (0, import_lib10.cn)("text-sm font-medium leading-none", className), ...props })
);
Small.displayName = "Small";
var Subtle = (0, import_utils12.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "p", ref, className: (0, import_lib10.cn)("text-sm text-muted-foreground", className), ...props }));
Subtle.displayName = "Subtle";
var Strong = (0, import_utils12.forwardRef)(
  ({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Box, { as: "strong", ref, className: (0, import_lib10.cn)("font-semibold", className), ...props })
);
Strong.displayName = "Strong";

// src/base/VStack/VStack.tsx
var import_lib11 = require("@paalan/react-shared/lib");
var import_utils13 = require("@paalan/react-shared/utils");
var import_jsx_runtime13 = require("react/jsx-runtime");
var VStack = (0, import_utils13.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Box, { className: (0, import_lib11.cn)("flex flex-col items-stretch gap-2", className), ...restProps, ref, children });
});

// src/base/Wrap/Wrap.tsx
var import_lib12 = require("@paalan/react-shared/lib");
var import_utils14 = require("@paalan/react-shared/utils");
var import_jsx_runtime14 = require("react/jsx-runtime");
var Wrap = (0, import_utils14.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Box, { className: (0, import_lib12.cn)("flex flex-wrap gap-2", className), ...restProps, ref, children });
});
var WrapItem = (0, import_utils14.forwardRef)((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Box, { className: (0, import_lib12.cn)("flex flex-none items-start", className), ...restProps, ref, children });
});

// src/components/Toast/components/HeadlessToast.tsx
var import_jsx_runtime15 = require("react/jsx-runtime");
var HeadlessToast = ({ title, description, id, toast: toast2 }) => {
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Box, { className: "toast-headless", children: [
    /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Text, { className: "toast-headless-title", children: title }),
    description && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Text, { className: "toast-headless-description", children: description }),
    /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "toast-headless-close", onClick: () => toast2.dismiss(id), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("path", { d: "M2.96967 2.96967C3.26256 2.67678 3.73744 2.67678 4.03033 2.96967L8 6.939L11.9697 2.96967C12.2626 2.67678 12.7374 2.67678 13.0303 2.96967C13.3232 3.26256 13.3232 3.73744 13.0303 4.03033L9.061 8L13.0303 11.9697C13.2966 12.2359 13.3208 12.6526 13.1029 12.9462L13.0303 13.0303C12.7374 13.3232 12.2626 13.3232 11.9697 13.0303L8 9.061L4.03033 13.0303C3.73744 13.3232 3.26256 13.3232 2.96967 13.0303C2.67678 12.7374 2.67678 12.2626 2.96967 11.9697L6.939 8L2.96967 4.03033C2.7034 3.76406 2.6792 3.3474 2.89705 3.05379L2.96967 2.96967Z" }) }) })
  ] });
};

// src/components/Toast/state.tsx
var import_jsx_runtime16 = require("react/jsx-runtime");
var toastsCounter = 1;
var Observer = class {
  subscribers;
  toasts;
  constructor() {
    this.subscribers = [];
    this.toasts = [];
  }
  // We use arrow functions to maintain the correct `this` reference
  subscribe = (subscriber) => {
    this.subscribers.push(subscriber);
    return () => {
      const index = this.subscribers.indexOf(subscriber);
      this.subscribers.splice(index, 1);
    };
  };
  publish = (data) => {
    this.subscribers.forEach((subscriber) => subscriber(data));
  };
  addToast = (data) => {
    this.publish(data);
    this.toasts = [...this.toasts, data];
  };
  create = (data) => {
    const { message, ...rest } = data;
    const id = typeof data?.id === "number" || data?.id && data.id.length && data.id.length > 0 ? data.id : toastsCounter++;
    const alreadyExists = this.toasts.find((toast2) => {
      return toast2.id === id;
    });
    const dismissible = data.dismissible === void 0 ? true : data.dismissible;
    if (alreadyExists) {
      this.toasts = this.toasts.map((toast2) => {
        if (toast2.id === id) {
          this.publish({ ...toast2, ...data, id, title: message });
          return {
            ...toast2,
            ...data,
            id,
            dismissible,
            title: message
          };
        }
        return toast2;
      });
    } else {
      this.addToast({ title: message, ...rest, dismissible, id });
    }
    return id;
  };
  dismiss = (id) => {
    if (!id) {
      this.toasts.forEach((toast2) => {
        this.subscribers.forEach((subscriber) => subscriber({ id: toast2.id, dismiss: true }));
      });
    } else {
      this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }));
    }
    return id;
  };
  message = (message, data) => {
    return this.create({ ...data, message });
  };
  error = (message, data) => {
    return this.create({ ...data, message, type: "error" });
  };
  success = (message, data) => {
    return this.create({ ...data, type: "success", message });
  };
  warning = (message, data) => {
    return this.create({ ...data, type: "warning", message });
  };
  info = (message, data) => {
    return this.create({ ...data, type: "info", message });
  };
  show = (message, { description, ...data } = {}) => {
    return this.custom((id) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(HeadlessToast, { id, title: message, description, toast }), data);
  };
  loading = (message, data) => {
    return this.create({ ...data, type: "loading", message });
  };
  promise = (promise, data) => {
    if (!data) {
      return;
    }
    let id = void 0;
    if (data.loading !== void 0) {
      id = this.create({
        ...data,
        promise,
        type: "loading",
        message: data.loading
      });
    }
    const p = promise instanceof Promise ? promise : promise();
    let shouldDismiss = id !== void 0;
    p.then((promiseData) => {
      if (data.success !== void 0) {
        shouldDismiss = false;
        const message = typeof data.success === "function" ? data.success(promiseData) : data.success;
        this.create({ id, type: "success", message });
      }
    }).catch((error) => {
      if (data.error !== void 0) {
        shouldDismiss = false;
        const message = typeof data.error === "function" ? data.error(error) : data.error;
        this.create({ id, type: "error", message });
      }
    }).finally(() => {
      if (shouldDismiss) {
        this.dismiss(id);
        id = void 0;
      }
      data.finally?.();
    });
    return id;
  };
  // We can't provide the toast we just created as a prop as we didn't create it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?
  custom = (jsx22, data) => {
    const id = data?.id || toastsCounter++;
    this.publish({ jsx: jsx22(id), id, ...data });
  };
};
var ToastState = new Observer();
var toastFunction = (message, data) => {
  const id = data?.id || toastsCounter++;
  ToastState.addToast({
    title: message,
    ...data,
    id
  });
  return id;
};
var basicToast = toastFunction;
var toast = Object.assign(basicToast, {
  success: ToastState.success,
  error: ToastState.error,
  warning: ToastState.warning,
  info: ToastState.info,
  show: ToastState.show,
  custom: ToastState.custom,
  message: ToastState.message,
  promise: ToastState.promise,
  dismiss: ToastState.dismiss,
  loading: ToastState.loading
});

// src/components/Toast/hooks.ts
var useToast = () => {
  return toast;
};

// src/components/Toast/Toaster.tsx
var import_react4 = __toESM(require("react"), 1);
var import_react_dom2 = require("react-dom");

// src/components/Toast/constant.ts
var TOAST_LIFETIME = 5e3;
var GAP = 14;
var SWIPE_THRESHOLD = 20;
var TIME_BEFORE_UNMOUNT = 200;
var VISIBLE_TOASTS_AMOUNT = 3;
var VIEWPORT_OFFSET = "32px";
var TOAST_WIDTH = 356;

// src/components/Toast/helper.ts
var import_react2 = __toESM(require("react"), 1);
var isValidReactNode = (value) => {
  return typeof value === "string" || import_react2.default.isValidElement(value);
};
var getDocumentDirection = () => {
  if (typeof window === "undefined") return "ltr";
  const dirAttribute = document.documentElement.getAttribute("dir");
  if (dirAttribute === "auto" || !dirAttribute) {
    return window.getComputedStyle(document.documentElement).direction;
  }
  return dirAttribute;
};

// src/components/Toast/Toast.tsx
var import_react3 = __toESM(require("react"), 1);
var import_lib15 = require("@paalan/react-shared/lib");

// src/components/Toast/assets.tsx
var import_react_icons = require("@paalan/react-icons");
var import_jsx_runtime17 = require("react/jsx-runtime");
var bars = Array(12).fill(0);
var Loader = ({ visible }) => {
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "toast-loading-wrapper", "data-visible": visible, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "toast-spinner", children: bars.map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "toast-loading-bar" }, `spinner-bar-${i}`)) }) });
};
var getAsset = (type) => {
  switch (type) {
    case "success":
      return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_icons.SuccessIcon, {});
    case "error":
      return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_icons.ErrorIcon, {});
    case "warning":
      return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_icons.WarningIcon1, {});
    case "info":
      return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_icons.InfoIcon1, {});
    default:
      return null;
  }
};

// src/components/Toast/components/ActionButton.tsx
var import_lib13 = require("@paalan/react-shared/lib");
var import_jsx_runtime18 = require("react/jsx-runtime");
var ActionButton = ({ toast: toast2, deleteToast, className }) => {
  if (isValidReactNode(toast2.action)) return toast2.action;
  const onClick = toast2.action.onClick;
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
    "button",
    {
      "data-button": true,
      onClick: (event) => {
        onClick?.(event);
        if (event.defaultPrevented) return;
        deleteToast();
      },
      className: (0, import_lib13.cn)(className, toast2.action.className),
      children: toast2.action.label
    }
  );
};

// src/components/Toast/components/CancelButton.tsx
var import_lib14 = require("@paalan/react-shared/lib");
var import_jsx_runtime19 = require("react/jsx-runtime");
var CancelButton = ({ toast: toast2, dismissible, deleteToast, className }) => {
  if (isValidReactNode(toast2.cancel)) return toast2.cancel;
  const onClick = toast2.cancel.onClick;
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
    "button",
    {
      "data-button": true,
      "data-cancel": true,
      onClick: () => {
        if (!dismissible) return;
        deleteToast();
        onClick?.();
      },
      className: (0, import_lib14.cn)(className, toast2.cancel.className),
      children: toast2.cancel.label
    }
  );
};

// src/components/Toast/Toast.tsx
var import_jsx_runtime20 = require("react/jsx-runtime");
var Toast = (props) => {
  const {
    invert: ToasterInvert,
    toast: toast2,
    interacting,
    setHeights,
    visibleToasts,
    heights,
    index,
    toasts,
    expanded,
    removeToast,
    closeButton,
    style,
    cancelButtonClassName,
    actionButtonClassName,
    className = "",
    descriptionClassName = "",
    duration: durationFromToaster,
    position,
    loadingIcon: loadingIconProp,
    expandByDefault
  } = props;
  const [mounted, setMounted] = import_react3.default.useState(false);
  const [removed, setRemoved] = import_react3.default.useState(false);
  const [swiping, setSwiping] = import_react3.default.useState(false);
  const [swipeOut, setSwipeOut] = import_react3.default.useState(false);
  const [offsetBeforeRemove, setOffsetBeforeRemove] = import_react3.default.useState(0);
  const [initialHeight, setInitialHeight] = import_react3.default.useState(0);
  const dragStartTime = import_react3.default.useRef(null);
  const toastRef = import_react3.default.useRef(null);
  const isFront = index === 0;
  const isVisible = index + 1 <= visibleToasts;
  const toastType = toast2.type;
  const dismissible = toast2.dismissible !== false;
  const toastClassname = toast2.className || "";
  const toastDescriptionClassname = toast2.descriptionClassName || "";
  const heightIndex = import_react3.default.useMemo(
    () => heights.findIndex((height) => height.toastId === toast2.id) || 0,
    [heights, toast2.id]
  );
  const duration = import_react3.default.useMemo(
    () => toast2.duration || durationFromToaster || TOAST_LIFETIME,
    [toast2.duration, durationFromToaster]
  );
  const closeTimerStartTimeRef = import_react3.default.useRef(0);
  const offset = import_react3.default.useRef(0);
  const lastCloseTimerStartTimeRef = import_react3.default.useRef(0);
  const pointerStartRef = import_react3.default.useRef(null);
  const [y, x] = position.split("-");
  const toastsHeightBefore = import_react3.default.useMemo(() => {
    return heights.reduce((prev, curr, reducerIndex) => {
      if (reducerIndex >= heightIndex) {
        return prev;
      }
      return prev + curr.height;
    }, 0);
  }, [heights, heightIndex]);
  const invert = toast2.invert || ToasterInvert;
  const disabled = toastType === "loading";
  offset.current = import_react3.default.useMemo(() => heightIndex * GAP + toastsHeightBefore, [heightIndex, toastsHeightBefore]);
  import_react3.default.useEffect(() => {
    setMounted(true);
  }, []);
  import_react3.default.useLayoutEffect(() => {
    if (!mounted) return;
    const toastNode = toastRef.current;
    if (!toastNode) return;
    const originalHeight = toastNode.style.height;
    toastNode.style.height = "auto";
    const newHeight = toastNode.getBoundingClientRect().height;
    toastNode.style.height = originalHeight;
    setInitialHeight(newHeight);
    setHeights((heights2) => {
      const alreadyExists = heights2.find((height) => height.toastId === toast2.id);
      if (!alreadyExists) {
        return [{ toastId: toast2.id, height: newHeight }, ...heights2];
      } else {
        return heights2.map((height) => height.toastId === toast2.id ? { ...height, height: newHeight } : height);
      }
    });
  }, [mounted, toast2.title, toast2.description, setHeights, toast2.id]);
  const deleteToast = import_react3.default.useCallback(() => {
    setRemoved(true);
    setOffsetBeforeRemove(offset.current);
    setHeights((h) => h.filter((height) => height.toastId !== toast2.id));
    setTimeout(() => {
      removeToast(toast2);
    }, TIME_BEFORE_UNMOUNT);
  }, [toast2, removeToast, setHeights, offset]);
  import_react3.default.useEffect(() => {
    if (toast2.promise && toastType === "loading" || toast2.duration === Infinity) return;
    let timeoutId;
    let remainingTime = duration;
    const pauseTimer = () => {
      if (lastCloseTimerStartTimeRef.current < closeTimerStartTimeRef.current) {
        const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
        remainingTime = remainingTime - elapsedTime;
      }
      lastCloseTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
    };
    const startTimer = () => {
      closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
      timeoutId = setTimeout(() => {
        toast2.onAutoClose?.(toast2);
        deleteToast();
      }, remainingTime);
    };
    if (expanded || interacting) {
      pauseTimer();
    } else {
      startTimer();
    }
    return () => clearTimeout(timeoutId);
  }, [expanded, interacting, expandByDefault, toast2, duration, deleteToast, toast2.promise, toastType]);
  import_react3.default.useEffect(() => {
    const toastNode = toastRef.current;
    if (toastNode) {
      const height = toastNode.getBoundingClientRect().height;
      setInitialHeight(height);
      setHeights((h) => [{ toastId: toast2.id, height }, ...h]);
      return () => setHeights((h) => h.filter((height2) => height2.toastId !== toast2.id));
    }
  }, [setHeights, toast2.id]);
  import_react3.default.useEffect(() => {
    if (toast2.delete) {
      deleteToast();
    }
  }, [deleteToast, toast2.delete]);
  function getLoadingIcon() {
    if (loadingIconProp) {
      return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Box, { className: "toast-loader", "data-visible": toastType === "loading", children: loadingIconProp });
    }
    return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Loader, { visible: toastType === "loading" });
  }
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
    "li",
    {
      "aria-live": toast2.important ? "assertive" : "polite",
      "aria-atomic": "true",
      role: "status",
      tabIndex: 0,
      ref: toastRef,
      className: (0, import_lib15.cn)(className, toastClassname),
      "data-toast-toast": "",
      "data-styled": !(toast2.jsx || toast2.unstyled),
      "data-mounted": mounted,
      "data-promise": Boolean(toast2.promise),
      "data-removed": removed,
      "data-visible": isVisible,
      "data-y-position": y,
      "data-x-position": x,
      "data-index": index,
      "data-front": isFront,
      "data-swiping": swiping,
      "data-dismissible": dismissible,
      "data-type": toastType,
      "data-invert": invert,
      "data-swipe-out": swipeOut,
      "data-expanded": Boolean(expanded || expandByDefault && mounted),
      style: {
        "--index": index,
        "--toasts-before": index,
        "--z-index": toasts.length - index,
        "--offset": `${removed ? offsetBeforeRemove : offset.current}px`,
        "--initial-height": expandByDefault ? "auto" : `${initialHeight}px`,
        ...style,
        ...toast2.style
      },
      onPointerDown: (event) => {
        if (disabled || !dismissible) return;
        dragStartTime.current = /* @__PURE__ */ new Date();
        setOffsetBeforeRemove(offset.current);
        event.target.setPointerCapture(event.pointerId);
        if (event.target.tagName === "BUTTON") return;
        setSwiping(true);
        pointerStartRef.current = { x: event.clientX, y: event.clientY };
      },
      onPointerUp: () => {
        if (swipeOut || !dismissible) return;
        pointerStartRef.current = null;
        const swipeAmount = Number(toastRef.current?.style.getPropertyValue("--swipe-amount").replace("px", "") || 0);
        const timeTaken = dragStartTime.current ? (/* @__PURE__ */ new Date()).getTime() - dragStartTime.current.getTime() : 0;
        const velocity = Math.abs(swipeAmount) / timeTaken;
        if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > 0.11) {
          setOffsetBeforeRemove(offset.current);
          toast2.onDismiss?.(toast2);
          deleteToast();
          setSwipeOut(true);
          return;
        }
        toastRef.current?.style.setProperty("--swipe-amount", "0px");
        setSwiping(false);
      },
      onPointerMove: (event) => {
        if (!pointerStartRef.current || !dismissible) return;
        const yPosition = event.clientY - pointerStartRef.current.y;
        const xPosition = event.clientX - pointerStartRef.current.x;
        const clamp = y === "top" ? Math.min : Math.max;
        const clampedY = clamp(0, yPosition);
        const swipeStartThreshold = event.pointerType === "touch" ? 10 : 2;
        const isAllowedToSwipe = Math.abs(clampedY) > swipeStartThreshold;
        if (isAllowedToSwipe) {
          toastRef.current?.style.setProperty("--swipe-amount", `${yPosition}px`);
        } else if (Math.abs(xPosition) > swipeStartThreshold) {
          pointerStartRef.current = null;
        }
      },
      children: [
        closeButton && dismissible && !toast2.jsx && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
          "button",
          {
            "aria-label": "Close toast",
            "data-disabled": disabled,
            "data-close-button": true,
            onClick: () => {
              if (disabled) return;
              deleteToast();
              toast2.onDismiss?.(toast2);
            },
            children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
              "svg",
              {
                xmlns: "http://www.w3.org/2000/svg",
                width: "16",
                height: "16",
                viewBox: "0 0 24 24",
                fill: "none",
                stroke: "currentColor",
                strokeWidth: "1.5",
                strokeLinecap: "round",
                strokeLinejoin: "round",
                children: [
                  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
                  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
                ]
              }
            )
          }
        ),
        toast2.jsx || import_react3.default.isValidElement(toast2.title) ? toast2.jsx || toast2.title : /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
          toastType || toast2.icon || toast2.promise ? /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { "data-icon": "", children: [
            (toast2.promise || toast2.type === "loading") && !toast2.icon ? getLoadingIcon() : null,
            toast2.icon || toastType && getAsset(toastType)
          ] }) : null,
          /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { "data-content": "", children: [
            /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { "data-title": "", children: toast2.title }),
            !!toast2.description && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { "data-description": "", className: (0, import_lib15.cn)(descriptionClassName, toastDescriptionClassname), children: toast2.description })
          ] }),
          (!!toast2.cancel || !!toast2.action) && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center space-x-2", children: [
            toast2.cancel && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
              CancelButton,
              {
                toast: toast2,
                dismissible,
                deleteToast,
                className: cancelButtonClassName
              }
            ),
            toast2.action && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionButton, { toast: toast2, deleteToast, className: actionButtonClassName })
          ] })
        ] })
      ]
    }
  );
};

// src/components/Toast/Toaster.tsx
var import_jsx_runtime21 = require("react/jsx-runtime");
var Toaster = (props) => {
  const {
    invert,
    position = "top-right",
    hotkey = ["altKey", "KeyT"],
    expand,
    closeButton,
    className,
    offset,
    theme = "light",
    richColors,
    duration,
    style,
    visibleToasts = VISIBLE_TOASTS_AMOUNT,
    toastOptions,
    dir = getDocumentDirection(),
    gap = GAP,
    loadingIcon
  } = props;
  const [toasts, setToasts] = import_react4.default.useState([]);
  const possiblePositions = import_react4.default.useMemo(() => {
    const positions = toasts.filter((toast2) => !!toast2.position).map((toast2) => toast2.position);
    return Array.from(new Set([position].concat(positions)));
  }, [toasts, position]);
  const [heights, setHeights] = import_react4.default.useState([]);
  const [expanded, setExpanded] = import_react4.default.useState(false);
  const [interacting, setInteracting] = import_react4.default.useState(false);
  const [actualTheme, setActualTheme] = import_react4.default.useState(
    theme !== "system" ? theme : typeof window !== "undefined" ? window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : "light"
  );
  const listRef = import_react4.default.useRef(null);
  const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
  const lastFocusedElementRef = import_react4.default.useRef();
  const isFocusWithinRef = import_react4.default.useRef(false);
  const removeToast = import_react4.default.useCallback(
    (toast2) => setToasts((toasts2) => toasts2.filter(({ id }) => id !== toast2.id)),
    []
  );
  import_react4.default.useEffect(() => {
    return ToastState.subscribe((toast2) => {
      if (toast2.dismiss) {
        setToasts((toasts2) => toasts2.map((t) => t.id === toast2.id ? { ...t, delete: true } : t));
        return;
      }
      setTimeout(() => {
        (0, import_react_dom2.flushSync)(() => {
          setToasts((toasts2) => {
            const indexOfExistingToast = toasts2.findIndex((t) => t.id === toast2.id);
            if (indexOfExistingToast !== -1) {
              return [
                ...toasts2.slice(0, indexOfExistingToast),
                { ...toasts2[indexOfExistingToast], ...toast2 },
                ...toasts2.slice(indexOfExistingToast + 1)
              ];
            }
            return [toast2, ...toasts2];
          });
        });
      });
    });
  }, []);
  import_react4.default.useEffect(() => {
    if (theme !== "system") {
      setActualTheme(theme);
      return;
    }
    if (theme === "system") {
      if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
        setActualTheme("dark");
      } else {
        setActualTheme("light");
      }
    }
    if (typeof window === "undefined") return;
    window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", ({ matches }) => {
      if (matches) {
        setActualTheme("dark");
      } else {
        setActualTheme("light");
      }
    });
  }, [theme]);
  import_react4.default.useEffect(() => {
    if (toasts.length <= 1) {
      setExpanded(false);
    }
  }, [toasts]);
  import_react4.default.useEffect(() => {
    const handleKeyDown = (event) => {
      const isHotkeyPressed = hotkey.every((key) => {
        return event[key] || event.code === key;
      });
      if (isHotkeyPressed) {
        setExpanded(true);
        listRef.current?.focus();
      }
      if (event.code === "Escape" && (document.activeElement === listRef.current || listRef.current?.contains(document.activeElement))) {
        setExpanded(false);
      }
    };
    document.addEventListener("keydown", handleKeyDown);
    return () => document.removeEventListener("keydown", handleKeyDown);
  }, [hotkey]);
  import_react4.default.useEffect(() => {
    if (listRef.current) {
      return () => {
        if (lastFocusedElementRef.current) {
          lastFocusedElementRef.current.focus({ preventScroll: true });
          lastFocusedElementRef.current = void 0;
          isFocusWithinRef.current = false;
        }
      };
    }
  }, []);
  if (!toasts.length) return null;
  return (
    // Remove item from normal navigation flow, only available via hotkey
    /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("section", { "aria-label": `Notifications ${hotkeyLabel}`, tabIndex: -1, children: possiblePositions.map((position2, index) => {
      const [y, x] = position2.split("-");
      return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
        "ol",
        {
          dir: dir === "auto" ? getDocumentDirection() : dir,
          tabIndex: -1,
          ref: listRef,
          className,
          "data-toast-toaster": true,
          "data-theme": actualTheme,
          "data-rich-colors": richColors,
          "data-y-position": y,
          "data-x-position": x,
          style: {
            "--front-toast-height": `${heights[0]?.height}px`,
            "--offset": typeof offset === "number" ? `${offset}px` : offset || VIEWPORT_OFFSET,
            "--width": `${TOAST_WIDTH}px`,
            "--gap": `${gap}px`,
            ...style
          },
          onBlur: (event) => {
            if (isFocusWithinRef.current && !event.currentTarget.contains(event.relatedTarget)) {
              isFocusWithinRef.current = false;
              if (lastFocusedElementRef.current) {
                lastFocusedElementRef.current.focus({ preventScroll: true });
                lastFocusedElementRef.current = void 0;
              }
            }
          },
          onFocus: (event) => {
            const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === "false";
            if (isNotDismissible) return;
            if (!isFocusWithinRef.current) {
              isFocusWithinRef.current = true;
              lastFocusedElementRef.current = event.relatedTarget;
            }
          },
          onMouseEnter: () => setExpanded(true),
          onMouseMove: () => setExpanded(true),
          onMouseLeave: () => {
            if (!interacting) {
              setExpanded(false);
            }
          },
          onPointerDown: (event) => {
            const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === "false";
            if (isNotDismissible) return;
            setInteracting(true);
          },
          onPointerUp: () => setInteracting(false),
          children: toasts.filter((toast2) => !toast2.position && index === 0 || toast2.position === position2).map((toast2, index2) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
            Toast,
            {
              index: index2,
              toast: toast2,
              duration: toastOptions?.duration ?? duration,
              className: toastOptions?.className,
              descriptionClassName: toastOptions?.descriptionClassName,
              invert: invert ?? false,
              visibleToasts,
              closeButton: closeButton ?? false,
              interacting,
              position: position2,
              style: toastOptions?.style,
              removeToast,
              toasts,
              heights,
              setHeights,
              expandByDefault: expand ?? false,
              expanded,
              cancelButtonClassName: toastOptions?.cancelButtonClassName,
              actionButtonClassName: toastOptions?.actionButtonClassName,
              gap,
              loadingIcon
            },
            toast2.id
          ))
        },
        position2
      );
    }) })
  );
};
