<?php
/**
 * Footer marketing : colonnes + barre bas — option WP `avi_footer_nav_config`.
 * Édition : wp-admin → AVISION → Footer (admin.php?page=avi-footer-admin).
 *
 * @package Avision
 */

defined( 'ABSPATH' ) || exit;

if ( ! defined( 'AVI_FOOTER_NAV_OPTION' ) ) {
	define( 'AVI_FOOTER_NAV_OPTION', 'avi_footer_nav_config' );
}

/**
 * Structure par défaut (identique à l’ancien footer.php en dur).
 *
 * @return array{columns:array<int,array{titles:array<string,string>,links:array<int,array{path:string,labels:array<string,string>}>}>,bottom:array<int,array{path:string,labels:array<string,string}>}>}
 */
function avi_footer_nav_get_defaults() {
	return array(
		'columns' => array(
			array(
				'titles' => array(
					'en' => 'Product',
					'fr' => 'Produit',
					'es' => 'Producto',
				),
				'links'  => array(
					array(
						'path'   => 'how-it-works',
						'labels' => array(
							'en' => 'How It Works',
							'fr' => 'Comment ça marche',
							'es' => 'Cómo funciona',
						),
					),
					array(
						'path'   => 'pricing',
						'labels' => array(
							'en' => 'Pricing',
							'fr' => 'Tarifs',
							'es' => 'Precios',
						),
					),
					array(
						'path'   => 'demo-dashboard',
						'labels' => array(
							'en' => 'Demo',
							'fr' => 'Démo',
							'es' => 'Demo',
						),
					),
				),
			),
			array(
				'titles' => array(
					'en' => 'Agencies',
					'fr' => 'Agences',
					'es' => 'Agencias',
				),
				'links'  => array(
					array(
						'path'   => 'agency-pricing',
						'labels' => array(
							'en' => 'Agency Plans',
							'fr' => 'Plans agence',
							'es' => 'Planes agencia',
						),
					),
					array(
						'path'   => 'connexion',
						'labels' => array(
							'en' => 'Fleet Dashboard',
							'fr' => 'Cockpit flotte',
							'es' => 'Panel flota',
						),
					),
					array(
						'path'   => 'nonprofits',
						'labels' => array(
							'en' => 'Nonprofits',
							'fr' => 'Associations',
							'es' => 'Sin ánimo de lucro',
						),
					),
					array(
						'path'   => 'appsumo-redeem',
						'labels' => array(
							'en' => 'AppSumo LTD',
							'fr' => 'AppSumo LTD',
							'es' => 'AppSumo LTD',
						),
					),
				),
			),
			array(
				'titles' => array(
					'en' => 'Resources',
					'fr' => 'Ressources',
					'es' => 'Recursos',
				),
				'links'  => array(
					array(
						'path'   => 'blog',
						'labels' => array(
							'en' => 'Blog',
							'fr' => 'Blog',
							'es' => 'Blog',
						),
					),
					array(
						'path'   => 'local-audit',
						'labels' => array(
							'en' => 'Free Audit',
							'fr' => 'Audit gratuit',
							'es' => 'Auditoría gratis',
						),
					),
					array(
						'path'   => 'about',
						'labels' => array(
							'en' => 'About',
							'fr' => 'À propos',
							'es' => 'Acerca de',
						),
					),
					array(
						'path'   => 'refer',
						'labels' => array(
							'en' => 'Refer a Friend',
							'fr' => 'Parrainer',
							'es' => 'Recomendar',
						),
					),
				),
			),
			array(
				'titles' => array(
					'en' => 'Legal',
					'fr' => 'Légal',
					'es' => 'Legal',
				),
				'links'  => array(
					array(
						'path'   => 'privacy-policy',
						'labels' => array(
							'en' => 'Privacy Policy',
							'fr' => 'Politique de confidentialité',
							'es' => 'Política de privacidad',
						),
					),
					array(
						'path'   => 'terms-of-use',
						'labels' => array(
							'en' => 'Terms of Use',
							'fr' => 'Conditions d’utilisation',
							'es' => 'Términos de uso',
						),
					),
					array(
						'path'   => 'api-security',
						'labels' => array(
							'en' => 'API Security',
							'fr' => 'Sécurité API',
							'es' => 'Seguridad API',
						),
					),
					array(
						'path'   => 'legal/#gdpr',
						'labels' => array(
							'en' => 'GDPR',
							'fr' => 'RGPD',
							'es' => 'RGPD',
						),
					),
				),
			),
		),
		'bottom'    => array(
			array(
				'path'   => 'privacy-policy',
				'labels' => array(
					'en' => 'Privacy',
					'fr' => 'Confidentialité',
					'es' => 'Privacidad',
				),
			),
			array(
				'path'   => 'terms-of-use',
				'labels' => array(
					'en' => 'Terms',
					'fr' => 'Conditions',
					'es' => 'Términos',
				),
			),
			array(
				'path'   => 'api-security',
				'labels' => array(
					'en' => 'API Security',
					'fr' => 'API',
					'es' => 'API',
				),
			),
		),
	);
}

