import { defineStore } from "pinia"; export const usePoliciesStore = defineStore( "policies", () => { // Schema version for persistence const schemaVersion = "1.0"; // Core policies const equalHourlyWage = ref(0); const payrollOncostPct = ref(25); const savingsTargetMonths = ref(3); const minCashCushionAmount = ref(3000); // Deferred pay limits const deferredCapHoursPerQtr = ref(240); const deferredSunsetMonths = ref(12); // Surplus distribution order const surplusOrder = ref([ "Deferred", "Savings", "Hardship", "Training", "Patronage", "Retained", ]); // Payment priority order const paymentPriority = ref(["Payroll", "Taxes", "CriticalOps", "Vendors"]); // Volunteer scope - allowed flows const volunteerScope = ref({ allowedFlows: ["Care", "SharedLearning"], }); // Validation computed const isValid = computed(() => { return ( equalHourlyWage.value > 0 && payrollOncostPct.value >= 0 && payrollOncostPct.value <= 100 && savingsTargetMonths.value >= 0 && minCashCushionAmount.value >= 0 && deferredCapHoursPerQtr.value >= 0 && deferredSunsetMonths.value >= 0 ); }); // Wizard-required actions function setEqualWage(amount) { if (amount > 0) { equalHourlyWage.value = amount; } } function setOncostPct(pct) { if (pct >= 0 && pct <= 100) { payrollOncostPct.value = pct; } } function setSavingsTargetMonths(months) { if (months >= 0) { savingsTargetMonths.value = months; } } function setMinCashCushion(amount) { if (amount >= 0) { minCashCushionAmount.value = amount; } } function setDeferredCap(hours) { if (hours >= 0) { deferredCapHoursPerQtr.value = hours; } } function setDeferredSunset(months) { if (months >= 0) { deferredSunsetMonths.value = months; } } function setVolunteerScope(allowedFlows) { volunteerScope.value = { allowedFlows: [...allowedFlows] }; } function setSurplusOrder(order) { surplusOrder.value = [...order]; } function setPaymentPriority(priority) { paymentPriority.value = [...priority]; } // Legacy actions function updatePolicy(key, value) { if (key === "equalHourlyWage") setEqualWage(value); else if (key === "payrollOncostPct") setOncostPct(value); else if (key === "savingsTargetMonths") setSavingsTargetMonths(value); else if (key === "minCashCushionAmount") setMinCashCushion(value); else if (key === "deferredCapHoursPerQtr") setDeferredCap(value); else if (key === "deferredSunsetMonths") setDeferredSunset(value); } function updateSurplusOrder(newOrder) { setSurplusOrder(newOrder); } function updatePaymentPriority(newOrder) { setPaymentPriority(newOrder); } // Reset function function resetPolicies() { equalHourlyWage.value = 0; payrollOncostPct.value = 25; savingsTargetMonths.value = 3; minCashCushionAmount.value = 3000; deferredCapHoursPerQtr.value = 240; deferredSunsetMonths.value = 12; surplusOrder.value = [ "Deferred", "Savings", "Hardship", "Training", "Patronage", "Retained", ]; paymentPriority.value = ["Payroll", "Taxes", "CriticalOps", "Vendors"]; volunteerScope.value = { allowedFlows: ["Care", "SharedLearning"] }; } return { equalHourlyWage, payrollOncostPct, savingsTargetMonths, minCashCushionAmount, deferredCapHoursPerQtr, deferredSunsetMonths, surplusOrder, paymentPriority, volunteerScope, isValid, schemaVersion, // Wizard actions setEqualWage, setOncostPct, setSavingsTargetMonths, setMinCashCushion, setDeferredCap, setDeferredSunset, setVolunteerScope, setSurplusOrder, setPaymentPriority, resetPolicies, // Legacy actions updatePolicy, updateSurplusOrder, updatePaymentPriority, }; }, { persist: { key: "urgent-tools-policies", paths: [ "equalHourlyWage", "payrollOncostPct", "savingsTargetMonths", "minCashCushionAmount", "deferredCapHoursPerQtr", "deferredSunsetMonths", "surplusOrder", "paymentPriority", "volunteerScope", ], }, } );