/* eslint-disable react/prop-types */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/prefer-stateless-function */
/* eslint-disable max-classes-per-file */
jest.mock('react-native-vector-icons', () => ({
  createIconSet: jest.fn(() => 'HeroIcon'),
  createIconSetFromIcoMoon: jest.fn(() => 'HeroIcon'),
}));

jest.mock('react-native', () => {
  const RN = jest.requireActual('react-native');
  const mockedAnimatedFunctions = {
    setImmediate: () => jest.fn(),
    start: jest.fn((callback?: (result: { finished: boolean }) => void) => {
      callback?.({ finished: true });
    }),
    stop: () => jest.fn(),
    _isUsingNativeDriver: () => jest.fn(),
    _startNativeLoop: () => jest.fn(),
  };

  RN.Animated.timing = () => mockedAnimatedFunctions;
  RN.Animated.spring = () => mockedAnimatedFunctions;
  RN.Animated.stagger = () => mockedAnimatedFunctions;

  return RN;
});

jest.mock('../src/utils/scale', () => ({
  scale: jest.fn((size) => size),
}));

jest.mock('react-native-pager-view', () => {
  const RealComponent = jest.requireActual('react-native-pager-view').default;
  const React = jest.requireActual('react');

  return class ViewPager extends React.Component<{
    children: React.ReactNode;
  }> {
    index = 0;

    setPage = (page: number) => {
      const { children } = this.props;

      this.index = Math.max(0, Math.min(page, React.Children.count(children)));
    };

    setPageWithoutAnimation = (page: number) => {
      const { children } = this.props;

      this.index = Math.max(0, Math.min(page, React.Children.count(children)));
    };

    render() {
      const { children } = this.props;
      return <RealComponent>{children}</RealComponent>;
    }
  };
});

jest.mock('@react-native-community/datetimepicker', () => {
  const React = jest.requireActual('react');

  return class Picker extends React.Component {
    render() {
      return React.createElement('Picker', this.props, this.props.children);
    }
  };
});

jest.mock('@ptomasroos/react-native-multi-slider', () => {
  const React = jest.requireActual('react');

  return class Slider extends React.Component {
    render() {
      return React.createElement(
        'MultiSlider',
        {
          ...(this.props ?? {}),
          testID: 'native-multi-slider',
        },
        this.props.children
      );
    }
  };
});

jest.mock('@react-native-community/slider', () => {
  const React = jest.requireActual('react');

  return class Slider extends React.Component {
    render() {
      return React.createElement('Slider', this.props, this.props.children);
    }
  };
});

jest.mock('react-native-webview', () => {
  const React = jest.requireActual('react');

  class WebView extends React.Component {
    render() {
      return React.createElement('WebView', this.props, this.props.children);
    }
  }

  return {
    WebView,
    default: WebView,
  };
});

jest.mock('@react-native-masked-view/masked-view', () => {
  const React = jest.requireActual('react');
  const { View } = jest.requireActual('react-native');

  const MaskedView = ({
    maskElement,
    children,
    style,
    testID,
  }: {
    maskElement: React.ReactNode;
    children: React.ReactNode;
    style?: object;
    testID?: string;
  }) => React.createElement(View, { style, testID }, maskElement, children);

  return { __esModule: true, default: MaskedView };
});

jest.mock('expo-linear-gradient', () => {
  const React = jest.requireActual('react');
  const { View } = jest.requireActual('react-native');

  return {
    LinearGradient: ({
      children,
      style,
    }: {
      children?: React.ReactNode;
      style?: object;
    }) => React.createElement(View, { style }, children),
  };
});

jest.mock('hero-editor/dist/app.js', () => ({ default: '' }));

jest.mock('react-native-gesture-handler', () => {
  const ReactNative = jest.requireActual('react-native');

  return {
    Swipeable: ReactNative.View,
    GestureHandlerRootView: ReactNative.View,
    FlatList: ReactNative.FlatList,
    RectButton: ReactNative.Button,
    TouchableOpacity: ReactNative.TouchableOpacity,
  };
});

jest.mock('@hero-design/react-native-month-year-picker', () => {
  const React = jest.requireActual('react');
  const { View, Text } = jest.requireActual('react-native');

  return {
    MonthYearPickerDialogueAndroid: ({ onChange }) => (
      <View
        onPress={() => {
          if (onChange) {
            onChange('dateSetAction', new Date('2019-09-01'));
          }
        }}
      >
        <Text>Android month year picker</Text>
      </View>
    ),
    MonthYearPickerViewIOS: ({ onChange }) => (
      <View
        onPress={() => {
          if (onChange) {
            onChange(new Date('2019-09-01'));
          }
        }}
      >
        <Text>IOS month year picker</Text>
      </View>
    ),
  };
});

export {};
