import os

files = [
    '/opt/lampp/htdocs/skripsifh/resources/views/p2/sk_pembimbing/create.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p2/sk_pembimbing/edit.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p3/surat_penelitian/create.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p3/surat_penelitian/edit.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p4/tim_penguji/create.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p4/tim_penguji/edit.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p5/undangan_ujian/create.blade.php',
    '/opt/lampp/htdocs/skripsifh/resources/views/p5/undangan_ujian/edit.blade.php'
]

search_str = """        var nimSelect = $('select[name="nim_mahasiswa"], select[name="nim"]');
        var judulTextarea = $('textarea[name="judul_skripsi"], textarea[name="judul"]');"""

replace_str = """        var nimSelect = $('select[name="nim_mahasiswa"], select[name="nim"]');
        nimSelect.select2({ theme: 'bootstrap4', placeholder: 'Pilih atau Cari Mahasiswa' });
        
        var dosenSelect = $('select[name^="nip_dosen"], select[name^="nip_penguji"]');
        if (dosenSelect.length > 0) {
            dosenSelect.select2({ theme: 'bootstrap4', placeholder: 'Pilih atau Cari Dosen' });
        }

        var judulTextarea = $('textarea[name="judul_skripsi"], textarea[name="judul"]');"""

for f in files:
    if os.path.exists(f):
        with open(f, 'r') as file:
            content = file.read()
        
        if search_str in content:
            content = content.replace(search_str, replace_str)
            with open(f, 'w') as file:
                file.write(content)
            print(f"Updated {f}")
        else:
            print(f"Already updated or string not found in {f}")
