import React from 'react';
import ReactTestRenderer from 'react-test-renderer';
import Adapter from 'enzyme-adapter-react-16/build/index';
import Enzyme from 'enzyme/build/index';
import { ConsoleMock } from 'app/testUtils/consoleMock';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { PaymentDetailsBalanceModal } from './paymentDetailsBalanceModal';

jest.mock('app/shared/store/ui/uiSelectors', () => ({
  getScreenWidth: jest.fn(() => 1300), 
}));

jest.mock('../store/paymentDetails.selectors', () => ({
  createPaymentDetailsLoadingSelector: jest.fn(() => () => false),
  selectPaymentDetailsDate: jest.fn(() => '2013-11-13'),
  selectPaymentDetailsBalanceModalState: jest.fn(() => true),
}));

jest.mock('../store/paymentTables.selectors', () => ({
  selectBalanceModalOverviewData: jest.fn(() => [
    {
      label: 'Average Pool Points',
      total: 13,
    },
    {
      label: 'Vessel Pool Points',
      total: 7,
    },
    {
      label: 'Average TCE pool (USD)*',
      total: 8,
    },
  ]),
  selectBalanceModalVesselOverviewData: jest.fn(() => [
    {
      label: 'Total allocated cash',
      total: 1,
      perDay: 2,
    },
    {
      label: 'Current period - Bunker Adjustment',
      total: 3,
      perDay: 4,
    },
    {
      label: 'Previous period adjustment - Bunker Adjustment',
      total: 5,
      perDay: 6,
    },
    {
      label: 'Current period - Scrubber Bonus',
      total: 11,
      perDay: 12,
    },
    {
      label: 'Previous period adjustment - Scrubber Bonus',
      total: 13,
      perDay: 14,
    },
    {
      label: 'WAF, DTA & CBP',
      total: 15,
      perDay: 16,
    },
    {
      label: 'Total distribution',
      total: 17,
      perDay: 18,
    },
    {
      label: 'On-account days',
      total: 19,
    },
    {
      label: 'Balance month days',
      total: 20,
    },
    {
      label: 'On-hire days total',
      total: 21,
    },
  ]),
  selectBalanceModalPaymentBreakdownData: jest.fn(() => [
    {
      label: 'Total distribution for month',
      total: 1,
    },
    {
      label: 'On-Account Payment',
      total: 2,
    },
    {
      label: 'Total payment related to current period',
      total: 3,
      highlighted: true,
    },
    {
      label: 'Current period - Pool earnings',
      total: 4,
    },
    {
      label: 'Current period - Actual/Impaired earnings',
      total: 5,
    },
    {
      label: 'Previous period adjustment - Pool earnings',
      total: 6,
    },
    {
      label: 'Previous period adjustment - Actual/Impaired earnings',
      total: 7,
    },
    {
      label: 'Owner expenses',
      total: 8,
    },
    {
      label: 'Working capital',
      total: 9,
    },
    {
      label: 'Balance Payment current period',
      total: 10,
      highlighted: true,
    },
  ]),
  selectBalanceModalPreviousBunkerAdjustmentYears: jest.fn(() => [
    '2019',
    '2020',
    '2021',
  ]),
  selectBalanceModalPreviousBunkerAdjustmentData: jest.fn(() => [
    {
      label: 'January',
      2019: 1,
      2020: 2,
      2021: 3,
    },
    {
      label: 'February',
      2019: 4,
      2020: 5,
      2021: 6,
    },
    {
      label: 'March',
      2019: 7,
      2020: 8,
      2021: 9,
    },
    {
      label: 'April',
      2019: 10,
      2020: 11,
      2021: 12,
    },
    {
      label: 'May',
      2019: 13,
      2020: 14,
      2021: 15,
    },
    {
      label: 'June',
      2019: 16,
      2020: 17,
      2021: 18,
    },
    {
      label: 'July',
      2019: 19,
      2020: 20,
      2021: 21,
    },
    {
      label: 'August',
      2019: 22,
      2020: 23,
      2021: 24,
    },
    {
      label: 'September',
      2019: 25,
      2020: 26,
      2021: 27,
    },
    {
      label: 'October',
      2019: 28,
      2020: 29,
      2021: 30,
    },
    {
      label: 'November',
      2019: 31,
      2020: 32,
      2021: 33,
    },
    {
      label: 'December',
      2019: 34,
      2020: 35,
      2021: 36,
    },
  ]),
  selectPreviousBunkerAdjustmentSummary: jest.fn(() => ({
    label: 'Total',
    2019: 210,
    2020: 222,
    2021: 334,
  })),
}));

jest.mock('app/modules/vesselDetails/root/store/vesselDetails.selectors', () => ({
  selectVesselName: jest.fn(() => 'Vessel Name'),
}));

describe('Payment details on account modal tests', () => {
  Enzyme.configure({ adapter: new Adapter() });

  const mockStore = configureStore();
  let store;

  let consoleMock;

  beforeEach(() => {
    consoleMock = new ConsoleMock();
    store = mockStore({});
  });

  afterEach(() => {
    consoleMock.destroy();
  });


  it('renders correctly', () => {
    const tree = ReactTestRenderer
      .create(
        <Provider store={store}>
          <PaymentDetailsBalanceModal />
        </Provider>
      )
      .toJSON();
    expect(tree).toMatchSnapshot();
    expect(console.error).not.toBeCalled();
  });
});
