import React, { useState, useEffect } from 'react';
import { classNames } from 'primereact/utils';
import { FilterMatchMode, FilterOperator } from 'primereact/api';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { Dropdown } from 'primereact/dropdown';
import { InputNumber } from 'primereact/inputnumber';
import { Button } from 'primereact/button';
import { ProgressBar } from 'primereact/progressbar';
import { Calendar } from 'primereact/calendar';
import { MultiSelect } from 'primereact/multiselect';
import { Slider } from 'primereact/slider';
import { TriStateCheckbox } from 'primereact/tristatecheckbox';
import { ToggleButton } from 'primereact/togglebutton';
import { Rating } from 'primereact/rating';
import { CustomerService } from '../service/CustomerService';
import { ProductService } from '../service/ProductService';
const TableDemo = () => {
const [customers1, setCustomers1] = useState(null);
const [customers2, setCustomers2] = useState([]);
const [customers3, setCustomers3] = useState([]);
const [filters1, setFilters1] = useState(null);
const [loading1, setLoading1] = useState(true);
const [loading2, setLoading2] = useState(true);
const [idFrozen, setIdFrozen] = useState(false);
const [products, setProducts] = useState([]);
const [expandedRows, setExpandedRows] = useState(null);
const representatives = [
{ name: "Amy Elsner", image: 'amyelsner.png' },
{ name: "Anna Fali", image: 'annafali.png' },
{ name: "Asiya Javayant", image: 'asiyajavayant.png' },
{ name: "Bernardo Dominic", image: 'bernardodominic.png' },
{ name: "Elwin Sharvill", image: 'elwinsharvill.png' },
{ name: "Ioni Bowcher", image: 'ionibowcher.png' },
{ name: "Ivan Magalhaes", image: 'ivanmagalhaes.png' },
{ name: "Onyama Limba", image: 'onyamalimba.png' },
{ name: "Stephen Shaw", image: 'stephenshaw.png' },
{ name: "XuXue Feng", image: 'xuxuefeng.png' }
];
const statuses = [
'unqualified', 'qualified', 'new', 'negotiation', 'renewal', 'proposal'
];
const customerService = new CustomerService();
const productService = new ProductService();
useEffect(() => {
setLoading2(true);
customerService.getCustomersLarge().then(data => { setCustomers1(getCustomers(data)); setLoading1(false) });
customerService.getCustomersLarge().then(data => { setCustomers2(getCustomers(data)); setLoading2(false); });
customerService.getCustomersMedium().then(data => setCustomers3(data));
productService.getProductsWithOrdersSmall().then(data => setProducts(data));
initFilters1();
}, []); // eslint-disable-line react-hooks/exhaustive-deps
const balanceTemplate = (rowData) => {
return (
{formatCurrency(rowData.balance)}
)
}
const getCustomers = (data) => {
return [...data || []].map(d => {
d.date = new Date(d.date);
return d;
});
}
const formatDate = (value) => {
return value.toLocaleDateString('en-US', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
});
}
const formatCurrency = (value) => {
return value.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
const initFilters1 = () => {
setFilters1({
'global': { value: null, matchMode: FilterMatchMode.CONTAINS },
'name': { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }] },
'country.name': { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }] },
'representative': { value: null, matchMode: FilterMatchMode.IN },
'date': { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }] },
'balance': { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.EQUALS }] },
'status': { operator: FilterOperator.OR, constraints: [{ value: null, matchMode: FilterMatchMode.EQUALS }] },
'activity': { value: null, matchMode: FilterMatchMode.BETWEEN },
'verified': { value: null, matchMode: FilterMatchMode.EQUALS }
});
}
const countryBodyTemplate = (rowData) => {
return (