import React, { useState } from 'react';
import { ChevronDownIcon, PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline';
import { formatRial } from '../../lib/utils';
import type { InventoryPackage } from '../../hooks/useInventory';
interface Props {
packages: InventoryPackage[];
onEdit: (pkg: InventoryPackage) => void;
onDelete: (pkg: InventoryPackage) => void;
}
/** Package cards with an expandable component list — mirrors tauri AddStockView. */
export default function PackagesView({ packages, onEdit, onDelete }: Props) {
return (
{packages.map((pkg) => (
))}
);
}
function PackageCard({ pkg, onEdit, onDelete }: { pkg: InventoryPackage } & Pick) {
const [expanded, setExpanded] = useState(false);
const divider = ;
return (
{/* Header */}
{pkg.title}
{pkg.available ? 'موجودی کافی' : 'موجودی ناکافی'}
{divider}
{/* Accordion */}
{expanded && (
{pkg.items.length === 0 ? (
این پکیج کالایی ندارد.
) : (
pkg.items.map((it) => (
{it.name}
{it.amount} {it.unit}
))
)}
)}
{divider}
{/* Footer */}
قیمت پکیج: {formatRial(pkg.total)}
);
}