import { cx } from "@linaria/core";
import { Image } from "@queenjs/ui";
import { Button } from "ant-design-vue";
import { defineComponent } from "vue";
import { any, bool } from "vue-types";

export default defineComponent({
  props: {
    record: any().isRequired,
    active: bool().def(false),
  },
  emits: ["replace", "click"],
  setup(props, { emit }) {
    return () => {
      const { active, record } = props;
      return (
        <div
          style={{ backgroundColor: "#303030" }}
          class={cx(
            "flex items-center py-6px px-12px rounded-4px border-1 border-solid cursor-pointer hover:opacity-80 transition-all",
            active ? "border-orange-200" : "border-transparent"
          )}
          onClick={() => emit("click", record)}
        >
          <Image src={record.thumbnail} class="w-48px rounded-4px" />
          <div class="ml-10px flex-1 mr-5px w-0">
            {record.meshName || "未命名"}
          </div>
          <Button
            type="primary"
            ghost
            size="small"
            onClick={(e) => {
              e.stopPropagation();
              emit("replace", record);
            }}
          >
            替换
          </Button>
        </div>
      );
    };
  },
});
