'use strict';

/**
 * Port dari packages/designer/src/migrators/label_generator.rs.
 * Generator label field dari snake_case ke human-readable format.
 */

const { snakeToTitle } = require('./naming');

const LABEL_OVERRIDES = {
    is_active: 'Status',
    uom: 'UOM',
    sku: 'SKU',
    email: 'Email',
    phone: 'Phone',
    url: 'URL',
    ip: 'IP',
    id: 'ID'
};

function generateLabel(fieldName, isForeignKey) {
    const name = String(fieldName || '');

    if (Object.prototype.hasOwnProperty.call(LABEL_OVERRIDES, name)) {
        return LABEL_OVERRIDES[name];
    }

    if (isForeignKey && name.endsWith('_id')) {
        const stripped = name.slice(0, -3);
        if (stripped.length > 0) {
            return snakeToTitle(stripped);
        }
    }

    return snakeToTitle(name);
}

module.exports = { generateLabel };
