const { useState, useEffect, useRef } = React;
const PAPER = "#EFE9DC";
const PAPER_CARD = "#F8F4EA";
const INK = "#24304A";
const INK_SOFT = "#63697A";
const CREDIT = "#2F5D4E";
const DEBIT = "#A13D2E";
const GOLD = "#B08D3F";
const LINE = "#D8CFBC";
const FALLBACK_CATEGORIES = ["עסק פרטי", "קמפ", 'בית חב"ד'];
const todayStr = () => new Date().toISOString().split("T")[0];
function formatILS(n) {
const num = Number(n) || 0;
return `${num.toLocaleString("he-IL", { maximumFractionDigits: 2 })} ₪`;
}
function formatDateDisplay(dateVal) {
if (!dateVal) return "";
const d = new Date(dateVal);
return d.toLocaleDateString("he-IL", { day: "2-digit", month: "2-digit", year: "numeric" });
}
function safeFileName(str) {
return (str || "תמונה").replace(/[^א-תa-zA-Z0-9 ]/g, "").trim() || "תמונה";
}
function downloadUrl(url, filename) {
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function resizeImageToBlob(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
const maxDim = 1200;
let width = img.width;
let height = img.height;
if (width > maxDim || height > maxDim) {
if (width > height) {
height = Math.round((height * maxDim) / width);
width = maxDim;
} else {
width = Math.round((width * maxDim) / height);
height = maxDim;
}
}
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
canvas.toBlob(
(blob) => {
if (blob) resolve(blob);
else reject(new Error("שגיאה בעיבוד תמונה"));
},
"image/jpeg",
0.8
);
};
img.onerror = () => reject(new Error("שגיאת טעינת תמונה"));
img.src = e.target.result;
};
reader.onerror = () => reject(new Error("שגיאת קריאת קובץ"));
reader.readAsDataURL(file);
});
}
function emptyForm() {
return {
date: todayStr(),
type: "expense",
category: "",
description: "",
source: "",
amount: "",
needsReimbursement: false,
hasWarranty: false,
warrantyMonths: "",
photoFile: null,
photoPreviewUrl: null,
hadExistingPhoto: false,
removeExistingPhoto: false,
};
}
function GlobalStyle() {
return (
);
}
function Icon({ children, size, style }) {
return (
);
}
const IconPlus = (p) => (
מעקב הכנסות והוצאות