import React from 'react';
import {Table} from 'semantic-ui-react';
import {convertTime} from '../../../tools';

const LogItem = ({i18n, data}) => {
	if(!(i18n && i18n.t)) return null;
	let defMsg = '';
	if(/^(do|di)/i.test(data.iolabel)){
		defMsg = i18n.t('page.log.description.dio');
	}else if(/^leone/i.test(data.iolabel)){
		defMsg = i18n.t('page.log.description.leone');
	}else if(/^iogroup/i.test(data.iolabel)){
		defMsg = i18n.t('page.log.description.iogroup');
	}
	let msg = defMsg
		.replace(/\$io_label\$/, data.iolabel)
		.replace(/\$io_name\$/, data.ioname)
		.replace(/\$io_logic\$/, data.iosetting1)
		.replace(/\$io_trigger_time\$/, convertTime(data.ioeventtst))
		.replace(/\$io_trigger_status\$/, data.ioevent);
	return (
		<Table.Row>
			<Table.Cell>{convertTime(data.ioeventtst)}</Table.Cell>
			<Table.Cell>{data.iosetting3}</Table.Cell>
			<Table.Cell>{data.iosetting2}</Table.Cell>
			<Table.Cell>{data.ioevent}</Table.Cell>
			<Table.Cell>{msg}</Table.Cell>
		</Table.Row>
	)
}

export default LogItem;