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 = [
  { KdId: '1653225', KdLabel: '0.98 ML Etanercept 50 MG/ML Auto-Injector [Enbrel]', EntityType: 'KdDrugRxNorm' },
  { KdId: '262095', KdLabel: 'atorvastatin 80 MG Oral Tablet [Lipitor]', EntityType: 'KdDrugRxNorm' },
  { KdId: '212233', KdLabel: 'Sertraline 25 MG Oral Tablet [Zoloft]', EntityType: 'KdDrugRxNorm' },
];

const initialValues = [
  { KdId: 'some drug', KdLabel: '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', 'Eq', initialValues);
    kdFilterModelRx = FilterItem('KdDrugRxNorm', 'KdId', 'KdDrugRxNorm', 'Eq', initialValuesRx);
    kdFilterModelOptions = [
      {
        label: 'DrugClass',
        modelOptions: {
          kdFilterModel,
          mainSelector: {
            visible: false,
            selected: '',
            optionValues: {
              anyOption: {
                visible: false,
              },
              userSpecifiedOption: {
                visible: false,
              },
            },
          },
        },
      },
      {
        label: 'DrugRx',
        modelOptions: {
          kdFilterModel: kdFilterModelRx,
          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();
    });

    fit('should set initialValues for first 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);
    });
  });
});
