<template>
  <el-popover
    v-model="visible"
    popper-class="app-popover"
    :placement="placement"
    width="1268"
    trigger="manual"
    @after-enter="loadAppData"
  >
    <app-selector
      ref="appSelector"
      :open-type="openType"
      :show-close="true"
      @after-select="afterSelect"
      @close="visible = false"
    />
    <span slot="reference" @click="visible = true">
      <slot name="default"></slot>
    </span>
  </el-popover>
</template>

<script>
  import AppSelector from './AppSelector.vue'
  export default {
    name: 'Index',
    components: { AppSelector },
    props: {
      placement: {
        type: String,
        default: 'bottom-start',
      },
      openType: {
        type: String,
        default: 'window',
      },
    },
    data() {
      return {
        visible: false,
      }
    },
    methods: {
      loadAppData() {
        this.$refs.appSelector.loadAppData()
      },
      afterSelect() {
        this.visible = false
      },
    },
  }
</script>

<style lang="scss">
  .app-popover {
    padding: 0 !important;
  }
</style>
