import React from 'react';
import PropTypes from 'prop-types';
import { VtxPageLayout, VtxSearch, VtxDatagrid } from '@vtx/components';
import { Form } from 'antd';
import { useAntdTable } from 'ahooks';
import { getBottlePageData } from './api';
import ParameterSelect from '../param-config-select';
import VtxGasCylinderFileModal from '../vtx-gas-cylinder-file-modal';
const { TableLayout } = VtxPageLayout;
const BottleList = ({ id }) => {
    const [form] = Form.useForm();
    const columns = [
        {
            title: '气瓶登记证编号',
            dataIndex: 'registerNo',
            render: (text, record) => {
                const { id, registerNo } = record;
                return <VtxGasCylinderFileModal id={id} label={registerNo} />;
            },
        },
        {
            title: '下次检验日期',
            dataIndex: 'nextCheckDate',
        },
        {
            title: '报废日期',
            dataIndex: 'scrapDate',
        },
        {
            title: '当前所处位置',
            dataIndex: 'address',
        },
        {
            title: '使用状态',
            dataIndex: 'bottleStatus',
            render: (text, record) => {
                return record?.bottleStatus?.value;
            },
        },
    ];
    const { refresh, search, tableProps } = useAntdTable(getBottlePageData(id), {
        defaultPageSize: 10,
        form,
        refreshDeps: [id],
    });
    const { submit, reset } = search;
    const { current, pageSize } = tableProps?.pagination;
    const datagridProps = {
        ...tableProps,
        columns,
        toolbarTilte: '查询结果',
        startIndex: (current - 1) * pageSize + 1,
        onRefresh: refresh,
        toolbar: false,
    };

    return (
        <TableLayout.Page>
            <TableLayout.Search>
                <Form form={form}>
                    <VtxSearch
                        titles={['使用状态']}
                        gridWeight={[1]}
                        onConfirm={submit}
                        onClear={reset}
                    >
                        <Form.Item name="bottleStatus">
                            <ParameterSelect code="BOTTLE_STATUS" />
                        </Form.Item>
                    </VtxSearch>
                </Form>
            </TableLayout.Search>
            <TableLayout.Content>
                {/* <TableLayout.Card>
                    <VtxStatisticsColumn>
                        <VtxStatisticsColumn.Item label="从业人员总数" value={total} />
                    </VtxStatisticsColumn>
                </TableLayout.Card> */}
                <TableLayout.Table>
                    <VtxDatagrid {...datagridProps} />
                </TableLayout.Table>
            </TableLayout.Content>
        </TableLayout.Page>
    );
};

BottleList.propTypes = {
    id: PropTypes.string,
};

export default BottleList;
