import React from 'react';
import {Table, Button} from 'semantic-ui-react';

const ListItem = ({i18n, user, openModal, delUser}) => {
	let write = sessionStorage.getItem('write_privilege');
	let account = sessionStorage.getItem('account');

	return (
		<Table.Row>
			<Table.Cell>{user.account}</Table.Cell>
			<Table.Cell>
				{user.write_privilege == 1 ? 'W' : ''}{user.write_privilege == 1 && user.read_privilege == 1 ? ' / ' : ''}{user.read_privilege == 1 ? 'R' : ''}
			</Table.Cell>
			<Table.Cell>
				{
					(write == 1 && (user.account != 'admin' || (account == 'admin') ) ) || account == user.account ? 
						<Button type="button" content={i18n && i18n.t ? i18n.t('page.userlist.table.button.edit') : ''} onClick={() => openModal(user.account)}/> :
						null 
				}
				{write == 1 && user.account != 'admin' ? <Button type="button" content={i18n && i18n.t ? i18n.t('page.userlist.table.button.del') : ''} onClick={()=>delUser(user.account)}/> : null }
			</Table.Cell>
		</Table.Row>
	)
}

export default ListItem;