import * as SMB2_MODULE from '@marsaud/smb2';
const SMB2 = (SMB2_MODULE as any).default || SMB2_MODULE;

const shares = [
  'dian priatna', 'Finance & Accounting', 'General Affair2', 'HRD_SMT1 20242025', 'IT', 'Kindergarten Gading',
  'Primary', 'Shared Folders', 'Users', 'hilda', 'rcs-public', 'OS', 'TV'
];

async function testShare(shareName: string) {
  return new Promise((resolve) => {
    const client = new SMB2({
      share: `\\\\173.22.1.3\\${shareName}`,
      domain: 'SYAFANAISLAMICS',
      username: 'salim',
      password: '11225588',
      autoCloseTimeout: 0
    });
    client.readdir('', (err: any, files: string[]) => {
      client.disconnect();
      if (err) {
         resolve({ name: shareName, access: false, reason: err.code });
      } else {
         resolve({ name: shareName, access: true, filesCount: files.length });
      }
    });
  });
}

async function run() {
  console.log("Testing access for 'salim'...");
  for (const share of shares) {
     const result: any = await testShare(share);
     if (result.access) {
         console.log(`[YES] Accessible: \\\\173.22.1.3\\${result.name} (Contains ${result.filesCount} items)`);
     } else {
         console.log(`[NO]  Denied:     \\\\173.22.1.3\\${result.name} (${result.reason})`);
     }
  }
}

run();
