import React from 'react';
import { renderInAppContext } from '@theorchard/suite-testing';
import { EMPTY_CHAR } from 'src/constants';
import TimedReleaseTable from '../TimedReleaseTable';

describe('TimedReleaseTable', () => {
    const renderComponent = (dateTime: string) => {
        return renderInAppContext(<TimedReleaseTable dateTime={dateTime} />);
    };

    test('renders table with correct timezones', () => {
        const dateTime = '2023-10-01T12:00:00Z';
        const { getByText } = renderComponent(dateTime);

        expect(getByText('Pacific Standard Time (PST)')).toBeInTheDocument();
        expect(getByText('Eastern Standard Time (EST)')).toBeInTheDocument();
        expect(getByText('Greenwich Mean Time (GMT/UTC)')).toBeInTheDocument();
        expect(getByText('Central European Time (CET)')).toBeInTheDocument();
        expect(getByText('India Standard Time (IST)')).toBeInTheDocument();
        expect(
            getByText('Australian Eastern Daylight Time (AEDT)')
        ).toBeInTheDocument();
    });

    test('renders correct local times for each timezone', () => {
        const dateTime = '2023-10-01T12:00:00Z';
        const { getByTestId } = renderComponent(dateTime);

        expect(getByTestId('timed-release-UTC-8')).toHaveTextContent(
            '5:00 AM, 01 Oct 2023'
        );
        expect(getByTestId('timed-release-UTC-5')).toHaveTextContent(
            '8:00 AM, 01 Oct 2023'
        );
        expect(getByTestId('timed-release-UTC+0')).toHaveTextContent(
            '12:00 PM, 01 Oct 2023'
        );
        expect(getByTestId('timed-release-UTC+1')).toHaveTextContent(
            '2:00 PM, 01 Oct 2023'
        );
        expect(getByTestId('timed-release-UTC+5:30')).toHaveTextContent(
            '5:30 PM, 01 Oct 2023'
        );
        expect(getByTestId('timed-release-UTC+11')).toHaveTextContent(
            '11:00 PM'
        );
    });

    test('renders empty char when dateTime is Invalid date', () => {
        const { getByTestId } = renderComponent('not-date-at-all');
        expect(getByTestId('timed-release-UTC+11')).toHaveTextContent(
            EMPTY_CHAR
        );
    });

    test('shows -1 days diff badge when local date is different from base by a day', () => {
        const dateTime = '2025-10-01T00:00:00Z';
        const { getByTestId } = renderComponent(dateTime);

        expect(getByTestId('UTC-5-badge')).toHaveTextContent('-1 Day');
    });

    test('shows +1 days diff badge when local date is different from base by a day', () => {
        const dateTime = '2025-10-01T23:00:00Z';
        const { getByTestId } = renderComponent(dateTime);

        expect(getByTestId('UTC+11-badge')).toHaveTextContent('+1 Day');
    });
});
