const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const Ops = GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators;
const headers = ['SKU', '품목명', '현재고', '안전재고', '재고상태'];
const colWidths = [80, 140, 90, 90, 80];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#37474F').foreColor('#ffffff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, colWidths[c]);
});
sheet.setRowHeight(0, 36);
const data = [
['SKU-001', '리튬배터리팩', 320, 100],
['SKU-002', '전원어댑터', 45, 80],
['SKU-003', '방열패드', 88, 50],
['SKU-004', 'USB-C 케이블', 560, 200],
['SKU-005', '보호필름', 12, 100],
['SKU-006', '충전거치대', 210, 80],
['SKU-007', '전선결속대', 34, 30],
['SKU-008', '냉각팬 모듈', 76, 50],
];
data.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 1, c, val));
const stock = row[2], safety = row[3];
const status = stock < safety ? '⚠ 부족' : stock < safety * 1.5 ? '△ 주의' : '✓ 정상';
sheet.setValue(r + 1, 4, status);
});
const rowCount = data.length;
const stockRange = [new GC.Spread.Sheets.Range(1, 2, rowCount, 1)];
const cfs = sheet.conditionalFormats;
// 정상: 현재고 > 150
const greenStyle = new GC.Spread.Sheets.Style();
greenStyle.backColor = '#E8F5E9';
greenStyle.foreColor = '#1B5E20';
cfs.addCellValueRule(Ops.greaterThan, 150, undefined, greenStyle, stockRange);
// 주의: 현재고 50~150
const yellowStyle = new GC.Spread.Sheets.Style();
yellowStyle.backColor = '#FFF8E1';
yellowStyle.foreColor = '#E65100';
cfs.addCellValueRule(Ops.between, 50, 150, yellowStyle, stockRange);
// 부족: 현재고 < 50 (마지막 추가 = 최우선 적용)
const redStyle = new GC.Spread.Sheets.Style();
redStyle.backColor = '#FFEBEE';
redStyle.foreColor = '#C62828';
cfs.addCellValueRule(Ops.lessThan, 50, undefined, redStyle, stockRange);