import os

file_path = r"c:\laragon\www\triwala-office\resources\js\Pages\Gaji\Index.tsx"

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

# Let's define the duplicate string with options for both CRLF and LF
dup_crlf = "                                 )}\r\n                                            </button>\r\n                                        </div>\r\n                                    </div>\r\n                                 )}"
dup_lf = "                                 )}\n                                            </button>\n                                        </div>\n                                    </div>\n                                 )}"

if dup_crlf in content:
    content = content.replace(dup_crlf, "                                 )}")
    print("Replaced CRLF version.")
elif dup_lf in content:
    content = content.replace(dup_lf, "                                 )}")
    print("Replaced LF version.")
else:
    # Let's try matching with flexible whitespace
    import re
    # We want to replace the first occurrence of:
    # )} followed by </button> </div> </div> )}
    pattern = r"\)\}\s*</button>\s*</div>\s*</div>\s*\)\}"
    new_content, count = re.subn(pattern, ")}", content)
    if count > 0:
        content = new_content
        print(f"Replaced regex version: {count} matches.")
    else:
        print("Duplicate block not found.")

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