<template>
  <div class="house-layout">
    <div class="iframe-layout">
      <iframe :src="fuseUrl" ref="iframeRef" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { CaseTagging, getCaseTaggings } from "@/store/caseTagging";
import {
  getFuseImage,
  getQuery,
  FuseImageType,
  fuseImageJoinHot,
  fuseIframeHandler,
} from "@/view/case/help";
import { computed, nextTick, onMounted, ref, watchEffect } from "vue";
import { QuiskExpose } from "@/helper/mount";
import saveAs from "@/util/file-serve";

export type PhotoFuseImage = { blob: Blob | null };
const props = defineProps<{ caseId: number }>();

const fuseUrl = computed(() => getQuery(props.caseId, true, true));
const iframeRef = ref<HTMLIFrameElement>();

watchEffect((onClanup) => {
  if (iframeRef.value) {
    onClanup(fuseIframeHandler(iframeRef.value));
  }
});

defineExpose<QuiskExpose>({
  async submit() {
    const fuseImage = await getFuseImage(iframeRef.value!, 1500, 1500);
    if (fuseImage.blob) {
      await saveAs(fuseImage.blob, `场景拍照.png`);
    }
  },
});
</script>

<style lang="scss" scoped>
.house-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - 200px);
}

.iframe-layout {
  height: 100%;
  flex: 1;
  iframe {
    border: none;
    width: 100%;
    height: 100%;
  }
}

.content-layout {
  flex: none;
  width: 360px;
  display: flex;
  flex-direction: column;
  margin-left: 40px;
  height: 100%;
  justify-content: space-between;

  h4 {
    font-size: 14px;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.85);
    line-height: 22px;
    margin-bottom: 15px;
    flex: none;

    span {
      float: right;
    }
  }

  > .house-tags {
    flex: none;
    display: flex;
    flex-direction: column;

    > .tagging-transfer {
      flex: 1;
      overflow: hidden;
    }
  }
}
.house-image {
  border: 1px solid #d9d9d9;
  padding-top: 68%;
  position: relative;

  > div {
    position: absolute;
    inset: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}
</style>

<style lang="scss">
.tagging-transfer {
  .el-transfer {
    display: flex;
    --el-transfer-panel-body-height: 160px;
  }
  .el-transfer__buttons {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    button {
      padding: 0;
      width: 24px;
      height: 24px;
      display: block;
      margin: 5px 0;
    }
  }
  .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
    font-size: 14px;
  }
}
.icon {
  cursor: pointer;
}

.value-option {
  display: flex;
  align-items: center;

  span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  i {
    flex: 0 0 auto;
  }
}
</style>

<style>
.value-option.dragging {
  opacity: 0.5;
}
</style>
