import React from "react";
import {Drawer} from "antd";
import {ProColumns, ProDescriptions, ProDescriptionsItemProps} from "@ant-design/pro-components";

export type ColumnDrawProps = {
  handleDrawer: (id?: any)=>void;
  isShowDetail: boolean;
  columns: ProColumns<API.ModelImage>[];
  currentRow: API.ModelImage | undefined;
};


const ColumnDrawer: React.FC<ColumnDrawProps> = (props) => {

  return (
    <Drawer
      width={500}
      open={props.isShowDetail}
      onClose={() => {
        props.handleDrawer();
      }}
      closable={true}
    >
      {props.currentRow?.id && (
        <ProDescriptions<API.ModelImage>
          column={2}
          title={props.currentRow?.id}
          request={async () => ({
            data: props.currentRow || {},
          })}
          params={{
            id: props.currentRow?.id,
          }}
          columns={props.columns.filter((item)=>{
            // update 对原内容项重写
            if(item.dataIndex === 'name'){
              item.render = (dom) => {
                return (<a>{dom}</a>)
              }
            }
            return item
          }) as ProDescriptionsItemProps<API.ModelImage>[]}
        />
      )}
    </Drawer>
  )
}
export {ColumnDrawer}

