// import { ref, type Ref } from "vue";
// import { normalizeObject } from "src/utils/normalize-object";
// import { normExpenseType } from "../utils/expense.util";
// import type { Expense, PayPeriodExpenses } from "src/modules/timesheets/models/expense.models";
// import { useExpensesStore } from "src/stores/expense-store";
// import { unwrapAndClone } from "src/utils/unwrap-and-clone";
// import { expense_validation_schema } from "src/modules/timesheets/models/expense.validation";

// const expenses_store = useExpensesStore();

// export const useExpenseItems = () => {
//     let expenses = unwrapAndClone(expenses_store.pay_period_expenses.expenses.map(normalizeExpense));

//     const normalizePayload = (expense: Expense): Expense => {
//     const exp = normalizeObject(expense, expense_validation_schema);
//     const out: Expense = {
//         date: exp.date,
//         type: exp.type as ExpenseType,
//         comment: exp.comment || '',
//     };
//     if(typeof exp.amount  === 'number') out.amount  = exp.amount;
//     if(typeof exp.mileage === 'number') out.mileage = exp.mileage;
//     return out;
// }

//     const addFromDraft = () => {
//         const candidate: Expense = normalizeExpense({
//             date: draft.date,
//             type: normExpenseType(draft.type),
//             ...(typeof draft.amount  === 'number' ? { amount: draft.amount   }: {}),
//             ...(typeof draft.mileage === 'number' ? { mileage: draft.mileage }: {}),
//             comment: String(draft.comment ?? '').trim(),
//         } as Expense);

//         validateExpenseUI(candidate, 'expense_draft');
//         expenses = [ ...expenses, candidate];
//     };

//     const removeAt = (index: number) => {
//         if(index < 0 || index >= expenses.length) return;
//         expenses = expenses.filter((_,i)=> i !== index);
//     };

//     const validateAll = () => {
//         for (const expense of expenses) {
//             validateExpenseUI(expense, 'expense_item');
//         }
//     };

//     const payload = () => expenses.map(normalizeExpense);

//     return {
//         expenses,
//         addFromDraft,
//         removeAt,
//         validateAll,
//         payload,
//     };
// };