/**
 * Nettoie un segment de chemin (slug ou slug#ancre).
 *
 * @param string $path Chemin relatif.
 * @return string
 */
function avi_footer_nav_sanitize_path_segment( $path ) {
	$path = is_string( $path ) ? trim( wp_unslash( $path ) ) : '';
	if ( $path === '' ) {
		return '';
	}
	if ( strpos( $path, '#' ) !== false ) {
		$p = explode( '#', $path, 2 );
		$base = isset( $p[0] ) ? trim( $p[0], '/' ) : '';
		$frag = isset( $p[1] ) ? preg_replace( '/[^a-zA-Z0-9\-_]/', '', $p[1] ) : '';
		$base = preg_replace( '/[^a-zA-Z0-9\-\/]/', '', str_replace( '\\', '', $base ) );
		$base = trim( preg_replace( '#/{2,}#', '/', $base ), '/' );
		return $frag !== '' ? $base . '#' . $frag : $base;
	}
	$path = preg_replace( '/[^a-zA-Z0-9\-\/]/', '', str_replace( '\\', '', $path ) );
	return trim( preg_replace( '#/{2,}#', '/', $path ), '/' );
}

/**
 * Construit une URL à partir d’un chemin relatif (support ancre #).
 *
 * @param string $path Chemin type how-it-works ou legal/#gdpr.
 * @return string
 */
function avi_footer_nav_build_url( $path ) {
	$path = avi_footer_nav_sanitize_path_segment( $path );
	if ( $path === '' ) {
		return home_url( '/' );
	}
	if ( strpos( $path, '#' ) !== false ) {
		$p = explode( '#', $path, 2 );
		$base = trim( isset( $p[0] ) ? $p[0] : '', '/' );
		$frag = isset( $p[1] ) ? $p[1] : '';
		$url  = $base === '' ? trailingslashit( home_url( '/' ) ) : trailingslashit( home_url( '/' . $base . '/' ) );
		return $frag !== '' ? $url . '#' . $frag : $url;
	}
	return home_url( '/' . $path . '/' );
}

/**
 * Fusionne labels pour une langue.
 *
 * @param array<string,string> $labels Libellés par langue.
 * @param string               $lang   en|fr|es.
 * @return string
 */
function avi_footer_nav_pick_label( $labels, $lang ) {
	$lang = in_array( $lang, array( 'en', 'fr', 'es' ), true ) ? $lang : 'en';
	if ( ! is_array( $labels ) ) {
		return '';
	}
	if ( isset( $labels[ $lang ] ) && (string) $labels[ $lang ] !== '' ) {
		return (string) $labels[ $lang ];
	}
	return isset( $labels['en'] ) ? (string) $labels['en'] : '';
}

/**
 * Fusion profonde colonnes / bas de page avec les défauts.
 *
 * @param array<string,mixed> $saved Données option.
 * @return array{columns:array,bottom:array}
 */
