import { Bubble, Icon, TableColumn } from "@tencent/tea-component";
import { Product } from "../../generated/prisma.types";
import { modelsEnum } from "../../generated/models.index";
import { TeaInputsComponent } from "@gadmin2/react-common";

// 定制fields
export const fieldsRecipe = (draft: TeaInputsComponent<Product>) => {
  const nameField = draft['name'];
  nameField.validator = () => true
};

//定制columns
export const columnsRecipe = (draft: TableColumn<Product>[]) => {
  const publishedColumn = draft.find((column) => column.key === 'published');
  if(publishedColumn) {
    publishedColumn.header =  () => (
        <>
          状态
          <Bubble content="状态描述">
            <Icon type="info" />
          </Bubble>
        </>
      );
    
    publishedColumn.width = 100;
    publishedColumn.render = (row : Product) => {
      if (row.published === modelsEnum['Status']['PUBLISHED']) {
        return <span style={{ color: "green" }}>已发布</span>;
      }
        return <span style={{ color: "red" }}>未发布</span>;
    };
  }
};
