import { css, cx } from "@linaria/core";
import { IconMore } from "@queenjs/icons";
import { Image, View } from "@queenjs/ui";
import { Dropdown, Menu } from "ant-design-vue";
import dayjs from "dayjs";
import { defineUI } from "queenjs";
import { any } from "vue-types";

export default defineUI({
  props: {
    record: any(),
  },
  emits: ["edit", "preview", "menu"],
  setup(props, { emit }) {
    return () => {
      const { record } = props;
      return (
        <div class={cx(itemStyles, "relative")}>
          <View ratio={1.4} class=" relative">
            <Image
              class="h-1/1 w-1/1 !object-contain bg-[#ebebeb]"
              src={record?.thumbnail}
            />
            {/* <Tag
              color="#E88B00"
              // color="rgba(0, 0, 0, 0.4)"
              class="absolute top-0 left-0 z-1 !rounded-none"
            >
              未发布
            </Tag> */}
            {/* <div class="absolute inset-0 flex items-center justify-center opacity-0 hover:opacity-100 transition-opacity">
              <div
                class="text-white icon_action w-60px leading-60px orange cursor-pointer rounded-1/2 text-center"
                onClick={() => emit("edit", props.record)}
              >
                编辑
              </div>
            </div> */}
          </View>
          <div class="item_footer rounded-b-4px flex items-center justify-between p-15px">
            <div class="w-0 flex-1">
              <div class="text-white text-bold truncate">{record.title}</div>
              <div class="flex items-center text-opacity-60 text-white text-12px mt-5px">
                {dayjs(record.updateTime).format("YYYY.MM.DD")}
              </div>
            </div>
            <Dropdown
              placement="bottom"
              overlay={
                <Menu class="w-90px">
                  <Menu.Item>
                    <div onClick={() => emit("menu", "rename")}>重命名</div>
                  </Menu.Item>
                  <Menu.Item>
                    <div onClick={() => emit("menu", "delete")}>删除</div>
                  </Menu.Item>
                </Menu>
              }
            >
              <IconMore class="ml-10px text-22px cursor-pointer" />
            </Dropdown>
          </div>
        </div>
      );
    };
  },
});

const itemStyles = css`
  .item_footer {
    background: #414141;
  }
  .icon_action {
    background-color: rgba(0, 0, 0, 0.5);
    &.orange {
      background-color: rgba(232, 139, 0, 0.5);
    }
  }
`;
