<template>
  <view>
    <hs-collection />
    <view class="archive_header_card">
      <view class="archive_card_header">
        {{ useModel?.showData?.value?.house_relation?.asset_house?.full_name || '' }}
        <text @click="show = true">切换房屋</text>
      </view>
      <view class="archive_card_role">
        <view class="item"> 您的身份事：产权人 </view>
        <view class="item">
          房屋已绑定：{{ useModel?.showData?.value?.house_occupants_num }}人
        </view>
      </view>
    </view>

    <view class="archive_houses_content">
      <hs-empty v-if="!useModel?.listData?.value?.length" />
      <view
        class="archive_container"
        v-for="(k, index) in useModel?.listData?.value"
        :key="`item_${index}`"
      >
        <view class="archive_header_number">
          <view class="border_left"> </view>
          <view class="title"> {{ k?.label }} </view>
        </view>
        <hs-empty v-if="!k.list?.length" />
        <view class="archive_items" v-for="(i, index) in k.list" :key="index">
          <view class="archive_items_heander">
            <view class="avatar">
              <up-avatar text="U" fontSize="18" bgColor="#ffeade" color="#333" />
            </view>
            <view class="user_info">
              <view class="name"> {{ i?.name }} </view>
              <view class="tabs">
                <hs-enum-tag
                  v-if="i?.house_relation === 'Owner'"
                  :value="i?.house_relation"
                  :Enums="HouseOccupantsHouseRelationEnum"
                  type="primary"
                />
                <hs-enum-tag
                  v-if="i?.house_relation === 'NonOwner'"
                  :value="i?.residential_relation"
                  :Enums="HouseOccupantsResidentialRelationEnum"
                  type="orange"
                />
              </view>
            </view>
            <view
              class="remove"
              v-if="
                i?.house_relation === 'NonOwner' &&
                useModel?.showData?.value?.house_relation?.house_relation === 'Owner'
              "
              @click="method?.handleRemove(i)"
            >
              移除该住户
            </view>
          </view>
        </view>
      </view>
    </view>

    <MyCreateHousehold />

    <hs-popup-switch-house
      :show="show"
      pageSource="archive_houses"
      @close="show = false"
      @change="handleSelectedHouse"
    />
  </view>
</template>
<script setup lang="ts">
import { onHide, onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import useModel from './model'
import method from './method'
import { useWeAppAuthStore } from '@/common'
import { HouseOccupantsResidentialRelationEnum, HouseOccupantsHouseRelationEnum } from '@/gen/Enums'
import { ref } from 'vue'
import MyCreateHousehold from './components/CreateHousehold.vue'
const show = ref(false)
const auth = useWeAppAuthStore()

const handleSelectedHouse = (e: { asset_houses_id: string }) => {
  console.log(e, 'sss')
  useModel.formData.value.asset_houses_id = e?.asset_houses_id
  method?.handleSearch()
  show.value = false
}

onHide(() => {
  show.value = false
})

onLoad(() => {
  useModel.formData.value.asset_houses_id = auth?.data?.selected_house?.id || ''
  method?.handleSearch()
})

onShareAppMessage(() => {
  return {
    title: '邀请您加入我的房屋',
    path: '/pages/index/index',
    imageUrl:
      'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K5B5RY2TQQAJ1GT2RZSK426V.jpg'
  }
})
onShareTimeline(() => {
  return {
    title: '邀请您加入我的房屋',
    path: '/pages/index/index',
    imageUrl:
      'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K5B5RY2TQQAJ1GT2RZSK426V.jpg'
  }
})
</script>
<style lang="scss">
@import './style.scss';
</style>
