"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEventFunWithoutRecord = exports.addRecordForFunc = exports.getTableVOnSelectRowsFuncName = exports.getTableRowSelectionType = exports.isInputParameters = void 0;
// import get from 'lodash/get';
const lodash = require('lodash');
function isInputParameters(vName, inputList = []) {
    if (Array.isArray(inputList)) {
        for (let i = 0; i < inputList.length; i += 1) {
            if (inputList[i].name === vName) {
                return true;
            }
        }
    }
    return false;
}
exports.isInputParameters = isInputParameters;
// 获取属性列表里的 select-type 属性，并且返回类型，类型共有两种，radio 和 checkbox，默认checkbox
// https://ant.design/components/table-cn/#rowSelection
function getTableRowSelectionType(attrList) {
    const target = attrList.find(a => a.name.name === 'selectType');
    if (target) {
        return lodash.get(target, 'value.value', 'checkbox');
    }
    return 'checkbox';
}
exports.getTableRowSelectionType = getTableRowSelectionType;
// 获取 client action 属性对应的 action name 'v-on:selectRows'
function getTableVOnSelectRowsFuncName(attrList, attrName) {
    const target = attrList.find(a => a.name.name === attrName);
    if (target) {
        const clientActionName = lodash.get(target, 'value.value', '');
        if (clientActionName.indexOf('client.') !== -1) {
            const actionName = clientActionName.split('client.')[1];
            return `onChange: this.${actionName}`;
        }
        return '';
    }
    return '';
}
exports.getTableVOnSelectRowsFuncName = getTableVOnSelectRowsFuncName;
// 为表格内事件添加record入参
function addRecordForFunc(funcName) {
    if (funcName.includes('(') && funcName.includes(')')) {
        // 提取括号内的内容
        const match = funcName.match(/\((.+?)\)/gi);
        if (match && match.length) {
            const paramStr = match[0];
            if (paramStr.includes('record')) {
                return funcName;
            }
            let newParamStr = paramStr.replace('(', '').replace(')', '');
            const funcStr = funcName.split("(")[0];
            if (newParamStr) {
                newParamStr += `,record`;
            }
            else {
                newParamStr = 'record';
            }
            return `${funcStr}(${newParamStr})`;
        }
    }
    return `${funcName}(record)`;
}
exports.addRecordForFunc = addRecordForFunc;
// 获取组件事件函数（剔除record参数）
function getEventFunWithoutRecord(funcName) {
    let ifInTable = false;
    if (funcName.includes('(record)')) {
        ifInTable = true;
        funcName = funcName.split('(')[0];
    }
    return {
        ifInTable,
        funcName
    };
}
exports.getEventFunWithoutRecord = getEventFunWithoutRecord;
