'use client';

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

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

// src/base/Container/Container.tsx
import { cn as cn2 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef3 } from "@paalan/react-shared/utils";
import { jsx as jsx3 } from "react/jsx-runtime";
var Container = forwardRef3((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ jsx3(Box, { className: cn2("container", className), ...restProps, ref, children });
});

// src/base/Flex/Flex.tsx
import { cn as cn3 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef4 } from "@paalan/react-shared/utils";
import { jsx as jsx4 } from "react/jsx-runtime";
var Flex = forwardRef4((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ jsx4(Box, { className: cn3("flex", className), ...restProps, ref, children });
});

// src/base/Grid/Grid.tsx
import { cn as cn4 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef5 } from "@paalan/react-shared/utils";
import { jsx as jsx5 } from "react/jsx-runtime";
var Grid = forwardRef5((props, ref) => {
  const { children, className, ...restProps } = props;
  return /* @__PURE__ */ jsx5(Box, { className: cn4("grid", className), ...restProps, ref, children });
});
var GridItem = forwardRef5((props, ref) => {
  const { children, ...restProps } = props;
  return /* @__PURE__ */ jsx5(Box, { ...restProps, ref, children });
});

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

// src/base/Heading/Heading.tsx
import { cn as cn6 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef7 } from "@paalan/react-shared/utils";
import { jsx as jsx7 } from "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 = forwardRef7((props, ref) => {
  const { children, as: headTag = "h1", className, ...restProps } = props;
  const size = headingSizes[headTag];
  return /* @__PURE__ */ jsx7(Box, { as: headTag, ...restProps, ref, className: cn6(size, className), children });
});

// src/base/Paper/Paper.tsx
import { cn as cn7 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef8 } from "@paalan/react-shared/utils";
import { cva } from "class-variance-authority";
import { jsx as jsx8 } from "react/jsx-runtime";
var paperVariants = 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 = forwardRef8(
  ({ withBorder, shadow, className, ...props }, ref) => {
    return /* @__PURE__ */ jsx8(
      Box,
      {
        ref,
        className: cn7(paperVariants({ shadow }), withBorder ? "border border-border" : "", className),
        ...props
      }
    );
  }
);

// src/base/Portal/Portal.tsx
import { forwardRef as forwardRef9, useRef, useState } from "react";
import { useIsomorphicEffect } from "@paalan/react-hooks";
import { assignRef } from "@paalan/react-shared/utils";
import { createPortal } from "react-dom";
import { Fragment, jsx as jsx9 } from "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 = forwardRef9((props, ref) => {
  const { children, target, ...others } = { ...defaultProps, ...props };
  const [mounted, setMounted] = useState(false);
  const nodeRef = useRef(null);
  useIsomorphicEffect(() => {
    setMounted(true);
    nodeRef.current = !target ? createPortalNode(others) : typeof target === "string" ? document.querySelector(target) : target;
    if (!nodeRef.current) return;
    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 createPortal(/* @__PURE__ */ jsx9(Fragment, { children }), nodeRef.current);
});
Portal.displayName = "Portal";

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

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

// src/base/Typography/Typography.tsx
import { cn as cn10 } from "@paalan/react-shared/lib";
import { forwardRef as forwardRef12 } from "@paalan/react-shared/utils";
import { jsx as jsx12 } from "react/jsx-runtime";
var H1 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "h1",
    ref,
    className: cn10("scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl", className),
    ...props
  }
));
H1.displayName = "H1";
var H2 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "h2",
    ref,
    className: cn10(
      "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 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "h3",
    ref,
    className: cn10("mt-8 scroll-m-20 text-2xl font-semibold tracking-tight", className),
    ...props
  }
));
H3.displayName = "H3";
var H4 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "h4", ref, className: cn10("scroll-m-20 text-xl font-semibold tracking-tight", className), ...props }));
H4.displayName = "H4";
var H5 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "h5", ref, className: cn10("scroll-m-20 text-lg font-semibold tracking-tight", className), ...props }));
H5.displayName = "H5";
var H6 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "h6", ref, className: cn10("scroll-m-20 text-base font-semibold tracking-tight", className), ...props }));
H6.displayName = "H6";
var P = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "p", ref, className: cn10("leading-7 [&:not(:first-child)]:mt-4", className), ...props }));
P.displayName = "P";
var BlockQuote = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
    Box,
    {
      as: "blockquote",
      ref,
      className: cn10(
        "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 = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "table", ref, className: cn10("w-full", className), ...props })
);
TableLayout.displayName = "Table";
var THead = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "thead", ref, className: cn10("", className), ...props })
);
THead.displayName = "THead";
var TBody = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "tbody", ref, className: cn10("", className), ...props })
);
TBody.displayName = "TBody";
var TR = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "tr",
    ref,
    className: cn10(
      "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 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "td",
    ref,
    className: cn10(
      "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 = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "th",
    ref,
    className: cn10(
      "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 = forwardRef12(({ className, unstyled = false, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "ul",
    ref,
    className: cn10(
      {
        "m-4 list-disc [&>li]:mt-2": !unstyled
      },
      className
    ),
    ...props
  }
));
UL.displayName = "UL";
var OL = forwardRef12(({ className, unstyled = false, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "ol",
    ref,
    className: cn10(
      {
        "m-4 list-decimal [&>li]:mt-2": !unstyled
      },
      className
    ),
    ...props
  }
));
OL.displayName = "OL";
var LI = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "li", ref, className: cn10("", className), ...props }));
LI.displayName = "LI";
var Code = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(
  Box,
  {
    as: "code",
    ref,
    className: cn10("relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-normal", className),
    ...props
  }
));
Code.displayName = "Code";
var Lead = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "p", ref, className: cn10("text-xl text-muted-foreground", className), ...props }));
Lead.displayName = "Lead";
var Large = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "div", ref, className: cn10("text-lg font-semibold", className), ...props }));
Large.displayName = "Large";
var Small = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "small", ref, className: cn10("text-sm font-medium leading-none", className), ...props })
);
Small.displayName = "Small";
var Subtle = forwardRef12(({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "p", ref, className: cn10("text-sm text-muted-foreground", className), ...props }));
Subtle.displayName = "Subtle";
var Strong = forwardRef12(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx12(Box, { as: "strong", ref, className: cn10("font-semibold", className), ...props })
);
Strong.displayName = "Strong";

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

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

// src/components/Toast/components/HeadlessToast.tsx
import { jsx as jsx15, jsxs } from "react/jsx-runtime";
var HeadlessToast = ({ title, description, id, toast: toast2 }) => {
  return /* @__PURE__ */ jsxs(Box, { className: "toast-headless", children: [
    /* @__PURE__ */ jsx15(Text, { className: "toast-headless-title", children: title }),
    description && /* @__PURE__ */ jsx15(Text, { className: "toast-headless-description", children: description }),
    /* @__PURE__ */ jsx15("button", { className: "toast-headless-close", onClick: () => toast2.dismiss(id), children: /* @__PURE__ */ jsx15("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ jsx15("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
import { jsx as jsx16 } from "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__ */ jsx16(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 = (jsx17, data) => {
    const id = data?.id || toastsCounter++;
    this.publish({ jsx: jsx17(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;
};
export {
  useToast
};
