'use strict';

/**
 * Port dari packages/designer/src/utils/naming.rs.
 * Konversi naming convention: snake_case -> kebab-case / camelCase / PascalCase / Title Case.
 */

function capitalize(s) {
    if (!s || s.length === 0) return '';
    return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
}

function snakeToKebab(name) {
    return String(name || '').replace(/_/g, '-');
}

function snakeToCamel(name) {
    const parts = String(name || '').split('_');
    if (parts.length === 0) return '';
    const first = parts.shift();
    return first + parts.map(capitalize).join('');
}

function snakeToPascal(name) {
    return String(name || '').split('_').map(capitalize).join('');
}

function snakeToTitle(name) {
    return String(name || '').split('_').map(capitalize).join(' ');
}

function kebabToTitle(name) {
    return String(name || '')
        .split(/[-_]+/)
        .filter(Boolean)
        .map(capitalize)
        .join(' ');
}

function toClassName(appCode) {
    return String(appCode || '').replace(/_/g, '-').split('-').map(capitalize).join('');
}

module.exports = {
    capitalize,
    snakeToKebab,
    snakeToCamel,
    snakeToPascal,
    snakeToTitle,
    kebabToTitle,
    toClassName
};
