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

import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { PropsType } from './GroupV2JoinDialog.dom.tsx';
import { GroupV2JoinDialog } from './GroupV2JoinDialog.dom.tsx';

const { i18n } = window.SignalContext;

const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
  memberCount: overrideProps.memberCount ?? 12,
  avatar: overrideProps.avatar,
  title: overrideProps.title ?? 'Random Group!',
  approvalRequired: overrideProps.approvalRequired ?? false,
  groupDescription: overrideProps.groupDescription,
  join: action('join'),
  onClose: action('onClose'),
  i18n,
});

export default {
  title: 'Components/GroupV2JoinDialog',
  argTypes: {},
  args: {},
} satisfies Meta<PropsType>;

export function Basic(): React.JSX.Element {
  return <GroupV2JoinDialog {...createProps()} />;
}

export function ApprovalRequired(): React.JSX.Element {
  return (
    <GroupV2JoinDialog
      {...createProps({
        approvalRequired: true,
        title: 'Approval required!',
      })}
    />
  );
}

export function WithAvatar(): React.JSX.Element {
  return (
    <GroupV2JoinDialog
      {...createProps({
        avatar: {
          url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
        },
        title: 'Has an avatar!',
      })}
    />
  );
}

export function WithOneMember(): React.JSX.Element {
  return (
    <GroupV2JoinDialog
      {...createProps({
        memberCount: 1,
        title: 'Just one member!',
      })}
    />
  );
}

export function AvatarLoadingState(): React.JSX.Element {
  return (
    <GroupV2JoinDialog
      {...createProps({
        avatar: {
          loading: true,
        },
        title: 'Avatar loading!',
      })}
    />
  );
}

export function Full(): React.JSX.Element {
  return (
    <GroupV2JoinDialog
      {...createProps({
        avatar: {
          url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
        },
        memberCount: 16,
        groupDescription: 'Discuss meets, events, training, and recruiting.',
        title: 'Underwater basket weavers (LA)',
      })}
    />
  );
}
