<template>
  <div class="custom-chose-model-dialog">
    <t-dialog
      class="chose-model-dialog"
      v-model:visible="visible"
      placement="center"
      :cancelBtn="null"
      :confirmBtn="null"
    >
      <template #body>
        <div class="model-dialog-box">
          <div ref="ScrollELement" class="search-area-box narrow-scrollbar">
            <div class="search-result-image" v-if="list.length">
              <template v-for="(item, index) in list" :key="index">
                <ImageViewer :img="item"></ImageViewer>
              </template>
              <template v-for="(item, index) in list" :key="item">
                <i v-if="index !== list.length - 1"></i>
              </template>
            </div>
          </div>
        </div>
      </template>
    </t-dialog>
  </div>
</template>

<script lang="ts" setup>
import { Dialog as TDialog } from 'tdesign-vue-next';
import { reactive, ref, watch } from 'vue';
import ImageViewer from './ImageViewer.vue';
const props = withDefaults(
  defineProps<{
    modelValue: boolean;
    list: string[];
  }>(),
  {}
);
const emit = defineEmits(['update:modelValue', 'SubmitImage']);
const ScrollELement = ref<HTMLElement>();
const visible = ref(props.modelValue);
const SearchList = reactive({
  index: null,
});
const ChoseImage = (item: any, index: number) => {
  SearchList.index = index;
};
watch(
  () => props.modelValue,
  (v) => {
    visible.value = v;
  }
);

watch(
  () => visible.value,
  (v) => {
    emit('update:modelValue', v);
  }
);
</script>

<style lang="less">
@import '@/style/variables.less';
.custom-chose-model-dialog {
  width: 48%;
  .open-dialog-btn {
    width: 100% !important;
  }
  .chose-model-dialog {
    .t-dialog {
      background: #2d2d2d;
      border: none;
      width: 600px;
      .t-dialog__header-content {
        color: white;
      }
      .t-dialog__close {
        color: #ddd;
        &:hover {
          color: #2d2d2d;
        }
      }
    }
    .model-dialog-box {
      margin-top: 6px;
      .select-model-input {
        width: 100% !important;
        height: auto !important;
        color: white;
        .right-input-icon {
          padding-right: 12px;
        }
      }
      .search-area-box {
        width: 100%;
        height: 389px;
        background: #181818;
        border: @main-border;
        border-radius: 8px;
        margin-top: 6px;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow-y: auto;
        .search-result-image {
          width: 100%;
          height: 100%;
          padding: 12px;
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;
          row-gap: 12px;
          i {
            width: 150px;
          }
          img {
            width: 150px;
            height: 150px;
            border-radius: 8px;
            cursor: pointer;
            border: 1.5px solid transparent;
            transition: border 0.2s;
          }
          .image-active {
            border: 1.5px solid #00f9f9;
            transition: border 0.2s;
          }
        }
      }
    }
  }
}
</style>
