// Modules
import { useState, useEffect } from 'react';
import { Api } from '../helpers/api';
import { v4 as uuidv4 } from 'uuid';
// Components
import TableRow from './TableRow';
const ChartTable = ({ activeRow, setActiveRow, tabIndex, lang }) => {
const [dataTable, setDataTable] = useState();
// Functions
const rowActive = (num) => {
setActiveRow(num);
};
useEffect(() => {
// Table data fetch
if (tabIndex) {
const TableApi = new Api(
`https://tmex.gov.tm:8765/api/categories/${tabIndex}/tradings`,
// `http://tmex.gov.tm:8765/api/categories/8/tradings`,
dataTable,
setDataTable,
).get();
}
}, [tabIndex]);
return (
{lang === 'ru'
? 'Товарная позиция'
: lang === 'tm'
? 'Harydyň ady'
: lang === 'en'
? 'Product name'
: null}
{lang === 'ru'
? 'Изменение цены'
: lang === 'tm'
? 'Bahanyň üýtgeýşi'
: lang === 'en'
? 'Price change'
: null}
{lang === 'ru'
? 'Текущая цена'
: lang === 'tm'
? 'Häzirki baha'
: lang === 'en'
? 'Current price'
: null}
{dataTable
? dataTable.data.map((tableRow, index) => {
return index <= 2 ? (
7 ? 'title-hide' : null}
priceChange={tableRow.price_change}
price={tableRow.price}
currency={tableRow.currency}
onClick={() => rowActive(index)}
active={activeRow === index ? 'active' : ''}
/>
) : null;
})
: null}
);
};
export default ChartTable;