package com.cf.imes.framework.excel.core.util;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.cf.imes.framework.common.constants.ResourceBundleConstants;
import com.cf.imes.framework.common.util.i18n.core.util.ResourceBundleUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.List;

/**
 * 表头国际化处理器
 *
 * @author Gqr
 * @since 2025/11/21 11:05
 */
public class I18nHeadWriteHandler implements CellWriteHandler {
    @Override
    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        if (Boolean.TRUE.equals(isHead)) {
            String key = head.getHeadNameList().get(0);
            cell.setCellValue(ResourceBundleUtils.getMessage(ResourceBundleConstants.MESSAGE_ENUM_PATH, key, key, LocaleContextHolder.getLocale(), null));
        }
    }
}
