/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { Verb } from '@datashaper/schema';
import { isInputColumnListStep, isInputColumnRecordStep, isInputColumnStep, isInputKeyValueStep, isInputTableListStep, isOutputColumnStep } from '@datashaper/workflow';
import { format } from 'd3-format';
/**
 * Create reasonable short detail text for a step.
 * For most this will be the column or columns operated on,
 * but we have a few special cases too.
 * @param step
 * @returns
 */ export function deriveDetails(step) {
    const { verb , args  } = step;
    // handle special case verbs first
    switch(verb){
        case Verb.Derive:
            return `from ${args.column1} & ${args.column2}`;
        case Verb.Orderby:
            return args.orders.map((o)=>o.column).join(',');
        case Verb.Sample:
            return sample(step);
    }
    if (isInputColumnStep(step)) {
        return args.column;
    } else if (isInputColumnListStep(step)) {
        return args.columns.join(',');
    } else if (isInputColumnRecordStep(step)) {
        return Object.keys(args.columns).join(',');
    } else if (isInputKeyValueStep(step)) {
        return `${args.key} & ${args.value}`;
    } else if (isOutputColumnStep(step)) {
        return args.to;
    } else if (isInputTableListStep(step)) {
        const others = step.input['other'] ? step.input['other'].node : step.input.others?.map((o)=>o.node).join(',');
        return 'with ' + others;
    }
}
const whole = format('d');
function sample(step) {
    const args = step.args;
    return args.proportion ? `${whole(args.proportion * 100)}% of rows` : `${args.size} rows`;
}
