import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
import '../theme/app_radius.dart';
import '../theme/app_text_styles.dart';

class KBSelector extends StatelessWidget {
  final List<String> knowledgeBases;
  final String? selectedKB;
  final ValueChanged<String?> onChanged;
  final bool compact;

  const KBSelector({
    super.key,
    required this.knowledgeBases,
    this.selectedKB,
    required this.onChanged,
    this.compact = false,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 10),
      decoration: BoxDecoration(
        color: AppColors.bgSecondary,
        border: Border.all(color: AppColors.border),
        borderRadius: AppRadius.smAll,
      ),
      child: DropdownButtonHideUnderline(
        child: DropdownButton<String>(
          value: selectedKB,
          hint: Text(
            compact ? 'No KB' : 'No KB Context',
            style: AppTextStyles.bodySmall.copyWith(color: AppColors.textTertiary),
          ),
          dropdownColor: AppColors.panelLight,
          icon: Icon(Icons.expand_more, size: 18, color: AppColors.textTertiary),
          isDense: compact,
          isExpanded: !compact,
          style: AppTextStyles.bodySmall,
          items: [
            DropdownMenuItem<String>(
              value: null,
              child: Text(compact ? 'No KB' : 'No KB Context',
                  style: AppTextStyles.bodySmall.copyWith(color: AppColors.textTertiary)),
            ),
            ...knowledgeBases.map((kb) => DropdownMenuItem(
                  value: kb,
                  child: Text('🧠 $kb', style: AppTextStyles.bodySmall),
                )),
          ],
          onChanged: onChanged,
        ),
      ),
    );
  }
}