<?php
/**
 * Champ catégorie GBP — select natif masqué + dropdown custom (.avi-cat-*).
 * Variables optionnelles avant include :
 *   $avi_category_lang (string) fr|en|es
 *   $avi_category_label_class (string)
 *   $avi_category_input_class (string) — ignoré par le dropdown (conservé pour compat)
 *   $avi_category_use_i18n_attrs (bool) — data-i18n label / placeholder search (shortcode)
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$avi_cat_lang = isset( $avi_category_lang ) ? $avi_category_lang : 'en';
if ( ! in_array( $avi_cat_lang, array( 'fr', 'en', 'es' ), true ) ) {
	$avi_cat_lang = 'en';
}

$avi_category_label_class = isset( $avi_category_label_class ) ? $avi_category_label_class : 'av-label';
$avi_category_label_style = isset( $avi_category_label_style ) ? $avi_category_label_style : '';
$avi_category_use_i18n    = ! empty( $avi_category_use_i18n_attrs );
$avi_cat_search_ph        = isset( $avi_category_search_placeholder ) ? $avi_category_search_placeholder : 'Search business type...';
$avi_cat_label_text       = isset( $avi_category_label_text ) ? $avi_category_label_text : 'Your business type';
$avi_cat_placeholder_text = isset( $avi_category_placeholder_text ) ? $avi_category_placeholder_text : '— Select your business type —';

$avi_cat_groups = array(
	array(
		'label'   => array(
			'en' => 'Marketing & Consulting',
			'fr' => 'Marketing & Conseil',
			'es' => 'Marketing y Consultoría',
		),
		'options' => array(
			array( 'en' => 'Marketing consultant', 'fr' => 'Consultant en marketing', 'es' => 'Consultor de marketing' ),
			array( 'en' => 'SEO consultant', 'fr' => 'Consultant SEO', 'es' => 'Consultor SEO' ),
			array( 'en' => 'Digital marketing agency', 'fr' => 'Agence de marketing digital', 'es' => 'Agencia de marketing digital' ),
			array( 'en' => 'Business consultant', 'fr' => 'Consultant en affaires', 'es' => 'Consultor de negocios' ),
			array( 'en' => 'Communication agency', 'fr' => 'Agence de communication', 'es' => 'Agencia de comunicación' ),
			array( 'en' => 'Web design agency', 'fr' => 'Agence web', 'es' => 'Agencia de diseño web' ),
			array( 'en' => 'IT consulting', 'fr' => 'Conseil en informatique', 'es' => 'Consultoría informática' ),
			array( 'en' => 'Graphic designer', 'fr' => 'Designer graphique', 'es' => 'Diseñador gráfico' ),
			array( 'en' => 'Social media agency', 'fr' => 'Agence réseaux sociaux', 'es' => 'Agencia de redes sociales' ),
			array( 'en' => 'Copywriter', 'fr' => 'Rédacteur web', 'es' => 'Redactor web' ),
			array( 'en' => 'Training center', 'fr' => 'Centre de formation', 'es' => 'Centro de formación' ),
			array( 'en' => 'Life coach', 'fr' => 'Coach de vie', 'es' => 'Coach de vida' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Health & Medical',
			'fr' => 'Santé & Médecine',
			'es' => 'Salud y Medicina',
		),
		'options' => array(
			array( 'en' => 'General practitioner', 'fr' => 'Médecin généraliste', 'es' => 'Médico de cabecera' ),
			array( 'en' => 'Dentist', 'fr' => 'Dentiste', 'es' => 'Dentista' ),
			array( 'en' => 'Physiotherapist', 'fr' => 'Kinésithérapeute', 'es' => 'Fisioterapeuta' ),
			array( 'en' => 'Psychologist', 'fr' => 'Psychologue', 'es' => 'Psicólogo' ),
			array( 'en' => 'Psychiatrist', 'fr' => 'Psychiatre', 'es' => 'Psiquiatra' ),
			array( 'en' => 'Osteopath', 'fr' => 'Ostéopathe', 'es' => 'Osteópata' ),
			array( 'en' => 'Naturopath', 'fr' => 'Naturopathe', 'es' => 'Naturópata' ),
			array( 'en' => 'Therapist', 'fr' => 'Thérapeute', 'es' => 'Terapeuta' ),
			array( 'en' => 'Ophthalmologist', 'fr' => 'Ophtalmologue', 'es' => 'Oftalmólogo' ),
			array( 'en' => 'Pediatrician', 'fr' => 'Pédiatre', 'es' => 'Pediatra' ),
			array( 'en' => 'Cardiologist', 'fr' => 'Cardiologue', 'es' => 'Cardiólogo' ),
			array( 'en' => 'Dermatologist', 'fr' => 'Dermatologue', 'es' => 'Dermatólogo' ),
			array( 'en' => 'Gynecologist', 'fr' => 'Gynécologue', 'es' => 'Ginecólogo' ),
			array( 'en' => 'Orthopedic surgeon', 'fr' => 'Chirurgien orthopédique', 'es' => 'Cirujano ortopédico' ),
			array( 'en' => 'Radiologist', 'fr' => 'Radiologue', 'es' => 'Radiólogo' ),
			array( 'en' => 'Veterinarian', 'fr' => 'Vétérinaire', 'es' => 'Veterinario' ),
			array( 'en' => 'Speech therapist', 'fr' => 'Orthophoniste', 'es' => 'Logopeda' ),
			array( 'en' => 'Occupational therapist', 'fr' => 'Ergothérapeute', 'es' => 'Terapeuta ocupacional' ),
			array( 'en' => 'Acupuncturist', 'fr' => 'Acupuncteur', 'es' => 'Acupuntor' ),
			array( 'en' => 'Nutritionist', 'fr' => 'Nutritionniste', 'es' => 'Nutricionista' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Beauty & Wellness',
			'fr' => 'Beauté & Bien-être',
			'es' => 'Belleza y Bienestar',
		),
		'options' => array(
			array( 'en' => 'Hair salon', 'fr' => 'Salon de coiffure', 'es' => 'Peluquería' ),
			array( 'en' => 'Beauty salon', 'fr' => 'Institut de beauté', 'es' => 'Salón de belleza' ),
			array( 'en' => 'Nail salon', 'fr' => 'Institut ongles', 'es' => 'Salón de uñas' ),
			array( 'en' => 'Spa', 'fr' => 'Spa', 'es' => 'Spa' ),
			array( 'en' => 'Massage therapist', 'fr' => 'Massothérapeute', 'es' => 'Masajista' ),
			array( 'en' => 'Tattoo studio', 'fr' => 'Studio de tatouage', 'es' => 'Estudio de tatuajes' ),
			array( 'en' => 'Barbershop', 'fr' => 'Barbier', 'es' => 'Barbería' ),
			array( 'en' => 'Tanning salon', 'fr' => 'Institut bronzage', 'es' => 'Centro de bronceado' ),
			array( 'en' => 'Aesthetic clinic', 'fr' => 'Clinique esthétique', 'es' => 'Clínica estética' ),
			array( 'en' => 'Eyebrow studio', 'fr' => 'Studio sourcils', 'es' => 'Estudio de cejas' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Sports & Fitness',
			'fr' => 'Sport & Fitness',
			'es' => 'Deporte y Fitness',
		),
		'options' => array(
			array( 'en' => 'Gym', 'fr' => 'Salle de sport', 'es' => 'Gimnasio' ),
			array( 'en' => 'Personal trainer', 'fr' => 'Coach sportif', 'es' => 'Entrenador personal' ),
			array( 'en' => 'Yoga studio', 'fr' => 'Studio de yoga', 'es' => 'Estudio de yoga' ),
			array( 'en' => 'Pilates studio', 'fr' => 'Studio de pilates', 'es' => 'Estudio de pilates' ),
			array( 'en' => 'Martial arts club', 'fr' => 'Club arts martiaux', 'es' => 'Club de artes marciales' ),
			array( 'en' => 'Sports club', 'fr' => 'Club sportif', 'es' => 'Club deportivo' ),
			array( 'en' => 'Swimming pool', 'fr' => 'Piscine', 'es' => 'Piscina' ),
			array( 'en' => 'CrossFit gym', 'fr' => 'Salle CrossFit', 'es' => 'Gimnasio CrossFit' ),
			array( 'en' => 'Dance studio', 'fr' => 'Studio de danse', 'es' => 'Academia de danza' ),
			array( 'en' => 'Climbing gym', 'fr' => 'Salle d\'escalade', 'es' => 'Rocódromo' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Food & Drink',
			'fr' => 'Restauration & Alimentation',
			'es' => 'Restauración',
		),
		'options' => array(
			array( 'en' => 'Restaurant', 'fr' => 'Restaurant', 'es' => 'Restaurante' ),
			array( 'en' => 'Cafe', 'fr' => 'Café', 'es' => 'Cafetería' ),
			array( 'en' => 'Bar', 'fr' => 'Bar', 'es' => 'Bar' ),
			array( 'en' => 'Bakery', 'fr' => 'Boulangerie', 'es' => 'Panadería' ),
			array( 'en' => 'Pastry shop', 'fr' => 'Pâtisserie', 'es' => 'Pastelería' ),
			array( 'en' => 'Pizza restaurant', 'fr' => 'Pizzeria', 'es' => 'Pizzería' ),
			array( 'en' => 'Sushi restaurant', 'fr' => 'Restaurant japonais', 'es' => 'Restaurante de sushi' ),
			array( 'en' => 'Burger restaurant', 'fr' => 'Restaurant burgers', 'es' => 'Hamburguesería' ),
			array( 'en' => 'Vegetarian restaurant', 'fr' => 'Restaurant végétarien', 'es' => 'Restaurante vegetariano' ),
			array( 'en' => 'Food truck', 'fr' => 'Food truck', 'es' => 'Food truck' ),
			array( 'en' => 'Ice cream shop', 'fr' => 'Glacier', 'es' => 'Heladería' ),
			array( 'en' => 'Wine bar', 'fr' => 'Bar à vins', 'es' => 'Bar de vinos' ),
			array( 'en' => 'Brewery', 'fr' => 'Brasserie', 'es' => 'Cervecería' ),
			array( 'en' => 'Catering service', 'fr' => 'Traiteur', 'es' => 'Servicio de catering' ),
			array( 'en' => 'Grocery store', 'fr' => 'Épicerie', 'es' => 'Tienda de comestibles' ),
			array( 'en' => 'Butcher shop', 'fr' => 'Boucherie', 'es' => 'Carnicería' ),
			array( 'en' => 'Fish shop', 'fr' => 'Poissonnerie', 'es' => 'Pescadería' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Legal & Finance',
			'fr' => 'Juridique & Finance',
			'es' => 'Legal y Finanzas',
		),
		'options' => array(
			array( 'en' => 'Lawyer', 'fr' => 'Avocat', 'es' => 'Abogado' ),
			array( 'en' => 'Notary', 'fr' => 'Notaire', 'es' => 'Notario' ),
			array( 'en' => 'Accountant', 'fr' => 'Expert-comptable', 'es' => 'Contable' ),
			array( 'en' => 'Financial advisor', 'fr' => 'Conseiller financier', 'es' => 'Asesor financiero' ),
			array( 'en' => 'Insurance agency', 'fr' => 'Agence d\'assurance', 'es' => 'Agencia de seguros' ),
			array( 'en' => 'Tax consultant', 'fr' => 'Conseiller fiscal', 'es' => 'Asesor fiscal' ),
			array( 'en' => 'Bailiff', 'fr' => 'Huissier de justice', 'es' => 'Oficial de justicia' ),
			array( 'en' => 'Patent attorney', 'fr' => 'Conseil en propriété intellectuelle', 'es' => 'Agente de patentes' ),
			array( 'en' => 'Mortgage broker', 'fr' => 'Courtier en prêts immobiliers', 'es' => 'Broker hipotecario' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Real Estate',
			'fr' => 'Immobilier',
			'es' => 'Inmobiliaria',
		),
		'options' => array(
			array( 'en' => 'Real estate agency', 'fr' => 'Agence immobilière', 'es' => 'Agencia inmobiliaria' ),
			array( 'en' => 'Property developer', 'fr' => 'Promoteur immobilier', 'es' => 'Promotor inmobiliario' ),
			array( 'en' => 'Interior designer', 'fr' => 'Décorateur d\'intérieur', 'es' => 'Diseñador de interiores' ),
			array( 'en' => 'Architect', 'fr' => 'Architecte', 'es' => 'Arquitecto' ),
			array( 'en' => 'Property management', 'fr' => 'Gestion locative', 'es' => 'Administración de fincas' ),
			array( 'en' => 'Home stager', 'fr' => 'Home stager', 'es' => 'Home stager' ),
			array( 'en' => 'Surveyor', 'fr' => 'Géomètre-expert', 'es' => 'Topógrafo' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Home Services',
			'fr' => 'Services à domicile',
			'es' => 'Servicios del hogar',
		),
		'options' => array(
			array( 'en' => 'Plumber', 'fr' => 'Plombier', 'es' => 'Fontanero' ),
			array( 'en' => 'Electrician', 'fr' => 'Électricien', 'es' => 'Electricista' ),
			array( 'en' => 'Locksmith', 'fr' => 'Serrurier', 'es' => 'Cerrajero' ),
			array( 'en' => 'Painter', 'fr' => 'Peintre en bâtiment', 'es' => 'Pintor' ),
			array( 'en' => 'Carpenter', 'fr' => 'Menuisier', 'es' => 'Carpintero' ),
			array( 'en' => 'Roofer', 'fr' => 'Couvreur', 'es' => 'Techador' ),
			array( 'en' => 'Mason', 'fr' => 'Maçon', 'es' => 'Albañil' ),
			array( 'en' => 'Cleaning service', 'fr' => 'Service de nettoyage', 'es' => 'Servicio de limpieza' ),
			array( 'en' => 'Moving company', 'fr' => 'Déménageur', 'es' => 'Empresa de mudanzas' ),
			array( 'en' => 'Gardener', 'fr' => 'Jardinier', 'es' => 'Jardinero' ),
			array( 'en' => 'Handyman', 'fr' => 'Homme toutes mains', 'es' => 'Manitas' ),
			array( 'en' => 'Heating technician', 'fr' => 'Chauffagiste', 'es' => 'Técnico de calefacción' ),
			array( 'en' => 'Air conditioning', 'fr' => 'Climatisation', 'es' => 'Aire acondicionado' ),
			array( 'en' => 'Window installer', 'fr' => 'Miroitier-vitrier', 'es' => 'Instalador de ventanas' ),
			array( 'en' => 'Tile setter', 'fr' => 'Carreleur', 'es' => 'Alicatador' ),
			array( 'en' => 'Pest control', 'fr' => 'Dératisation', 'es' => 'Control de plagas' ),
			array( 'en' => 'Pool installer', 'fr' => 'Pisciniste', 'es' => 'Instalador de piscinas' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Automotive',
			'fr' => 'Automobile',
			'es' => 'Automoción',
		),
		'options' => array(
			array( 'en' => 'Car dealer', 'fr' => 'Concessionnaire automobile', 'es' => 'Concesionario de coches' ),
			array( 'en' => 'Auto repair shop', 'fr' => 'Garage automobile', 'es' => 'Taller mecánico' ),
			array( 'en' => 'Car wash', 'fr' => 'Lavage automobile', 'es' => 'Lavado de coches' ),
			array( 'en' => 'Tire shop', 'fr' => 'Centre auto pneus', 'es' => 'Taller de neumáticos' ),
			array( 'en' => 'Auto body shop', 'fr' => 'Carrosserie', 'es' => 'Taller de chapa y pintura' ),
			array( 'en' => 'Motorcycle dealer', 'fr' => 'Concessionnaire moto', 'es' => 'Concesionario de motos' ),
			array( 'en' => 'Car rental', 'fr' => 'Location de voitures', 'es' => 'Alquiler de coches' ),
			array( 'en' => 'Driving school', 'fr' => 'Auto-école', 'es' => 'Autoescuela' ),
			array( 'en' => 'Electric vehicle charging', 'fr' => 'Borne recharge véhicule électrique', 'es' => 'Carga vehículo eléctrico' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Education & Training',
			'fr' => 'Éducation & Formation',
			'es' => 'Educación y Formación',
		),
		'options' => array(
			array( 'en' => 'Private tutor', 'fr' => 'Cours particuliers', 'es' => 'Clases particulares' ),
			array( 'en' => 'Language school', 'fr' => 'École de langues', 'es' => 'Escuela de idiomas' ),
			array( 'en' => 'Music school', 'fr' => 'École de musique', 'es' => 'Escuela de música' ),
			array( 'en' => 'Art school', 'fr' => 'École d\'art', 'es' => 'Escuela de arte' ),
			array( 'en' => 'Primary school', 'fr' => 'École primaire', 'es' => 'Colegio' ),
			array( 'en' => 'High school', 'fr' => 'Lycée', 'es' => 'Instituto' ),
			array( 'en' => 'University', 'fr' => 'Université', 'es' => 'Universidad' ),
			array( 'en' => 'Nursery', 'fr' => 'Crèche', 'es' => 'Guardería' ),
			array( 'en' => 'Tutoring center', 'fr' => 'Centre de soutien scolaire', 'es' => 'Centro de apoyo escolar' ),
			array( 'en' => 'Professional training', 'fr' => 'Formation professionnelle', 'es' => 'Formación profesional' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Retail & Commerce',
			'fr' => 'Commerce & Vente',
			'es' => 'Comercio y Ventas',
		),
		'options' => array(
			array( 'en' => 'Clothing store', 'fr' => 'Boutique de vêtements', 'es' => 'Tienda de ropa' ),
			array( 'en' => 'Shoe store', 'fr' => 'Magasin de chaussures', 'es' => 'Zapatería' ),
			array( 'en' => 'Florist', 'fr' => 'Fleuriste', 'es' => 'Floristería' ),
			array( 'en' => 'Bookstore', 'fr' => 'Librairie', 'es' => 'Librería' ),
			array( 'en' => 'Pharmacy', 'fr' => 'Pharmacie', 'es' => 'Farmacia' ),
			array( 'en' => 'Optician', 'fr' => 'Opticien', 'es' => 'Óptico' ),
			array( 'en' => 'Jewelry store', 'fr' => 'Bijouterie', 'es' => 'Joyería' ),
			array( 'en' => 'Electronics store', 'fr' => 'Magasin électronique', 'es' => 'Tienda de electrónica' ),
			array( 'en' => 'Furniture store', 'fr' => 'Magasin de meubles', 'es' => 'Mueblería' ),
			array( 'en' => 'Toy store', 'fr' => 'Magasin de jouets', 'es' => 'Juguetería' ),
			array( 'en' => 'Sports store', 'fr' => 'Magasin de sport', 'es' => 'Tienda de deportes' ),
			array( 'en' => 'Gift shop', 'fr' => 'Boutique cadeaux', 'es' => 'Tienda de regalos' ),
			array( 'en' => 'Organic store', 'fr' => 'Magasin bio', 'es' => 'Tienda ecológica' ),
			array( 'en' => 'Pet store', 'fr' => 'Animalerie', 'es' => 'Tienda de animales' ),
			array( 'en' => 'Music store', 'fr' => 'Magasin de musique', 'es' => 'Tienda de música' ),
			array( 'en' => 'Stationery store', 'fr' => 'Papeterie', 'es' => 'Papelería' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Hospitality & Tourism',
			'fr' => 'Hôtellerie & Tourisme',
			'es' => 'Hostelería y Turismo',
		),
		'options' => array(
			array( 'en' => 'Hotel', 'fr' => 'Hôtel', 'es' => 'Hotel' ),
			array( 'en' => 'Bed and breakfast', 'fr' => 'Chambre d\'hôtes', 'es' => 'Casa rural' ),
			array( 'en' => 'Holiday rental', 'fr' => 'Location saisonnière', 'es' => 'Alquiler vacacional' ),
			array( 'en' => 'Camping', 'fr' => 'Camping', 'es' => 'Camping' ),
			array( 'en' => 'Youth hostel', 'fr' => 'Auberge de jeunesse', 'es' => 'Albergue' ),
			array( 'en' => 'Travel agency', 'fr' => 'Agence de voyage', 'es' => 'Agencia de viajes' ),
			array( 'en' => 'Tourist guide', 'fr' => 'Guide touristique', 'es' => 'Guía turístico' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Events & Entertainment',
			'fr' => 'Événementiel & Loisirs',
			'es' => 'Eventos y Ocio',
		),
		'options' => array(
			array( 'en' => 'Event planner', 'fr' => 'Organisateur d\'événements', 'es' => 'Organizador de eventos' ),
			array( 'en' => 'Wedding planner', 'fr' => 'Wedding planner', 'es' => 'Wedding planner' ),
			array( 'en' => 'Photographer', 'fr' => 'Photographe', 'es' => 'Fotógrafo' ),
			array( 'en' => 'Videographer', 'fr' => 'Vidéaste', 'es' => 'Videógrafo' ),
			array( 'en' => 'DJ', 'fr' => 'DJ', 'es' => 'DJ' ),
			array( 'en' => 'Entertainment venue', 'fr' => 'Salle de spectacle', 'es' => 'Sala de espectáculos' ),
			array( 'en' => 'Cinema', 'fr' => 'Cinéma', 'es' => 'Cine' ),
			array( 'en' => 'Escape room', 'fr' => 'Escape game', 'es' => 'Escape room' ),
			array( 'en' => 'Bowling', 'fr' => 'Bowling', 'es' => 'Bolera' ),
			array( 'en' => 'Laser game', 'fr' => 'Laser game', 'es' => 'Laser game' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Transport & Logistics',
			'fr' => 'Transport & Logistique',
			'es' => 'Transporte y Logística',
		),
		'options' => array(
			array( 'en' => 'Taxi', 'fr' => 'Taxi', 'es' => 'Taxi' ),
			array( 'en' => 'Chauffeur service', 'fr' => 'Chauffeur VTC', 'es' => 'Servicio de chófer' ),
			array( 'en' => 'Courier service', 'fr' => 'Service de livraison', 'es' => 'Servicio de mensajería' ),
			array( 'en' => 'Freight transport', 'fr' => 'Transport de marchandises', 'es' => 'Transporte de mercancías' ),
			array( 'en' => 'Storage facility', 'fr' => 'Garde-meuble', 'es' => 'Almacén' ),
			array( 'en' => 'Bicycle repair', 'fr' => 'Réparateur de vélos', 'es' => 'Taller de bicicletas' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Nonprofit & Association',
			'fr' => 'Association & Nonprofit',
			'es' => 'ONG y Asociaciones',
		),
		'options' => array(
			array( 'en' => 'Nonprofit organization', 'fr' => 'Association', 'es' => 'ONG' ),
			array( 'en' => 'Charity', 'fr' => 'Organisation caritative', 'es' => 'Organización benéfica' ),
			array( 'en' => 'Religious organization', 'fr' => 'Organisation religieuse', 'es' => 'Organización religiosa' ),
			array( 'en' => 'Community center', 'fr' => 'Centre communautaire', 'es' => 'Centro comunitario' ),
			array( 'en' => 'Cultural association', 'fr' => 'Association culturelle', 'es' => 'Asociación cultural' ),
		),
	),
	array(
		'label'   => array(
			'en' => 'Other Services',
			'fr' => 'Autres services',
			'es' => 'Otros servicios',
		),
		'options' => array(
			array( 'en' => 'Printing service', 'fr' => 'Imprimerie', 'es' => 'Imprenta' ),
			array( 'en' => 'Photo studio', 'fr' => 'Studio photo', 'es' => 'Estudio fotográfico' ),
			array( 'en' => 'Dry cleaner', 'fr' => 'Pressing', 'es' => 'Tintorería' ),
			array( 'en' => 'Laundromat', 'fr' => 'Laverie automatique', 'es' => 'Lavandería' ),
			array( 'en' => 'Post office', 'fr' => 'Bureau de poste', 'es' => 'Oficina de correos' ),
			array( 'en' => 'Bank', 'fr' => 'Banque', 'es' => 'Banco' ),
			array( 'en' => 'Co-working space', 'fr' => 'Espace de coworking', 'es' => 'Espacio de coworking' ),
			array( 'en' => 'Funeral home', 'fr' => 'Pompes funèbres', 'es' => 'Funeraria' ),
			array( 'en' => 'Recruitment agency', 'fr' => 'Agence de recrutement', 'es' => 'Agencia de empleo' ),
			array( 'en' => 'Security company', 'fr' => 'Société de sécurité', 'es' => 'Empresa de seguridad' ),
		),
	),
);

$avi_cat_empty_msg = 'No results';
if ( $avi_cat_lang === 'fr' ) {
	$avi_cat_empty_msg = 'Aucun résultat';
} elseif ( $avi_cat_lang === 'es' ) {
	$avi_cat_empty_msg = 'Sin resultados';
}
?>
<div class="avision-category-field av-form-group">
	<label class="<?php echo esc_attr( $avi_category_label_class ); ?>"
		for="avi-cat-trigger"
		<?php echo $avi_category_label_style !== '' ? ' style="' . esc_attr( $avi_category_label_style ) . '"' : ''; ?>
		<?php echo $avi_category_use_i18n ? ' data-i18n="category_select_label"' : ''; ?>>
		<?php echo esc_html( $avi_cat_label_text ); ?>
	</label>

	<select name="avision_category" id="avision_category" required style="display:none;" aria-hidden="true" tabindex="-1">
		<option value=""><?php echo esc_html( $avi_cat_placeholder_text ); ?></option>
		<?php foreach ( $avi_cat_groups as $group ) : ?>
			<optgroup label="<?php echo esc_attr( isset( $group['label'][ $avi_cat_lang ] ) ? $group['label'][ $avi_cat_lang ] : $group['label']['en'] ); ?>">
				<?php
				foreach ( $group['options'] as $opt ) {
					$val = isset( $opt[ $avi_cat_lang ] ) ? $opt[ $avi_cat_lang ] : $opt['en'];
					echo '<option value="' . esc_attr( $val ) . '">' . esc_html( $val ) . '</option>';
				}
				?>
			</optgroup>
		<?php endforeach; ?>
	</select>

	<div class="avi-cat-wrap" id="avi-cat-wrap" role="combobox" aria-haspopup="listbox" aria-expanded="false">

		<button type="button" class="avi-cat-trigger" id="avi-cat-trigger" aria-haspopup="listbox">
			<span class="avi-cat-trigger-text"><?php echo esc_html( $avi_cat_placeholder_text ); ?></span>
			<svg class="avi-cat-chevron" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>
		</button>

		<div class="avi-cat-panel" id="avi-cat-panel" role="listbox" aria-label="<?php echo esc_attr( $avi_cat_label_text ); ?>">
			<div class="avi-cat-search-wrap">
				<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
				<input type="text"
					class="avi-cat-search"
					id="avi-cat-search"
					placeholder="<?php echo esc_attr( $avi_cat_search_ph ); ?>"
					autocomplete="off"
					aria-label="<?php echo esc_attr( $avi_cat_search_ph ); ?>"
					<?php echo $avi_category_use_i18n ? ' data-i18n-placeholder="category_search_placeholder"' : ''; ?>>
			</div>
			<div class="avi-cat-options" id="avi-cat-options">
				<?php foreach ( $avi_cat_groups as $gi => $group ) : ?>
					<?php
					$group_label = isset( $group['label'][ $avi_cat_lang ] ) ? $group['label'][ $avi_cat_lang ] : $group['label']['en'];
					?>
					<div class="avi-cat-group" data-group="<?php echo esc_attr( (string) $gi ); ?>">
						<div class="avi-cat-group-label"><?php echo esc_html( $group_label ); ?></div>
						<?php
						foreach ( $group['options'] as $opt ) {
							$val = isset( $opt[ $avi_cat_lang ] ) ? $opt[ $avi_cat_lang ] : $opt['en'];
							echo '<div class="avi-cat-option" role="option" aria-selected="false" data-value="' . esc_attr( $val ) . '" tabindex="0">';
							echo esc_html( $val );
							echo '</div>';
						}
						?>
					</div>
				<?php endforeach; ?>
				<div class="avi-cat-empty" style="display:none;"><?php echo esc_html( $avi_cat_empty_msg ); ?></div>
			</div>
		</div>
	</div>
</div>
<style>
.avi-cat-wrap { position:relative; width:100%; }
.avi-cat-trigger {
	width:100%; display:flex; align-items:center; justify-content:space-between;
	padding:10px 14px; border:1px solid #d1d5db; border-radius:8px;
	background:#fff; cursor:pointer; font-size:14px; color:#374151;
	text-align:left; transition:border-color .2s;
}
.avi-cat-trigger:focus, .avi-cat-trigger.open { border-color:#4f46e5; outline:none; box-shadow:0 0 0 3px rgba(79,70,229,.15); }
.avi-cat-trigger-text { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.avi-cat-trigger-text.selected { color:#111827; font-weight:500; }
.avi-cat-chevron { flex-shrink:0; margin-left:8px; transition:transform .2s; color:#6b7280; }
.avi-cat-wrap[aria-expanded="true"] .avi-cat-chevron { transform:rotate(180deg); }
.avi-cat-panel {
	display:none; position:absolute; top:calc(100% + 4px); left:0; right:0;
	background:#fff; border:1px solid #d1d5db; border-radius:10px;
	box-shadow:0 10px 40px rgba(0,0,0,.12); z-index:9999; overflow:hidden;
}
.avi-cat-wrap[aria-expanded="true"] .avi-cat-panel { display:block; }
.avi-cat-search-wrap {
	display:flex; align-items:center; gap:8px;
	padding:10px 14px; border-bottom:1px solid #f3f4f6; position:sticky; top:0; background:#fff;
}
.avi-cat-search-wrap svg { color:#9ca3af; flex-shrink:0; }
.avi-cat-search {
	flex:1; border:none; outline:none; font-size:13px; color:#374151;
	background:transparent; padding:0;
}
.avi-cat-search::placeholder { color:#9ca3af; }
.avi-cat-options { max-height:280px; overflow-y:auto; padding:6px 0; }
.avi-cat-options::-webkit-scrollbar { width:4px; }
.avi-cat-options::-webkit-scrollbar-thumb { background:#e5e7eb; border-radius:2px; }
.avi-cat-group-label {
	padding:8px 14px 4px; font-size:11px; font-weight:700; color:#9ca3af;
	text-transform:uppercase; letter-spacing:.06em;
}
.avi-cat-option {
	padding:9px 14px; font-size:13px; color:#374151; cursor:pointer;
	transition:background .1s;
}
.avi-cat-option:hover, .avi-cat-option:focus { background:#f5f3ff; color:#4f46e5; outline:none; }
.avi-cat-option.selected { background:#ede9fe; color:#4f46e5; font-weight:600; }
.avi-cat-empty { padding:16px 14px; font-size:13px; color:#9ca3af; text-align:center; }
.avi-cat-group.hidden { display:none; }
</style>
<script>
(function() {
	var wrap = document.getElementById('avi-cat-wrap');
	var trigger = document.getElementById('avi-cat-trigger');
	var triggerText = trigger ? trigger.querySelector('.avi-cat-trigger-text') : null;
	var panel = document.getElementById('avi-cat-panel');
	var search = document.getElementById('avi-cat-search');
	var options = document.getElementById('avi-cat-options');
	var select = document.getElementById('avision_category');
	var empty = options ? options.querySelector('.avi-cat-empty') : null;
	if (!wrap || !trigger || !panel || !search || !select) return;

	function openPanel() {
		wrap.setAttribute('aria-expanded', 'true');
		trigger.classList.add('open');
		search.value = '';
		filterOptions('');
		setTimeout(function() { search.focus(); }, 50);
	}
	function closePanel() {
		wrap.setAttribute('aria-expanded', 'false');
		trigger.classList.remove('open');
	}
	function togglePanel() {
		wrap.getAttribute('aria-expanded') === 'true' ? closePanel() : openPanel();
	}
	function selectOption(val, label) {
		var i;
		for (i = 0; i < select.options.length; i++) {
			if (select.options[i].value === val) {
				select.selectedIndex = i;
				break;
			}
		}
		if (triggerText) {
			triggerText.textContent = label;
			triggerText.classList.add('selected');
		}
		var opts = options.querySelectorAll('.avi-cat-option');
		opts.forEach(function(o) {
			o.classList.toggle('selected', o.dataset.value === val);
			o.setAttribute('aria-selected', o.dataset.value === val ? 'true' : 'false');
		});
		closePanel();
		select.dispatchEvent(new Event('change', { bubbles: true }));
	}
	function filterOptions(q) {
		q = q.toLowerCase().trim();
		var groups = options.querySelectorAll('.avi-cat-group');
		var totalVisible = 0;
		groups.forEach(function(g) {
			var opts = g.querySelectorAll('.avi-cat-option');
			var groupVisible = 0;
			opts.forEach(function(o) {
				var match = q === '' || o.textContent.toLowerCase().indexOf(q) !== -1;
				o.style.display = match ? '' : 'none';
				if (match) groupVisible++;
			});
			var lbl = g.querySelector('.avi-cat-group-label');
			g.classList.toggle('hidden', groupVisible === 0);
			if (lbl) lbl.style.display = groupVisible === 0 ? 'none' : '';
			totalVisible += groupVisible;
		});
		if (empty) empty.style.display = totalVisible === 0 ? 'block' : 'none';
	}

	trigger.addEventListener('click', togglePanel);
	search.addEventListener('input', function() { filterOptions(this.value); });
	search.addEventListener('keydown', function(e) {
		if (e.key === 'Escape') closePanel();
	});
	options.addEventListener('click', function(e) {
		var opt = e.target.closest('.avi-cat-option');
		if (opt) selectOption(opt.dataset.value, opt.textContent.trim());
	});
	options.addEventListener('keydown', function(e) {
		var opt = e.target.closest('.avi-cat-option');
		if (!opt) return;
		if (e.key === 'Enter' || e.key === ' ') {
			e.preventDefault();
			selectOption(opt.dataset.value, opt.textContent.trim());
		}
		if (e.key === 'Escape') closePanel();
	});
	document.addEventListener('click', function(e) {
		if (!wrap.contains(e.target)) closePanel();
	});
})();
</script>
