import React from "react";
import { BaseRecord } from "@refinedev/core";
import { EditButton, ShowButton, DeleteButton } from "@refinedev/antd";
import { Table, Space, Tag } from "antd";
import { SmartList } from "@cundi/refine-xaf";
import { useTranslation } from "react-i18next";

export const OrderList: React.FC = () => {
    const { t } = useTranslation();

    return (
        <SmartList
            resource="Order"
            searchFields={["OrderNumber", "CustomerName"]}
        >
            <Table.Column
                dataIndex="OrderNumber"
                title={t("order.orderNumber")}
                sorter
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                dataIndex="OrderDate"
                title={t("order.orderDate")}
                sorter
                render={(value: string) => value ? new Date(value).toLocaleDateString() : "-"}
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                dataIndex="CustomerName"
                title={t("order.customerName")}
                sorter
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                dataIndex="TotalAmount"
                title={t("order.totalAmount")}
                sorter
                render={(value: number) => value ? `$${value.toFixed(2)}` : "$0.00"}
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                title={t("buttons.list")}
                dataIndex="actions"
                render={(_, record: BaseRecord) => (
                    <Space>
                        <EditButton hideText size="small" recordItemId={record.Oid} />
                        <ShowButton hideText size="small" recordItemId={record.Oid} />
                        <DeleteButton hideText size="small" recordItemId={record.Oid} />
                    </Space>
                )}
            />
        </SmartList>
    );
};
