import { useEffect, useState } from "react";
import NodeTableComponent, {
  DataTemplateInterface,
} from "../NodeTableComponent/NodeTableComponent";
import { invoke } from "@tauri-apps/api/core";

export default function NTHeader() {
  const [data, setData] = useState<any[]>([]);
  // TODO: 这里要分64位和32位，最好让后端返回
  const dataTemplate: DataTemplateInterface = {
    signature: {
      name: "Signature",
      offset: 0,
      size: 4,
      value: 0,
      data_type: "hex",
      description: "PE文件的标志，可执行文件的标志是0x00004550",
    },
  };
  const command = "command_get_pe_data_nt_header";
  const columns = [
    {
      title: "字段名",
      dataIndex: "name",
      key: "name",
    },
    {
      title: "偏移",
      dataIndex: "offset",
      key: "offset",
      hexSwitch: true,
    },
    {
      title: "大小",
      dataIndex: "size",
      key: "size",
    },
    {
      title: "值",
      dataIndex: "value",
      key: "value",
      hexSwitch: true,
      editable: true,
    },
    {
      title: "描述信息",
      dataIndex: "description",
      key: "description",
    },
  ];

  useEffect(() => {
    invoke(command).then((res) => {
      setData(res as any);
    });
  }, []);

  return (
    <NodeTableComponent
      defaultData={data as any}
      dataTemplate={dataTemplate}
      columns={columns as any}
    ></NodeTableComponent>
  );
}
