import React from 'react';
import ReactDOM from 'react-dom';
import App, { IConnectionCompanyData } from './connection-map.component';

const {
	meta: { requestedEntityId: toyotaRequestId },
	data: toyotaData
}: {
	meta: {
		requestedEntityId: string;
	};
	data: Array<IConnectionCompanyData>;
} = require('./data/toyota-motor-corp.json');

const {
	meta: { requestedEntityId: misawaRequestId },
	data: misawaData
}: {
	meta: {
		requestedEntityId: string;
	};
	data: Array<IConnectionCompanyData>;
} = require('./data/misawa-homes-chugoku.json');

const {
	meta: { requestedEntityId: tataRequestId },
	data: tataData
}: {
	meta: {
		requestedEntityId: string;
	};
	data: Array<IConnectionCompanyData>;
} = require('./data/tata-steel.json');

const {
	meta: { requestedEntityId: broadcomRequestId },
	data: broadcomData
}: {
	meta: {
		requestedEntityId: string;
	};
	data: Array<IConnectionCompanyData>;
} = require('./data/broadcom.json');

const {
	meta: { requestedEntityId: broadcomTwoRequestId },
	data: broadcomTwoData
}: {
	meta: {
		requestedEntityId: string;
	};
	data: Array<IConnectionCompanyData>;
} = require('./data/broadcom-2.json');

const DATA: 'TOYOTA' | 'MISAWA' | 'TATA' | 'BROADCOM' | 'BROADCOMTWO' = 'TATA'; // change me for super fun times

let data: Array<IConnectionCompanyData>;
let reqId: string;

switch (DATA.toString()) {
	case 'TOYOTA':
		data = toyotaData;
		reqId = toyotaRequestId;
		break;
	case 'MISAWA':
		data = misawaData;
		reqId = misawaRequestId;
		break;
	case 'TATA':
		data = tataData;
		reqId = tataRequestId;
		break;
	case 'BROADCOM':
		data = broadcomData;
		reqId = broadcomRequestId;
		break;
	case 'BROADCOM2':
		data = broadcomTwoData;
		reqId = broadcomTwoRequestId;
}

document.addEventListener('DOMContentLoaded', function(event) {
	ReactDOM.render(
		<App
			connectionsData={data}
			requestId={reqId}
			onNavigateToCompanyPage={scoutId => {
				alert('Company page navigation attempt to ' + scoutId);
			}}
			onNavigateToConnectionMap={scoutId => {
				alert('Connection map page navigation attempt to ' + scoutId);
			}}
			onViewCompany={scoutId => {
				alert('onViewCompany attempt to ' + scoutId);
			}}
			onAddToTargetList={scoutId => {
				alert('Add to target list attempt ' + scoutId);
			}}
			onViewLatestNews={scoutId => {
				alert('Latest news navigation attempt to ' + scoutId);
			}}
			onBackAction={() => alert('back')}
		/>,
		document.getElementById('mount')
	);
});