function avi_footer_nav_merge_config( $saved ) {
	$def = avi_footer_nav_get_defaults();
	if ( ! is_array( $saved ) ) {
		return $def;
	}
	$out_cols = array();
	$def_cols = isset( $def['columns'] ) && is_array( $def['columns'] ) ? $def['columns'] : array();
	$sav_cols = isset( $saved['columns'] ) && is_array( $saved['columns'] ) ? $saved['columns'] : array();
	$max_c    = max( count( $def_cols ), count( $sav_cols ) );
	for ( $ci = 0; $ci < $max_c; $ci++ ) {
		$dcol = isset( $def_cols[ $ci ] ) ? $def_cols[ $ci ] : array( 'titles' => array(), 'links' => array() );
		$scol = isset( $sav_cols[ $ci ] ) && is_array( $sav_cols[ $ci ] ) ? $sav_cols[ $ci ] : array();
		$titles = array();
		foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
			$dt = isset( $dcol['titles'][ $lc ] ) ? (string) $dcol['titles'][ $lc ] : '';
			$st = isset( $scol['titles'][ $lc ] ) ? (string) $scol['titles'][ $lc ] : '';
			$titles[ $lc ] = $st !== '' ? $st : $dt;
		}
		$dlinks = isset( $dcol['links'] ) && is_array( $dcol['links'] ) ? $dcol['links'] : array();
		$slinks = isset( $scol['links'] ) && is_array( $scol['links'] ) ? $scol['links'] : array();
		$links  = array();
		$max_l  = max( count( $dlinks ), count( $slinks ) );
		for ( $li = 0; $li < $max_l; $li++ ) {
			$dl = isset( $dlinks[ $li ] ) ? $dlinks[ $li ] : array( 'path' => '', 'labels' => array() );
			$sl = isset( $slinks[ $li ] ) ? $slinks[ $li ] : array();
			$path = isset( $sl['path'] ) ? avi_footer_nav_sanitize_path_segment( $sl['path'] ) : '';
			if ( $path === '' && isset( $dl['path'] ) ) {
				$path = avi_footer_nav_sanitize_path_segment( $dl['path'] );
			}
			$labels = array();
			foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
				$labels[ $lc ] = '';
				if ( isset( $sl['labels'] ) && is_array( $sl['labels'] ) && isset( $sl['labels'][ $lc ] ) ) {
					$labels[ $lc ] = (string) $sl['labels'][ $lc ];
				} elseif ( isset( $dl['labels'][ $lc ] ) ) {
					$labels[ $lc ] = (string) $dl['labels'][ $lc ];
				}
			}
			$links[] = array(
				'path'   => $path,
				'labels' => $labels,
			);
		}
		$out_cols[] = array(
			'titles' => $titles,
			'links'  => $links,
		);
	}

	$def_bot = isset( $def['bottom'] ) && is_array( $def['bottom'] ) ? $def['bottom'] : array();
	$sav_bot = isset( $saved['bottom'] ) && is_array( $saved['bottom'] ) ? $saved['bottom'] : array();
	$bottom  = array();
	$max_b   = max( count( $def_bot ), count( $sav_bot ) );
	for ( $bi = 0; $bi < $max_b; $bi++ ) {
		$db = isset( $def_bot[ $bi ] ) ? $def_bot[ $bi ] : array( 'path' => '', 'labels' => array() );
		$sb = isset( $sav_bot[ $bi ] ) ? $sav_bot[ $bi ] : array();
		$path = isset( $sb['path'] ) ? avi_footer_nav_sanitize_path_segment( $sb['path'] ) : '';
		if ( $path === '' && isset( $db['path'] ) ) {
			$path = avi_footer_nav_sanitize_path_segment( $db['path'] );
		}
		$labels = array();
		foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
			$labels[ $lc ] = '';
			if ( isset( $sb['labels'] ) && is_array( $sb['labels'] ) && isset( $sb['labels'][ $lc ] ) ) {
				$labels[ $lc ] = (string) $sb['labels'][ $lc ];
			} elseif ( isset( $db['labels'][ $lc ] ) ) {
				$labels[ $lc ] = (string) $db['labels'][ $lc ];
			}
		}
		$bottom[] = array(
			'path'   => $path,
			'labels' => $labels,
		);
	}

	return array(
		'columns' => $out_cols,
		'bottom'  => $bottom,
	);
}

/**
 * Configuration fusionnée (option ou défauts).
 *
 * @return array{columns:array,bottom:array}
 */
function avi_footer_nav_get_config() {
	$saved = get_option( AVI_FOOTER_NAV_OPTION, null );
	return avi_footer_nav_merge_config( is_array( $saved ) ? $saved : array() );
}

/**
 * Données prêtes pour le template footer (langue active).
 *
 * @param string $lang en|fr|es.
 * @return array{columns:array<int,array{title:string,links:array<int,array{label:string,url:string}>}>,bottom:array<int,array{label:string,url:string}>}
 */
