#!/usr/bin/env python3
"""
Debug script to see exactly what's happening in the ICR processing stage.
This will help us understand why long vowel detection isn't working.
"""

import cadar


def debug_icr_processing():
    print("=== DEBUG: ICR Processing Stage ===\n")

    # Test cases
    test_cases = [
        "aa",  # Should become A2
        "ii",  # Should become I2
        "uu",  # Should become U2
        "oo",  # Should become O2
        "اا",  # Should become A2
        "يي",  # Should become I2
        "وو",  # Should become U2
        "laa",  # Should have A2 segment
        "لا",  # Should have A2 segment when converted back
    ]

    for test_input in test_cases:
        print(f"Testing: '{test_input}'")

        try:
            # Try to convert and see what happens
            if all(ord(c) < 128 for c in test_input):  # Latin script
                arabic_result = cadar.bizi2ara(test_input, darija="Ma")
                print(f"  Latin → Arabic: '{test_input}' → '{arabic_result}'")

                # Now convert back
                latin_result = cadar.ara2bizi(arabic_result, darija="Ma")
                print(f"  Arabic → Latin: '{arabic_result}' → '{latin_result}'")

                # Check if roundtrip successful
                if test_input == latin_result:
                    print("  ✅ Roundtrip: SUCCESS")
                else:
                    print(
                        f"  ❌ Roundtrip: FAILED (expected '{test_input}', got '{latin_result}')"
                    )
            else:  # Arabic script
                latin_result = cadar.ara2bizi(test_input, darija="Ma")
                print(f"  Arabic → Latin: '{test_input}' → '{latin_result}'")

        except Exception as e:
            print(f"  ❌ ERROR: {e}")

        print()


if __name__ == "__main__":
    debug_icr_processing()
