import { KeepAlive, Transition } from 'vue'
import { RouterView } from 'vue-router'
import { useKeepAliveStore } from '@/store/keepAlive'

export default function (name: string) {
  return defineComponent({
    name,
    setup() {
      const { cachedViews } = storeToRefs(useKeepAliveStore())
      return () => (
        <div key={name} style="width: 100%; height: 100%">
          <RouterView>
            {({ Component }) => (
              <Transition name="fade-transform" mode="out-in">
                <KeepAlive include={cachedViews.value}>
                  <Component />
                </KeepAlive>
              </Transition>
            )}
          </RouterView>
        </div>
      )
    },
  })
}
