import type { ProfileFieldsConfig } from './types';

/**
 * 更新字段配置
 * @param fieldConfig - 当前字段配置
 * @param responseData - 接口返回的配置数据
 */
export function updateFieldConfig(fieldConfig: any, responseData: ProfileFieldsConfig) {
  // 基础字段更新'three_period',, 'political_status'
  const basicFields = [
    'name', 'gender', 'phone', 'id_card', 'ethnicity', 
    'height', 'weight', 'current_address', 'household_location', 
    'marital_status', 'expected_salary'
  ];
  
  basicFields.forEach(field => {
    if (responseData[field]) {
      fieldConfig[field].visible = responseData[field].visible;
      fieldConfig[field].required = responseData[field].required;
    }
  });

  // 嵌套字段更新
  const nestedFields = ['family_member', 'education', 'work_experience'];
  
  nestedFields.forEach(field => {
    if (responseData[field]) {
      // 更新主字段
      fieldConfig[field].visible = responseData[field].visible;
      
      // 更新子字段
      Object.keys(responseData[field].fields).forEach(subField => {
        if (fieldConfig[field].fields[subField]) {
          fieldConfig[field].fields[subField].visible = responseData[field].fields[subField].visible;
          fieldConfig[field].fields[subField].required = responseData[field].fields[subField].required;
        }
      });
    }
  });
} 