function avi_footer_nav_get_for_lang( $lang ) {
	$lang   = in_array( $lang, array( 'en', 'fr', 'es' ), true ) ? $lang : 'en';
	$config = avi_footer_nav_get_config();
	$cols   = array();
	foreach ( $config['columns'] as $col ) {
		$titles = isset( $col['titles'] ) && is_array( $col['titles'] ) ? $col['titles'] : array();
		$title  = avi_footer_nav_pick_label( $titles, $lang );
		$links  = array();
		if ( isset( $col['links'] ) && is_array( $col['links'] ) ) {
			foreach ( $col['links'] as $lk ) {
				$path = isset( $lk['path'] ) ? $lk['path'] : '';
				if ( avi_footer_nav_sanitize_path_segment( $path ) === '' ) {
					continue;
				}
				$lbls = isset( $lk['labels'] ) && is_array( $lk['labels'] ) ? $lk['labels'] : array();
				$lab  = avi_footer_nav_pick_label( $lbls, $lang );
				if ( $lab === '' ) {
					continue;
				}
				$links[] = array(
					'label' => $lab,
					'url'   => avi_footer_nav_build_url( $path ),
				);
			}
		}
		if ( $title !== '' && count( $links ) > 0 ) {
			$cols[] = array(
				'title' => $title,
				'links' => $links,
			);
		}
	}
	$bottom_out = array();
	foreach ( $config['bottom'] as $b ) {
		$path = isset( $b['path'] ) ? $b['path'] : '';
		if ( avi_footer_nav_sanitize_path_segment( $path ) === '' ) {
			continue;
		}
		$lbls = isset( $b['labels'] ) && is_array( $b['labels'] ) ? $b['labels'] : array();
		$lab  = avi_footer_nav_pick_label( $lbls, $lang );
		if ( $lab === '' ) {
			continue;
		}
		$bottom_out[] = array(
			'label' => $lab,
			'url'   => avi_footer_nav_build_url( $path ),
		);
	}
	return array(
		'columns' => $cols,
		'bottom'  => $bottom_out,
	);
}

/**
 * Sanitize POST footer.
 *
 * @param array<string,mixed> $post $_POST.
 * @return array{columns:array,bottom:array}|null
 */
function avi_footer_nav_sanitize_post( $post ) {
	if ( ! isset( $post['avi_footer_columns'] ) || ! is_array( $post['avi_footer_columns'] ) ) {
		return null;
	}
	$defaults = avi_footer_nav_get_defaults();
	$cols_in  = $post['avi_footer_columns'];
	$def_cols = $defaults['columns'];
	$columns  = array();
	$max_c    = max( count( $def_cols ), count( $cols_in ) );
	for ( $ci = 0; $ci < $max_c; $ci++ ) {
		$dcol = isset( $def_cols[ $ci ] ) ? $def_cols[ $ci ] : array( 'titles' => array(), 'links' => array() );
		$cin  = isset( $cols_in[ $ci ] ) && is_array( $cols_in[ $ci ] ) ? $cols_in[ $ci ] : array();
		$titles = array();
		foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
			$key          = 'title_' . $lc;
			$titles[ $lc ] = isset( $cin[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $cin[ $key ] ) ) : '';
			if ( $titles[ $lc ] === '' && isset( $dcol['titles'][ $lc ] ) ) {
				$titles[ $lc ] = (string) $dcol['titles'][ $lc ];
			}
		}
		$links_in = isset( $cin['links'] ) && is_array( $cin['links'] ) ? $cin['links'] : array();
		$dlinks   = isset( $dcol['links'] ) && is_array( $dcol['links'] ) ? $dcol['links'] : array();
		$links    = array();
		$max_l    = max( count( $dlinks ), count( $links_in ) );
		for ( $li = 0; $li < $max_l; $li++ ) {
			$din = isset( $links_in[ $li ] ) && is_array( $links_in[ $li ] ) ? $links_in[ $li ] : array();
			$dl  = isset( $dlinks[ $li ] ) ? $dlinks[ $li ] : array( 'path' => '', 'labels' => array() );
			$path = isset( $din['path'] ) ? avi_footer_nav_sanitize_path_segment( wp_unslash( (string) $din['path'] ) ) : '';
			if ( $path === '' && isset( $dl['path'] ) ) {
				$path = avi_footer_nav_sanitize_path_segment( $dl['path'] );
			}
			$labels = array();
			foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
				$key           = 'label_' . $lc;
				$labels[ $lc ] = isset( $din[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $din[ $key ] ) ) : '';
				if ( $labels[ $lc ] === '' && isset( $dl['labels'][ $lc ] ) ) {
					$labels[ $lc ] = (string) $dl['labels'][ $lc ];
				}
			}
			$links[] = array(
				'path'   => $path,
				'labels' => $labels,
			);
		}
		$columns[] = array(
			'titles' => $titles,
			'links'  => $links,
		);
	}

	$bottom_in = isset( $post['avi_footer_bottom'] ) && is_array( $post['avi_footer_bottom'] ) ? $post['avi_footer_bottom'] : array();
	$def_bot   = $defaults['bottom'];
	$bottom    = array();
	$max_b     = max( count( $def_bot ), count( $bottom_in ) );
	for ( $bi = 0; $bi < $max_b; $bi++ ) {
		$dbin = isset( $bottom_in[ $bi ] ) && is_array( $bottom_in[ $bi ] ) ? $bottom_in[ $bi ] : array();
		$db   = isset( $def_bot[ $bi ] ) ? $def_bot[ $bi ] : array( 'path' => '', 'labels' => array() );
		$path = isset( $dbin['path'] ) ? avi_footer_nav_sanitize_path_segment( wp_unslash( (string) $dbin['path'] ) ) : '';
		if ( $path === '' && isset( $db['path'] ) ) {
			$path = avi_footer_nav_sanitize_path_segment( $db['path'] );
		}
		$labels = array();
		foreach ( array( 'en', 'fr', 'es' ) as $lc ) {
			$key           = 'label_' . $lc;
			$labels[ $lc ] = isset( $dbin[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $dbin[ $key ] ) ) : '';
			if ( $labels[ $lc ] === '' && isset( $db['labels'][ $lc ] ) ) {
				$labels[ $lc ] = (string) $db['labels'][ $lc ];
			}
		}
		$bottom[] = array(
			'path'   => $path,
			'labels' => $labels,
		);
	}

	return array(
		'columns' => $columns,
		'bottom'  => $bottom,
	);
}

