<template>
  <Teleport to="body">
    <div class="lofty-drawer" :class="{'lofty-show-drawer': show}">
      <p class="lofty-drawer-title">
        <span>{{ title }}</span>
        <i class="lofty_iconfont lofty-icon-close font-16" @click="closeDrawer"></i>
      </p>
      <slot></slot>
    </div>
  </Teleport>
</template>

<script setup>
const props = defineProps({
  title: {
    type: String,
    default: 'title'
  },
})
const show = defineModel({default: false})
show.value = !!props.modelValue
watch(show, (value) => {
  if (value) {
    document.body.classList.add('lofty-overflow-hidden')
  } else {
    document.body.classList.remove('lofty-overflow-hidden')
  }
})
function closeDrawer() {
  show.value = false
  document.body.classList.remove('lofty-overflow-hidden')
}
</script>

<style lang="scss">
.lofty-drawer {
  position: fixed;
  width: 100%;
  left: 0;
  bottom: 0;
  transform: translateY(100%);
  transition: all 0.5s ease;
  z-index: 1090;
  background-color: #fff;
  overflow: hidden;
  height: calc(100%);
  .lofty-drawer-title {
    font-size: 14px;
    font-weight: 700;
    line-height: 20px;
    color: #111111;
    border-bottom: 1px solid rgba(17, 17, 17, 0.1);
    padding: 20px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
.lofty-show-drawer {
  transform: translateY(0) translateZ(100px) !important;
  box-shadow: 0px -10px 10px 0px rgba(0, 0, 0, 0.1);
  z-index: 100000;
}
</style>