const fs = require('fs');
const path = require('path');
const root = __dirname;
const css = fs.readFileSync(path.join(root, 'assets/css/style.css'), 'utf8');
const account = fs.readFileSync(path.join(root, 'account.php'), 'utf8');
const header = fs.readFileSync(path.join(root, 'app/header.php'), 'utf8');
let passed = 0, failed = 0;
function check(name, cond) {
  if (cond) { console.log(`PASS ${name}`); passed++; }
  else { console.error(`FAIL ${name}`); failed++; }
}
check('Account sadrži CTA Sačuvaj fotografiju', account.includes('Sačuvaj fotografiju'));
check('Account sadrži CTA Sačuvaj novu lozinku', account.includes('Sačuvaj novu lozinku'));
check('Photo CTA je u profile-photo-form', /profile-photo-form[\s\S]*?Sačuvaj fotografiju/.test(account));
check('Password CTA je u password-form', /password-form[\s\S]*?Sačuvaj novu lozinku/.test(account));
check('Postoji v3.22.2 mobile-only blok', css.includes('v3.22.2 — kompaktna mobile dugmad na Podaci o nalogu'));
check('Koristi postojeći 640px breakpoint', /@media \(max-width: 640px\)[\s\S]*?profile-photo-form[\s\S]*?password-form/.test(css));
check('Photo selector je lokalno ograničen', css.includes('.account-action-grid .profile-photo-form .inline-actions > .button-primary'));
check('Password selector je lokalno ograničen', css.includes('.account-action-grid .password-form .inline-actions > .button-primary'));
check('Mobile override uklanja 180px flex-basis', /profile-photo-form[\s\S]*?flex:\s*0 0 auto/.test(css));
check('Mobile override zadržava 48px touch target', /profile-photo-form[\s\S]*?min-height:\s*48px/.test(css));
check('Mobile override koristi 12px padding-block', /profile-photo-form[\s\S]*?padding-block:\s*12px/.test(css));
check('Ne koristi !important u novom bloku', !css.slice(css.indexOf('v3.22.2 — kompaktna mobile dugmad')).includes('!important'));
check('Globalni 760px flex-basis ostaje nepromenjen', css.includes('.inline-actions .button, .inline-actions button { flex: 1 1 180px; }'));
check('v3.22.1 quick/ticket CTA override ostaje prisutan', css.includes('.quick-card .inline-actions .button') && css.includes('.ticket-form-actions .button'));
check('Asset cache je v3.25.0', (header.match(/\?v=3\.25\.0/g) || []).length >= 2);
console.log(`RESULT ${passed}/${passed+failed} PASS`);
process.exit(failed ? 1 : 0);
