/* Модуль «Материалы» — учёт материалов проекта Показывает: название, категория, количество, единицы, поставщик, стоимость, статус */ window.RD = window.RD || { core: {}, modules: {} }; window.RD.modules.Materials = function Materials() { var store = RD.core.useStore(); var h = React.createElement; var fmt = RD.core; // FIX: Data is in store.raw directly, not in store.raw.data var materials = store.raw.materials || []; return h('div', { style: { flex: 1, overflow: 'auto', padding: 20, display: 'flex', flexDirection: 'column', gap: 16 } }, // Header h('div', null, h('h2', { style: { fontSize: 20, fontWeight: 700, color: 'var(--rd-text)', marginBottom: 6 } }, 'Материалы'), h('p', { style: { fontSize: 13, color: 'var(--rd-text-muted)' } }, materials.length + ' материалов' ) ), // Placeholder (если пусто) materials.length === 0 ? h('div', { style: { flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: 40, color: 'var(--rd-text-muted)' } }, h('div', { style: { fontSize: 48, marginBottom: 16, opacity: 0.3 } }, '📦'), h('div', { style: { fontSize: 18, fontWeight: 600, marginBottom: 8, color: 'var(--rd-text)' } }, 'Материалы не загружены'), h('div', { style: { fontSize: 13, marginBottom: 20, textAlign: 'center', maxWidth: 480 } }, 'Для проекта ещё не добавлены материалы. Импортируйте из сметы или добавьте вручную.' ), h('div', { style: { display: 'flex', gap: 12 } }, h('button', { onClick: function () { store.showToast('Импорт материалов из сметы — в разработке', 'info'); }, style: { padding: '10px 18px', border: '1px solid var(--rd-border)', borderRadius: 8, background: 'var(--rd-surface-2)', color: 'var(--rd-text)', fontSize: 13, fontWeight: 600, cursor: 'pointer' } }, '📋 Импорт из сметы'), h('button', { onClick: function () { store.showToast('Добавление материала вручную — в разработке', 'info'); }, style: { padding: '10px 18px', border: 'none', borderRadius: 8, background: 'var(--rd-accent)', color: '#fff', fontSize: 13, fontWeight: 600, cursor: 'pointer' } }, '+ Добавить вручную') ), h('div', { style: { marginTop: 30, fontSize: 12, color: 'var(--rd-text-muted)', textAlign: 'center', maxWidth: 600, lineHeight: 1.6 } }, h('div', { style: { fontWeight: 600, marginBottom: 8 } }, 'Что хранится в материалах:'), h('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } }, h('li', null, '• Кольца ЖБИ (например: Кольца Ø22 б/у — выкуп 2,369,000 ₽)'), h('li', null, '• Щебень, песок, цемент, арматура'), h('li', null, '• Расходники: доски, крепёж, геотекстиль'), h('li', null, '• Связь с поставщиками и сметными позициями') ) ) ) : h('div', { style: { background: 'var(--rd-surface)', border: '1px solid var(--rd-border)', borderRadius: 12, overflow: 'hidden' } }, h('table', { style: { width: '100%', borderCollapse: 'collapse' } }, h('thead', null, h('tr', { style: { background: 'var(--rd-surface-2)', borderBottom: '1px solid var(--rd-border)' } }, ['Название', 'Категория', 'Количество', 'Ед.', 'Поставщик', 'Стоимость', 'Статус'].map(function (col) { return h('th', { key: col, style: { padding: '12px 14px', textAlign: 'left', fontSize: 11, fontWeight: 700, color: 'var(--rd-text-muted)', textTransform: 'uppercase' } }, col); }) ) ), h('tbody', null, materials.map(function (m, i) { return h('tr', { key: m.id, style: { borderBottom: i < materials.length - 1 ? '1px solid var(--rd-border)' : 'none', transition: 'background 0.2s' }, onMouseEnter: function (e) { e.currentTarget.style.background = 'var(--rd-surface-2)'; }, onMouseLeave: function (e) { e.currentTarget.style.background = 'transparent'; } }, h('td', { style: { padding: '12px 14px', fontSize: 12, fontWeight: 600, color: 'var(--rd-text)' } }, m.name), h('td', { style: { padding: '12px 14px', fontSize: 12, color: 'var(--rd-text-muted)' } }, m.category), h('td', { style: { padding: '12px 14px', fontSize: 12, color: 'var(--rd-text)' } }, m.quantity), h('td', { style: { padding: '12px 14px', fontSize: 12, color: 'var(--rd-text-muted)' } }, m.unit), h('td', { style: { padding: '12px 14px', fontSize: 12, color: 'var(--rd-text)' } }, m.supplier || '—'), h('td', { style: { padding: '12px 14px', fontSize: 12, color: 'var(--rd-accent)', fontWeight: 600 } }, fmt.money(m.cost || 0)), h('td', { style: { padding: '12px 14px' } }, h('span', { style: { fontSize: 10, fontWeight: 700, background: m.status === 'ordered' ? 'var(--rd-info)' : m.status === 'delivered' ? 'var(--rd-good)' : 'var(--rd-surface-2)', color: m.status === 'ordered' || m.status === 'delivered' ? '#fff' : 'var(--rd-text-muted)', padding: '4px 8px', borderRadius: 6, textTransform: 'uppercase' } }, m.status === 'ordered' ? 'Заказано' : m.status === 'delivered' ? 'Доставлено' : 'Планируется') ) ); }) ) ) ) ); };