// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import * as React from 'react';
import type { Meta } from '@storybook/react';
import type { Props } from './AddNewLines.dom.tsx';
import { AddNewLines } from './AddNewLines.dom.tsx';

export default {
  title: 'Components/Conversation/AddNewLines',
} satisfies Meta<Props>;

const createProps = (overrideProps: Partial<Props> = {}): Props => ({
  renderNonNewLine: overrideProps.renderNonNewLine,
  text: overrideProps.text || '',
});

export function AllNewlines(): React.JSX.Element {
  const props = createProps({
    text: '\n\n\n',
  });

  return <AddNewLines {...props} />;
}

export function StartingEndingWithNewlines(): React.JSX.Element {
  const props = createProps({
    text: '\nSome text\n',
  });

  return <AddNewLines {...props} />;
}

export function NewlinesInTheMiddle(): React.JSX.Element {
  const props = createProps({
    text: 'Some\ntext',
  });

  return <AddNewLines {...props} />;
}

export function NoNewlines(): React.JSX.Element {
  const props = createProps({
    text: 'Some text',
  });

  return <AddNewLines {...props} />;
}

export function CustomRenderFunction(): React.JSX.Element {
  const props = createProps({
    text: 'Some text',
    renderNonNewLine: ({ text: theText, key }) => (
      <div key={key} style={{ color: 'aquamarine' }}>
        {theText}
      </div>
    ),
  });

  return <AddNewLines {...props} />;
}
