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

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

    return (
        <SmartList
            resource="DrawioTest"
            searchFields={["Name"]}
        >
            <Table.Column
                dataIndex="Name"
                title={t("drawioTest.name")}
                sorter
                // @ts-ignore
                defaultVisible
            />
            <Table.Column
                dataIndex="XmlContent"
                title={t("drawioTest.xmlContent")}
                render={(value: string) => (
                    <span style={{ fontSize: '0.9em', color: '#666' }}>
                        {value ? `${value.substring(0, 50)}...` : "-"}
                    </span>
                )}
                // @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>
    );
};
