<script setup>
import { ref } from "vue";
import Avatar from "@/components/Avatar.vue";

import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);

const props = defineProps({
  editAvatar: {
    type: Function,
    default: () => {},
  },
});

const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;

const toEditPage = (type) => {
  uni.navigateTo({
    url: "/pages/edit-profile?type=" + type,
  });
};

const toSignInPage = () => {
  uni.navigateTo({
    url: "/pages/signin",
  });
};
</script>

<template>
  <view
    class="profile"
    :style="{
      paddingTop: statusBarHeight + 'px',
    }"
  >
    <view class="header">
      <image :src="user.avatar" mode="widthFix" />
      <view @click="editAvatar">
        <image src="../static/pen-yellow.png" mode="widthFix" />
      </view>
    </view>
    <view class="body">
      <view>
        <view @click="toEditPage('Name')">
          <image src="../static/user-yellow.png" mode="widthFix" />
          <text>Name</text>
          <image src="../static/back-grey.png" mode="widthFix" />
        </view>
        <view @click="toEditPage('Email')">
          <image src="../static/email-yellow.png" mode="widthFix" />
          <text>Email</text>
          <image src="../static/back-grey.png" mode="widthFix" />
        </view>
        <view @click="toEditPage('Password')">
          <image src="../static/password-yellow.png" mode="widthFix" />
          <text>Password</text>
          <image src="../static/back-grey.png" mode="widthFix" />
        </view>
      </view>
      <view @click="toSignInPage">Log out</view>
      <view>
        <text>Have questions? Please contact us through email: </text>
        <text>shelingxingqiu@163.com</text>
      </view>
    </view>
  </view>
</template>

<style scoped>
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: url("../static/app-bg6.png") no-repeat top/contain;
  height: 100%;
  position: relative;
}
.header {
  position: relative;
}
.header > image {
  width: 160rpx;
  height: 160rpx;
  border-radius: 50%;
  border: 4rpx solid #fff;
  box-sizing: border-box;
}
.header > view {
  position: absolute;
  right: 0;
  bottom: 0;
}
.header > view > image {
  width: 60rpx;
  height: 60rpx;
}
.body {
  padding: 25rpx;
  width: calc(100% - 50rpx);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.body > view:first-child {
  background-color: #fff;
  border-radius: 25px;
  padding: 0 20px;
  width: calc(100% - 80rpx);
}
.body > view:first-child > view {
  display: flex;
  align-items: center;
  padding: 20px 0;
}
.body > view:first-child > view:not(:last-child) {
  border-bottom: 1rpx solid #e3e3e3;
}
.body > view:first-child > view > image:first-child {
  width: 40rpx;
  height: 40rpx;
}
.body > view:first-child > view > text {
  flex: 1;
  font-size: 26rpx;
  color: #333333;
  text-align: left;
  padding-left: 20rpx;
}
.body > view:first-child > view > image:last-child {
  width: 28rpx;
  height: 28rpx;
}
.body > view:nth-child(2) {
  margin-top: 24rpx;
  background: #fff;
  border-radius: 24rpx;
  font-size: 26rpx;
  color: #287fff;
  text-align: center;
  width: 100%;
  height: 100rpx;
  line-height: 100rpx;
}
.body > view:nth-child(3) {
  margin-top: auto;
  padding-bottom: 25rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 24rpx;
  color: #666666;
  position: absolute;
  bottom: 120rpx;
}
.body > view:nth-child(3) > text:last-child {
  color: #287fff;
}
</style>
