import React from 'react';
import { Invoice } from '../../..';
import 'antd/dist/antd.css';
import { LineAttributeType } from '@/Invoice/InvoiceController';
import idGenerator from '@/Invoice/tools/idGenerator';

export default () => {

    const invoiceController = React.useMemo(() => new Invoice.InvoiceController(), [])

    React.useEffect(() => {
        invoiceController.setColumnsConfig = e => {
            const l = [...e];
            l.splice(-1, 0, {
                title: '扩展',
                dataIndex: 'zk',
                key: 'zk',
                align: 'right',
            });
            return l;
        };

        setTimeout(() => {
            invoiceController.run(async s => {
                s.goodsListState.columnshide = Array.from(new Set([...s.goodsListState.columnshide, 'lineAttribute']))
                s.goodsListState.goodsList = lines.map(e => ({ $index: idGenerator(), ...e }));
            })
        }, 1000)
    }, [])

    return (
        <Invoice controller={invoiceController} />
    )
};

const children = []
for (let i = 0; i <= 10; i++) {
    children.push({
        itemName: `项目名称${i}`,
        lineAttribute: LineAttributeType.正常,
        lineAmountExcludeTax: 9.99,
        lineAmountIncludeTax: 10.29,
        taxRate: 3,
        taxAmount: 0.3,
    });
}


const lines: any[] = [
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 1,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": null,
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "套",
        "quantity": 1.0000000000001,
        "taxRate": 0.06,
        "priceExcludeTax": 0.0000000000001,
        "priceIncludeTax": 2.12,
        "amountTax": 0.3,
        "lineAmountExcludeTax": 5,
        "lineAmountIncludeTax": 5.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": "1714491422291693568",
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "taxAmount": 1
    },
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 2,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": "",
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "",
        "quantity": -1,
        "taxRate": 0.06,
        "priceExcludeTax": null,
        "priceIncludeTax": null,
        "amountTax": -0.06,
        "lineAmountExcludeTax": 2,
        "lineAmountIncludeTax": 2.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": "1714491422291693568",
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "taxAmount": 1,
        "children": children.map(e => ({ ...e, $index: idGenerator(), }))
    },
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 3,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": null,
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "套",
        "quantity": 1,
        "taxRate": 0.06,
        "priceExcludeTax": 2,
        "priceIncludeTax": 2.12,
        "amountTax": 0.12,
        "lineAmountExcludeTax": 5,
        "lineAmountIncludeTax": 5.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": null,
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "taxAmount": 1
    },
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 3,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": null,
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "套",
        "quantity": 1,
        "taxRate": 0.06,
        "priceExcludeTax": 2,
        "priceIncludeTax": 2.12,
        "amountTax": 0.12,
        "lineAmountExcludeTax": 5,
        "lineAmountIncludeTax": 5.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": null,
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "taxAmount": 1,
        "children": children.map(e => ({ ...e, $index: idGenerator(), }))
    },
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 3,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": null,
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "套",
        "quantity": 1,
        "taxRate": 0.06,
        "priceExcludeTax": 2,
        "priceIncludeTax": 2.12,
        "amountTax": 0.12,
        "lineAmountExcludeTax": 5,
        "lineAmountIncludeTax": 5.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": null,
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "taxAmount": 1
    },
    {
        "serialNumber": "1714491422279110656",
        "lineNumber": 3,
        "taxCode": "3070401000000000000",
        "taxName": "信息技术服务",
        "specification": null,
        "itemName": "技术服务费",
        "itemCode": "z",
        "unit": "套",
        "quantity": 1,
        "taxRate": 0.06,
        "priceExcludeTax": 2,
        "priceIncludeTax": 2.12,
        "amountTax": 0.12,
        "lineAmountExcludeTax": 5,
        "lineAmountIncludeTax": 5.3,
        "lineAttribute": LineAttributeType.正常,
        "discountGroup": null,
        "favouredPolicyMark": false,
        "favouredPolicyName": null,
        "zeroTaxRateFlag": null,
        "referenceLines": null,
        "version": 0,
        "shorthand": "布料",
        "taxAmount": 1
    }
]

for (let i = 0; i <= 100; i++) {
    lines.push({
        $index: idGenerator(),
        itemName: `项目名称${100 + i}`,
        lineAttribute: LineAttributeType.正常,
        lineAmountExcludeTax: 9.99,
        lineAmountIncludeTax: 10.29,
        taxRate: 3,
        taxAmount: 0.3,
    });
}