<?php
declare(strict_types=1);
$options=getopt('', ['target::']);
$target=rtrim((string)($options['target']??'C:\xampp\htdocs\ddb-new'),"\\/");
function pj(string ...$p):string{return preg_replace('~[\\/]+~',DIRECTORY_SEPARATOR,implode(DIRECTORY_SEPARATOR,$p))??'';}
function text(string $p):string{$v=@file_get_contents($p);return $v===false?'':$v;}
$checks=[];$failed=[];
$check=static function(bool $ok,string $name)use(&$checks,&$failed):void{$checks[]=$name;if(!$ok)$failed[]=$name;};
$layout=text(pj($target,'app/Views/layouts/main.php'));
$js=text(pj($target,'public/assets/js/native-executive-sidebar-r5-stable.js'));
$css=text(pj($target,'public/assets/css/diar-sidebar-r5-root-stability.css'));
$parentCss=text(pj($target,'public/assets/css/diar-premium-stabilization.css'));
$check($layout!=='','LAYOUT_EXISTS');
$check($js!=='','R5_JS_EXISTS');
$check($css!=='','R5_CSS_EXISTS');
$check($parentCss!=='','PARENT_STABILIZATION_EXISTS');
$check(substr_count($layout,'DIAR_6B_2_R3_1_2_ROOT_STABILITY_CSS')===1,'CSS_MARKER_ONCE');
$check(substr_count($layout,'DIAR_6B_2_R3_1_2_ROOT_STABILITY_JS')===1,'JS_MARKER_ONCE');
$check(strpos($layout,"native-executive-sidebar-r5-stable.js")!==false,'R5_SCRIPT_LINKED');
$check(strpos($layout,"diar-sidebar-r5-root-stability.css")!==false,'R5_CSS_LINKED');
$check(strpos($layout,'<?php if ($isDiarPremiumPage): ?>')!==false,'DIAR_CONDITIONAL_PRESENT');
$check(substr_count($layout,'native-executive-sidebar.js?v=native-sidebar-r4')===1,'LEGACY_SCRIPT_RETAINED_ONCE');
$check(strpos($js,'MutationObserver')===false,'NO_MUTATION_OBSERVER');
$check(strpos($js,'applyDensity')===false,'NO_DYNAMIC_DENSITY_FUNCTION');
$check(strpos($js,"classList.add('native-sidebar-height-compact'")===false,'NO_COMPACT_CLASS_ADD');
$check(strpos($js,"classList.add('native-sidebar-height-ultra'")===false,'NO_ULTRA_CLASS_ADD');
$check(strpos($js,"data-native-sidebar-density', 'FIXED'")!==false,'FIXED_DENSITY_CONTRACT');
$check(strpos($js,"data-native-sidebar-release', 'R5S'")!==false,'R5_RELEASE_CONTRACT');
$check(strpos($js,"window.addEventListener('resize'")!==false,'RESIZE_ONLY_RECHECK');
$check(strpos($css,'transition:none!important')!==false,'NO_SIDEBAR_TRANSITIONS');
$check(strpos($css,'animation:none!important')!==false,'NO_SIDEBAR_ANIMATIONS');
$check(strpos($css,'overflow-anchor:none!important')!==false,'NO_SCROLL_ANCHOR_JUMP');
$check(strpos($css,'scrollbar-gutter:stable both-edges!important')!==false,'STABLE_SCROLLBAR_GUTTER');
$check(strpos($css,'.native-nav-item:hover')!==false,'HOVER_RULE_PRESENT');
$check(strpos($css,'MAX_GEOMETRY_DELTA')===false,'NO_TEST_TEXT_IN_RUNTIME_CSS');
$check(strpos($parentCss,'native-sidebar-height-compact')!==false,'PARENT_DYNAMIC_CLASSES_NEUTRALIZED');
$check(strpos($layout,'DIAR_6B_2_R3_1_1_STABILIZATION_CSS')!==false,'PARENT_R3_1_1_PRESENT');
if($failed!==[]){fwrite(STDERR,'DIAR_6B_2_R3_1_2_STATIC_QA|FAIL|CHECKS='.count($checks).'|FAILED='.implode(',',$failed).PHP_EOL);exit(1);}
echo 'DIAR_6B_2_R3_1_2_STATIC_QA|PASS|CHECKS='.count($checks).'|MUTATION_LOOP=REMOVED|DENSITY=FIXED|HOVER_GEOMETRY=LOCKED|LEGACY_NON_DIAR=PRESERVED'.PHP_EOL;
