import React from 'react';
import { mount } from 'enzyme';
import karmadataTheme from '../../themes/karmadata.scss';
import { FilterItem } from 'karmadata';
import renderer from 'react-test-renderer';

import KdSelectEntityMultiple from '../../components/KdSelectEntityMultiple';
import { chicklets, events, apiOptions } from '../__utils';

const initialValuesRx = [
  { value: '1653225', label: '0.98 ML Etanercept 50 MG/ML Auto-Injector [Enbrel]', EntityType: 'KdDrugRxNorm' },
  { value: '262095', label: 'atorvastatin 80 MG Oral Tablet [Lipitor]', EntityType: 'KdDrugRxNorm' },
  { value: '212233', label: 'Sertraline 25 MG Oral Tablet [Zoloft]', EntityType: 'KdDrugRxNorm' },
];
const initialValues = [
  { value: 'some drug', label: 'some drug', EntityType: 'KdDrugClassEPC' },
];


const props = {
  events,
  chicklets,
  api: apiOptions,
};

describe('KdSelectEntityMultiple', () => {
  let mainSelector;
  let kdFilterModel;
  let kdFilterModelRx;
  let kdFilterModelOptions;
  beforeEach(() => {
    kdFilterModel = FilterItem('KdDrugClassEPC', 'KdId', 'KdDrugClassEPC');
    kdFilterModelRx = FilterItem('KdDrugRxNorm', 'KdId', 'KdDrugRxNorm');
    kdFilterModelOptions = [
      {
        label: 'DrugClass',
        modelOptions: {
          kdFilterModel,
          selectedValuesInitial: initialValues,
          mainSelector: {
            visible: false,
            selected: '',
            optionValues: {
              anyOption: {
                visible: false,
              },
              userSpecifiedOption: {
                visible: false,
              },
            },
          },
        },
      },
      {
        label: 'DrugRx',
        modelOptions: {
          kdFilterModel: kdFilterModelRx,
          selectedValuesInitial: initialValuesRx,
          mainSelector: {
            visible: false,
            selected: '',
            optionValues: {
              anyOption: {
                visible: false,
              },
              userSpecifiedOption: {
                visible: false,
              },
            },
          },
        },
      },
    ];

    mainSelector = {
      visible: false,
      selected: '',
      optionValues: {
        anyOption: {
          visible: false,
        },
        customOptions: kdFilterModelOptions,
        userSpecifiedOption: {
          visible: true,
        },
      },
    };
  });


  describe('Setup', () => {
    it('renders correctly', () => {
      const tree = renderer.create(
        <KdSelectEntityMultiple
          theme={karmadataTheme}
          mainSelector={mainSelector}
          {...props}
        />
      ).toJSON();
      expect(tree).toMatchSnapshot();
    });

    it('should set initialValues for each kdModel', () => {
      const wrapper = mount(
        <KdSelectEntityMultiple
          theme={karmadataTheme}
          mainSelector={mainSelector}
          {...props}
        />);
      const filterValues = kdFilterModel.getSelected().length + kdFilterModelRx.getSelected().length;
      expect(wrapper.node.getChicklets().length).toBe(filterValues);
      expect(kdFilterModel.getSelected().length).toBe(initialValues.length);
      expect(kdFilterModelRx.getSelected().length).toBe(initialValuesRx.length);
    });
  });
});
