import { ref, computed } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; import { useSettingsStore } from '@/stores/setting.ts'; import { useAccountsStore } from '@/stores/account.ts'; import { Account, type CategorizedAccountWithDisplayBalance } from '@/models/account.ts'; export function useMoveAllTransactionsPageBase() { const { tt, getCategorizedAccountsWithDisplayBalance } = useI18n(); const settingsStore = useSettingsStore(); const accountsStore = useAccountsStore(); const moving = ref(false); const fromAccount = ref(undefined); const toAccountId = ref(''); const toAccountName = ref(''); const showAccountBalance = computed(() => settingsStore.appSettings.showAccountBalance); const allAccounts = computed(() => accountsStore.allPlainAccounts); const allVisibleAccounts = computed(() => accountsStore.allVisiblePlainAccounts); const allVisibleCategorizedAccounts = computed(() => getCategorizedAccountsWithDisplayBalance(allVisibleAccounts.value, showAccountBalance.value)); const displayToAccountName = computed(() => { if (!toAccountId.value) { return tt('Target Account'); } return Account.findAccountNameById(allAccounts.value, toAccountId.value, tt('Target Account')) || tt('Target Account'); }); const isToAccountNameValid = computed(() => { if (!toAccountId.value || !toAccountName.value) { return false; } const expectedAccountName = Account.findAccountNameById(allAccounts.value, toAccountId.value); if (!expectedAccountName) { return false; } return expectedAccountName === toAccountName.value; }); return { // states moving, fromAccount, toAccountId, toAccountName, // computed states allAccounts, allVisibleAccounts, allVisibleCategorizedAccounts, displayToAccountName, isToAccountNameValid }; }