import React from 'react';
import { Status } from '@theorchard/suite-components';

const StatusIndicator = ({
    status,
    showText = true,
}: {
    status?: string;
    showText?: boolean;
}) => {
    if (!status) return null;
    const variant: 'success' | 'loading' | 'error' | undefined = (
        {
            success: 'success',
            in_progress: 'loading',
            failure: 'error',
        } as const
    )[status];
    return (
        variant && (
            <Status
                variant={variant}
                filled={true}
                text={
                    showText
                        ? status
                              .replace(/_/g, ' ')
                              .replace(/\b\w/g, c => c.toUpperCase())
                        : ''
                }
            />
        )
    );
};

export default StatusIndicator;
