import type { Ref } from 'vue'

const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms))

export async function ChangeTitle(refvar: Ref, old_string: string, new_string: string) {
  const old_array = old_string.split(' ')
  const new_array = new_string.split(' ')

  for (let i = old_array.length; i >= 0; i -= 1) {
    refvar.value = old_array.slice(0, i).join(' ')
    await sleep(100)
  }

  for (let i = 0; i < new_array.length; i++) {
    refvar.value = new_array.slice(0, i + 1).join(' ')
    await sleep(100)
  }
}
