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

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

    return (
        <SmartList
            resource="Product"
            searchFields={["Name", "Description"]}
        >
            <Table.Column
                dataIndex="Name"
                title={t("product.name")}
                sorter
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                dataIndex="Description"
                title={t("product.description")}
                render={(value: string) => (
                    <span style={{ fontSize: '0.9em' }}>
                        {value?.length > 50 ? `${value.substring(0, 50)}...` : value}
                    </span>
                )}
                sorter
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                title={t("buttons.list")}
                dataIndex="actions"
                render={(_, record: BaseRecord) => (
                    <Space>
                        <EditButton hideText size="small" recordItemId={record.Oid} />
                        <DeleteButton hideText size="small" recordItemId={record.Oid} />
                    </Space>
                )}
            />
        </SmartList>
    );
};
