<script lang="ts" setup>
import type SetPassword from "@/components/set-password/set-password.vue";
import type PasswordInput from "@/components/password-input/password-input.vue";
import {useUserStore} from "@/store";


const emits = defineEmits<{
  success: [password: string];
}>();

const userStore = useUserStore();


const setPasswordRef = ref<InstanceType<typeof SetPassword> | null>(null);
const passwordInputRef = ref<InstanceType<typeof PasswordInput> | null>(null);


function showSetPassword() {
  setPasswordRef.value?.init();
}

function showPasswordInput() {
  if (!userStore.userInfo?.payPwd) {
    showSetPassword()
    return
  }
  passwordInputRef.value?.init?.();
}

function handleSuccess(password: string) {
  emits("success", password);
}


defineOptions({
  name: "PasswordContainer",
});

defineExpose({
  showSetPassword,
  showPasswordInput,
});
</script>

<template>
  <view class="">
    <set-password ref="setPasswordRef"/>
    <password-input ref="passwordInputRef" @success="handleSuccess"/>
  </view>

</template>

<style lang="scss" scoped>

</style>