<template>
  <div class="focus_item flex items-center justify-between">
    <div class="focus_left flex items-center">
      <Icon type="icon-cur-star" />
      <span class="ml-2">{{
        `${detailInfo.eventCode}/${detailInfo.eventTitle}`
      }}</span>
    </div>
    <div v-if="from !== 'detail'">
      <div v-if="!isFocus" class="focus_right" @click="onFocus">
        <a-button>
          <Icon type="icon-cur-star" />
          {{ $t("FOCUS_ON") }}</a-button
        >
      </div>
      <div v-else class="focus_right" @click="onFocus">
        <a-button type="primary">
          <Icon type="icon-cur-star" />
          {{ $t("FOLLOWED") }}</a-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import ApiConstant from "@/api/ApiConstant";
import { Icon } from "@mega-design/ui-vue";

export default {
  name: "EventFocusInfo",
  components: { Icon },
  props: {
    detailInfo: {
      type: Object,
      default() {
        return {};
      },
    },
    from: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      activeKey: "a",
      // eslint-disable-next-line
      passImg: require("@/assets/img/pass.png"),
      // eslint-disable-next-line
      vetoImg: require("@/assets/img/veto.png"),
      isFocus: false,
      isCilck: false,
    };
  },
  computed: {
    ...mapState({
      systemConfig: (state) => state.app.systemConfig,
    }),
  },
  watch: {
    "detailInfo.currentUserConcernFlag": {
      handler(newVal, oldVal) {
        if (newVal === "Y") {
          this.isFocus = true;
        }
      },
      deep: true,
      immediate: true,
    },
  },
  mounted() {},
  methods: {
    onFocus() {
      if (this.isCilck) return;
      this.isCilck = true;
      const params = {
        eventId: this.detailInfo.id,
      };
      let url = "/api/est/event/concern";
      if (this.isFocus) {
        url = "/api/est/event/unconcern";
      }
      this.$axios
        .put(`${ApiConstant.PREFIX_CORE}${url}`, params)
        .then(() => {
          this.isCilck = false;
          this.isFocus = !this.isFocus;
          if (this.isFocus) {
            this.$message.success(
              `${this.$t("FOCUS_ON")} ${this.$t("SUCCESS")}`
            );
          } else {
            this.$message.success(`${this.$t("CANCEL")} ${this.$t("SUCCESS")}`);
          }
        })
        .catch((e) => {
          this.isCilck = false;
          this.confirmLoading = false;
        });
    },
  },
};
</script>
<style lang="less" scoped>
.focus_item {
  width: 100%;
  height: 58px;
  padding: 0 13px;
  border-bottom: 8px solid #f0f2f5;
  .focus_left {
    height: 100%;
    color: rgba(0, 104, 150, 1);
    span {
      font-size: 14px;
      font-weight: 400;
      color: #666;
    }
  }
}
</style>
