import { css } from "@linaria/core";

import { defineComponent } from "vue";
import { useRouter, useRoute } from "vue-router";
import { any, string } from "vue-types";

export default defineComponent({
  props: {
    data: any(),
    activeKey: string(),
  },
  setup(props) {
    const router = useRouter();
    const route = useRoute();
    return () => {
      return (
        <div class={page}>
          {props.data &&
            props.data.map((e: CategoryItem) => {
              return (
                <div
                  class={["tabs_item", e._id == props.activeKey ? "cur" : ""]}
                  key={e._id}
                  onClick={() => {
                    router.push({ path: route.path, query: { cid: e._id } });
                  }}
                >
                  <div class={"name"}>{e.name}</div>
                </div>
              );
            })}
        </div>
      );
    };
  },
});
const page = css`
  width: 100%;
  display: flex;
  align-items: center;
  margin-bottom: 25px;
  overflow-x: auto;
  .tabs_item {
    position: relative;
    margin-right: 30px;
    height: 24px;
    line-height: 24px;
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    .name {
      position: relative;
      z-index: 2;
    }
    &.cur {
      font-weight: 600;
      color: #333;
      &::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;
        z-index: 1;
        width: 100%;
        height: 8px;
        background-color: var(--vt-c-primary);
      }
    }
  }
`;
