import type { Meta, StoryObj } from "@storybook/preact";
import { ErrorBoundary } from "./ErrorBoundary";

function BrokenComponent(): preact.JSX.Element {
  throw new Error("Something went wrong in this component");
}

const meta: Meta = { title: "Global/ErrorBoundary" };
export default meta;
type Story = StoryObj;

export const CaughtError: Story = {
  render: () => (
    <ErrorBoundary>
      <BrokenComponent />
    </ErrorBoundary>
  ),
};

export const Working: Story = {
  render: () => (
    <ErrorBoundary>
      <p class="text-sm">This component works fine. No error caught.</p>
    </ErrorBoundary>
  ),
};
