<template>
  <kk-button text @click="dialogVisible = true">
    click to open the Dialog
  </kk-button>

  <div>
    <p>Close dialog and the input will be focused</p>
    <el-input ref="inputRef" placeholder="Please input" />
  </div>

  <kk-dialog
    v-model="dialogVisible"
    destroy-on-close
    title="Tips"
    width="30%"
    @close-auto-focus="handleCloseAutoFocus"
  >
    <span>This is a message</span>
    <el-divider />
    <el-input placeholder="Initially focused" />
    <template #footer>
      <span class="dialog-footer">
        <kk-button @click="dialogVisible = false">Cancel</kk-button>
        <kk-button type="primary" @click="dialogVisible = false">
          Confirm
        </kk-button>
      </span>
    </template>
  </kk-dialog>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { KkButton, KkDialog } from 'kankan-components'
import { ElInput } from 'element-plus'

const dialogVisible = ref(false)
const inputRef = ref<InstanceType<typeof ElInput>>()

const handleCloseAutoFocus = () => {
  inputRef.value?.focus()
}
</script>
<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
