import re

filepath = "/Users/thongle/Downloads/REPO/goerp/goerp-core/packages/core/src/ui/forms/multi-select.tsx"

with open(filepath, 'r', encoding='utf-8') as f:
    content = f.read()

old_search_logic = """    // Filter options based on search value
    const filteredOptions = useMemo(() => {
      if (!searchValue.trim()) {
        return options;
      }
      const searchLower = searchValue.toLowerCase();
      return options.filter(
        (option) =>
          option.label.toLowerCase().includes(searchLower) ||
          String(option.value).toLowerCase().includes(searchLower),
      );
    }, [options, searchValue]);"""

new_search_logic = """    // Filter options based on search value
    const filteredOptions = useMemo(() => {
      if (!searchValue.trim()) {
        return options;
      }
      const removeAccents = (str: string) => {
        return str ? str.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '') : '';
      };
      
      const searchLower = removeAccents(searchValue.toLowerCase());
      
      return options.filter(
        (option) => {
          const labelLower = option.label ? removeAccents(option.label.toLowerCase()) : '';
          const valueLower = option.value !== undefined && option.value !== null 
            ? removeAccents(String(option.value).toLowerCase()) 
            : '';
          return labelLower.includes(searchLower) || valueLower.includes(searchLower);
        }
      );
    }, [options, searchValue]);"""

content = content.replace(old_search_logic, new_search_logic)

with open(filepath, 'w', encoding='utf-8') as f:
    f.write(content)

print("Updated multiselect search logic")
