<template>
  <div class="myBooking xl:tw-max-w-[1246px] xl:tw-mx-auto">
    <div class="xl:tw-flex xl:tw-justify-between xl:tw-items-start">
      <userSidebar
        :userData="userData"
        :firstName="firstName"
        :lastName="lastName"
        class="tw-hidden xl:tw-block"
      >
      </userSidebar>
      <!-- <div class="xl:tw-hidden"></div> -->
      <div
        class="tw-bg-transparent xl:tw-bg-white xl:tw-p-[30px] xl:tw-rounded-[20px] xl:tw-min-w-[900px] xl:tw-max-w-[900px]"
      >
        <div
          class="tw-flex tw-flex-col md:tw-flex-row md:tw-justify-between md:tw-items-center tw-mb-[20px] md:tw-mb-[34px]"
        >
          <div
            class="tw-text-[20px] tw-font-bold tw-text-base-primary tw-mb-[20px] md:t24 md:tw-mb-0"
          >
            <two-dots class="tw-mr-[30px]"></two-dots>{{ $t("My Bookings") }}
          </div>
        </div>
        <bookingListContent
          :width="width"
          :userData="userData"
        ></bookingListContent>
      </div>
    </div>
  </div>
</template>
<script>
import TwoDots from "@/components/TwoDots";
import bookingListContent from "@/components/user/bookingListContent.vue";
import userSidebar from "@/components/user/userSidebar.vue";
export default {
  name: "myBooking",
  layout: "profile_gray",

  components: {
    TwoDots,
    bookingListContent,
    userSidebar,
  },
  data() {
    return {
      firstName: "",
      lastName: "",
      userData: {},
      width: 0,
      youMightLikeList: [],
      countrycode: [],
      regionName: [],
    };
  },
  created() {
    this.fetchUserData();
    // this.getLocationName();
    // this.getYouMightLikeData();
    if (process.browser) {
      window.addEventListener("resize", this.handleResize);
    }
    this.handleResize();
  },
  mounted() {
    this.$nextTick(() => {
      window.addEventListener("resize", this.onResize);
    });     
  },
  destroyed() {
    if (process.browser) {
      window.removeEventListener("resize", this.handleResize);
    }
  },
  methods: {
    patchUserData() {
      // if (this.width < 1366) {
      //   this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
      // }
      
      this.validators();
      // if (this.validators()) {
        // this.userData.prefer_country = JSON.stringify(this.languageSelect);
        // if (this.$vuetify.breakpoint.name !== "xs") {
        //   this.userData.birth_date =
        //     this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
        //   if (this.userData.birth_date.length < 10) {
        //     this.userData.birth_date = null;
        //   }
        // }
        
        const patchData = JSON.parse(JSON.stringify(this.userData));
        this.$axios
          .post(
            `/trending/api/Members/Member`, patchData
          )
          .then((response) => {
            //console.log(JSON.stringify(response));
            if (response.status == 200) {
              this.successUpdate = !this.successUpdate;
              setTimeout(() => {
            this.successUpdate = !this.successUpdate;
          }, 1000);
            }
            this.fetchUserData();

          })
          .catch((error) => {
            console.log(error);
          });
    },
    fetchUserData() {
      this.$axios
        .get(
          `/trending/api/Members/Info`
        )
        .then((response) => {
          //console.log(JSON.stringify(response));
          if(response && response.data && response.data.DATA && response.data.DATA.rel){
            let data = response.data.DATA.rel
            if(data){
              this.userData = data;
              this.firstName = this.userData.FirstName;
              this.lastName = this.userData.LastName;

            }
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    logout() {
      this.$auth.$storage.removeUniversal("jwt");
      this.$auth.$storage.removeUniversal("userPicture");
      this.$auth.$storage.removeUniversal("userLastName");
      this.$auth.$storage.removeUniversal("userBeforePath");

      if (width < 1024) {
        this.$router.push(this.localePath("/"));
      } else {
        this.$router.push(this.localePath("/user"));
      }
      this.$auth.logout();
    },
    // async getLocationName() {
    //   this.$axios
    //     .get(
    //       `/t/exhibitions/locations?lang=${this.$i18n.localeProperties["langQuery"]}&sort=False`
    //     )
    //     .then((response) => {
    //       this.regionName = response.data.region_ori;
    //       this.countrycode = response.data.country_ori;
    //     })
    //     .catch((error) => console.log(error));
    // },
    // async getYouMightLikeData() {
    //   this.$axios
    //     .get(
    //       `https://dev-api-console.showeasy.com/user-services/advertisements?region=0&country=0&city=0&expo=0&counts=3&lang_code=${this.$i18n.localeProperties["langQuery"]}`
    //     )
    //     .then((res) => {
    //       this.youMightLikeList = res.data;
    //     })
    //     .catch((error) => console.log(error));
    // },
    handleResize() {
      if (process.browser) {
        this.width = window.innerWidth;
      }
    },
  },
};
</script>

<style scoped lang="scss"></style>