import { label as external_label_js_label } from "./label.js";
import { createFormatterByDimension } from "../../../../utils/index.js";
import { Separator } from "../../../../../dataReshape/index.js";
const labelSunburst = (spec, context)=>{
    const { advancedVSeed } = context;
    const { chartType, encoding, dimensions = [] } = advancedVSeed;
    const baseConfig = advancedVSeed.config[chartType];
    const { label } = baseConfig;
    const result = external_label_js_label(spec, context);
    if (label?.enable) {
        const labelSpec = result.label;
        const formatHierarchyName = (name)=>{
            const dimIds = encoding.hierarchy || [];
            if (!dimIds.length) return name;
            const dimFormatters = dimIds.map((id)=>{
                const dim = dimensions.find((item)=>item.id === id);
                return createFormatterByDimension(dim, advancedVSeed.locale);
            });
            const parts = String(name ?? '').split(Separator);
            const formatted = parts.map((part, index)=>{
                const formatter = dimFormatters[index] || ((v)=>v);
                return formatter(part);
            });
            return formatted.join(Separator);
        };
        result.label = {
            ...labelSpec,
            formatMethod: (_, datum)=>formatHierarchyName(String(datum?.name ?? '')),
            style: {
                ...labelSpec?.style,
                fontSize: label?.labelFontSize ?? 12,
                fillOpacity: (datum)=>{
                    if (encoding.hierarchy?.length === 1) return 1;
                    return datum.isLeaf ? 0.4 : 0.6;
                }
            }
        };
    }
    return result;
};
export { labelSunburst };

//# sourceMappingURL=labelSunburst.js.map