/**
 * Page admin AVISION → Footer.
 *
 * @return void
 */
function avi_render_footer_nav_admin_page() {
	if ( ! current_user_can( 'manage_options' ) ) {
		wp_die( esc_html__( 'Accès refusé.', 'avision-dashboard' ), '', array( 'response' => 403 ) );
	}

	if ( isset( $_POST['avi_footer_nav_save'] ) && isset( $_POST['_wpnonce'] )
		&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'avi_footer_nav_save' ) ) {
		$san = avi_footer_nav_sanitize_post( $_POST );
		if ( is_array( $san ) ) {
			update_option( AVI_FOOTER_NAV_OPTION, $san, false );
			echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Footer enregistré.', 'avision-dashboard' ) . '</p></div>';
		} else {
			echo '<div class="notice notice-error"><p>' . esc_html__( 'Données invalides.', 'avision-dashboard' ) . '</p></div>';
		}
	}

	$config      = avi_footer_nav_get_config();
	$footer_file = defined( 'AVISION_PATH' ) ? trailingslashit( AVISION_PATH ) . 'templates/layout/footer.php' : '';

	echo '<div class="wrap">';
	echo '<h1>' . esc_html__( 'Footer (public)', 'avision-dashboard' ) . '</h1>';
	echo '<p class="description">' . esc_html__( 'Colonnes de liens et barre inférieure : libellés EN / FR / ES et chemins relatifs (sans domaine). Pour une ancre : legal/#gdpr', 'avision-dashboard' ) . '</p>';
	if ( $footer_file !== '' ) {
		echo '<p><span class="description">' . esc_html__( 'Fichier d’affichage :', 'avision-dashboard' ) . '</span> <code>' . esc_html( $footer_file ) . '</code></p>';
	}

	echo '<form method="post" action="">';
	wp_nonce_field( 'avi_footer_nav_save' );
	echo '<input type="hidden" name="avi_footer_nav_save" value="1" />';

	$cols = isset( $config['columns'] ) ? $config['columns'] : array();
	foreach ( $cols as $ci => $col ) {
		$titles = isset( $col['titles'] ) && is_array( $col['titles'] ) ? $col['titles'] : array();
		echo '<h2 style="margin-top:28px;">' . esc_html( sprintf( /* translators: %d: column index */ __( 'Colonne %d', 'avision-dashboard' ), (int) $ci + 1 ) ) . '</h2>';
		echo '<table class="form-table" role="presentation"><tbody>';
		echo '<tr><th scope="row">' . esc_html__( 'Titres de colonne', 'avision-dashboard' ) . '</th><td>';
		echo '<div style="display:grid;gap:8px;max-width:520px;">';
		foreach ( array( 'en' => 'EN', 'fr' => 'FR', 'es' => 'ES' ) as $lc => $lab ) {
			$val = isset( $titles[ $lc ] ) ? (string) $titles[ $lc ] : '';
			echo '<label><span class="description">' . esc_html( $lab ) . '</span><br />';
			echo '<input type="text" class="regular-text" name="avi_footer_columns[' . (int) $ci . '][title_' . esc_attr( $lc ) . ']" value="' . esc_attr( $val ) . '" /></label>';
		}
		echo '</div></td></tr>';

		$links = isset( $col['links'] ) && is_array( $col['links'] ) ? $col['links'] : array();
		foreach ( $links as $li => $lk ) {
			$lbs = isset( $lk['labels'] ) && is_array( $lk['labels'] ) ? $lk['labels'] : array();
			echo '<tr><th scope="row">' . esc_html( sprintf( /* translators: %d: link index */ __( 'Lien %d', 'avision-dashboard' ), (int) $li + 1 ) ) . '</th><td>';
			echo '<fieldset style="display:grid;gap:8px;max-width:720px;">';
			echo '<label><span class="description">' . esc_html__( 'Chemin', 'avision-dashboard' ) . '</span><br />';
			echo '<input type="text" class="regular-text code" name="avi_footer_columns[' . (int) $ci . '][links][' . (int) $li . '][path]" value="' . esc_attr( isset( $lk['path'] ) ? (string) $lk['path'] : '' ) . '" /></label>';
			foreach ( array( 'en' => 'EN', 'fr' => 'FR', 'es' => 'ES' ) as $lc => $lc_lab ) {
				$v = isset( $lbs[ $lc ] ) ? (string) $lbs[ $lc ] : '';
				echo '<label><span class="description">' . esc_html( $lc_lab ) . '</span><br />';
				echo '<input type="text" class="regular-text" name="avi_footer_columns[' . (int) $ci . '][links][' . (int) $li . '][label_' . esc_attr( $lc ) . ']" value="' . esc_attr( $v ) . '" /></label>';
			}
			echo '</fieldset></td></tr>';
		}
		echo '</tbody></table>';
	}

	echo '<h2 style="margin-top:28px;">' . esc_html__( 'Barre du bas (Privacy / Terms / …)', 'avision-dashboard' ) . '</h2>';
	echo '<table class="form-table" role="presentation"><tbody>';
	$bottom = isset( $config['bottom'] ) ? $config['bottom'] : array();
	foreach ( $bottom as $bi => $b ) {
		$bls = isset( $b['labels'] ) && is_array( $b['labels'] ) ? $b['labels'] : array();
		echo '<tr><th scope="row">' . esc_html( sprintf( /* translators: %d */ __( 'Lien bas %d', 'avision-dashboard' ), (int) $bi + 1 ) ) . '</th><td>';
		echo '<fieldset style="display:grid;gap:8px;max-width:720px;">';
		echo '<label><span class="description">' . esc_html__( 'Chemin', 'avision-dashboard' ) . '</span><br />';
		echo '<input type="text" class="regular-text code" name="avi_footer_bottom[' . (int) $bi . '][path]" value="' . esc_attr( isset( $b['path'] ) ? (string) $b['path'] : '' ) . '" /></label>';
		foreach ( array( 'en' => 'EN', 'fr' => 'FR', 'es' => 'ES' ) as $lc => $lc_lab ) {
			$v = isset( $bls[ $lc ] ) ? (string) $bls[ $lc ] : '';
			echo '<label><span class="description">' . esc_html( $lc_lab ) . '</span><br />';
			echo '<input type="text" class="regular-text" name="avi_footer_bottom[' . (int) $bi . '][label_' . esc_attr( $lc ) . ']" value="' . esc_attr( $v ) . '" /></label>';
		}
		echo '</fieldset></td></tr>';
	}
	echo '</tbody></table>';

	submit_button( __( 'Enregistrer le footer', 'avision-dashboard' ) );
	echo '</form>';

	echo '<p style="margin-top:24px;"><a class="button button-secondary" href="' . esc_url( admin_url( 'admin.php?page=avi-nav-admin' ) ) . '">' . esc_html__( '← Navigation header', 'avision-dashboard' ) . '</a></p>';
	echo '</div>';
}
