jQuery(function($) {
	
	//Declaramos los desplegables para que se plieguen y desplieguen
	initRupI18nPromise.then(function () {
		Ad74aUtils.hacerPlegable();
		
		$('#convivencia_layer').hide();
		if($('[name="informeSocial.sola02"]:checked').attr("id").split('_')[1] == 1) {
			 $('#convivencia_layer').fadeIn();		
			 loadConvivencia()
		}
	});
	
	const loadConvivencia = () => {
		
		try {
			$("#convivencia").DataTable().destroy();
		} catch (error) {}
		
		let tableColModels = [                    
			{ name: "idConviviente82", index: "idConviviente82", editable: false, hidden: true },
			{ name: "idInfSocial82", index: "idInfSocial82", editable: false, hidden: true },
			{ name: "nombreApellidos82", index: "nombreApellidos82", editable: true, hidden: false, orderable: false, },
			{ name: "parentesco82",	index: "parentesco82", editable: true, hidden: false, orderable: false,	},
			{ 
				name: "fNacimiento82", 
				index: "fNacimiento82", 
				editable: true, 
				hidden: false, 
				orderable: false, 
				rupType: 'date',
				editoptions: {
					yearRange: 'c-120:c',
					mask: 'dd/mm/yyyy',
					showButtonPanel : true,
					showOtherMonths : true,
	            },
			}						
		];
		
		if($("#idInfSocial02").val() != ''){
			
			const urlBase = $.rup.CTX_PATH +"convivientesinfsoci/"+$("#idInfSocial02").val();
			$("#convivencia").attr("data-url-base", urlBase);					
			
			const tableConvivencia = $("#convivencia").rup_table({
				colReorder: {
					fixedColumnsLeft: 1
				},
				colModel: tableColModels,
				columnDefs : [
					{ 
						"targets": 2,
						"width": "40%",					
					},
					{
						"targets": 3,
						"width": "35%",
					},
					{
						"targets": 4,
						"width": "25%",
					},
				],
				primaryKey: "idConviviente82",
				filter: "noFilter",			
				createTooltipBody: false,
				//inlineEdit: editParams,
				select: {
					activate: false
				},
				"pageLength": 50,
				dom: 't<"container-fluid paginationContainer"' +
				  '<"row mx-0"' +
				  '<"col-6 order-3 text-right align-self-center col-sm-5 order-sm-2 col-xl-2 order-xl-1 text-xl-left">' +
				  '<"d-none"p>' +
				  '<"col-12 text-center"i>' +
				  '>' +
				  '>' +
				  'r',
				buttons: {
					activate: false,
					blackListButtons: ['reportsButton', 'cloneButton', 'copyButton'],                        
				},
				order: [[0, "asc"]],
			});
		}	
			
	}

});