// material-ui
import * as React from 'react';
import * as DateUtils from "utils/DateUtils";
import { FiDataGrid } from "components/FiDataGrid";
import { FormattedMessage, useIntl } from "react-intl";
import {GET_ANNOUNCE_LIST} from "utils/ApiPathConst";
// ==============================|| EVENT TABLE ||============================== //

export default function SearchPublicNoticeTable({ searchCriteria, applyGridOnReady,applySearch }) {

    const intl = useIntl();
    const { locale } = intl;

    const [_searchCriteria, set_searchCriteria] = React.useState(searchCriteria);
    React.useEffect(() => {
        set_searchCriteria(searchCriteria);
    }, [searchCriteria]);

    const columns = [
        {
            field: 'announceDate',
            headerName: <FormattedMessage id="date"></FormattedMessage>,
            width: 250,
            cellClassName: 'announceDate',
            renderCell: (params) => {
                return DateUtils.dateValue(params?.value);
            },
        },
        {
            id: 'subject',
            field: 'subject',
            headerName: <FormattedMessage id="subject"></FormattedMessage>,
            minWidth: 400,
            renderCell: (params) => {
                return <>
                {locale === 'en' ?params.row.subjectEng:locale === 'zh-HK' ?params.row.subjectCht:params.row.subjectChs}
                </>
            },
        },
        {
            id: 'content',
            field: 'content',
            headerName: <FormattedMessage id="content"></FormattedMessage>,
            flex:1,
            minWidth: 400,
            renderCell: (params) => {
                return <>
                {locale === 'en' ?params.row.contentEng:locale === 'zh-HK' ?params.row.contentCht:params.row.contentChs}
                </>
            }
        },
    ];

    return (
        <div style={{ width: '100%' }}>
            <FiDataGrid
                columns={columns}
                customPageSize={10}
                getRowHeight={() => 'auto'}
                applyGridOnReady={applyGridOnReady}
                applySearch={applySearch}
                // doLoad={{
                //     url: GET_ANNOUNCE_LIST,
                //     params: _searchCriteria
                // }}
                doLoad={React.useMemo(() => ({
                    url: GET_ANNOUNCE_LIST,
                    params: _searchCriteria,
                }), [_searchCriteria])}
            />
        </div>
    );
}
