
<?php
/**
 * Heist Board Installer
 * Run once. Creates all folders, files, and placeholders.
 */

$root = __DIR__ . '/heist-board';
$assets = $root . '/plan-assets';

@mkdir($root, 0777, true);
@mkdir($assets, 0777, true);

function writeFile($path, $content) {
    file_put_contents($path, $content);
}

writeFile($root.'/plan-board.php', <<<PHP
<?php
$dir = __DIR__;
$files = scandir($dir);
$pieces = [];

foreach ($files as $file) {
    if (!preg_match('/\.(php|html)$/', $file)) continue;
    if ($file === 'plan-board.php') continue;

    $base = pathinfo($file, PATHINFO_FILENAME);
    $img = null;
    foreach (['png','jpg','jpeg','webp'] as $ext) {
        if (file_exists("$dir/$base.$ext")) { $img = "$base.$ext"; break; }
    }

    $c = @file_get_contents("$dir/$file");
    preg_match('/<title>(.*?)<\/title>/i', $c, $m);

    $pieces[] = [
        'file' => $file,
        'title' => $m[1] ?? $base,
        'size' => round(filesize("$dir/$file")/1024,1).' KB',
        'date' => date('Y-m-d', filectime("$dir/$file")),
        'image' => $img
    ];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>The Plan</title>
<link rel="stylesheet" href="plan-assets/board.css">
</head>
<body>
<div id="board"><svg id="strings"></svg>
<?php foreach ($pieces as $i=>$p): ?>
<div class="piece" style="--i:<?= $i ?>">
<?php if($p['image']): ?><img src="<?= $p['image'] ?>"><?php endif; ?>
<div class="label"><strong><?= htmlspecialchars($p['title']) ?></strong><br><?= $p['file'] ?><br><?= $p['size'] ?><br><?= $p['date'] ?></div>
</div>
<?php endforeach; ?>
</div>
<script src="plan-assets/board.js"></script>
</body>
</html>
PHP);

writeFile($assets.'/board.css', "body{margin:0;background:#2b1d12;font-family:Courier,monospace;}#board{position:relative;width:100vw;height:100vh;background:url('cork.jpg') repeat;} .piece{position:absolute;top:calc(10% + var(--i)*12%);left:calc(10% + var(--i)*15%);background:#f6f1e7;padding:10px;box-shadow:0 8px 20px rgba(0,0,0,.4);} .piece img{max-width:220px;display:block;margin-bottom:6px;} .label{font-size:12px;}");

writeFile($assets.'/board.js', "const p=document.querySelectorAll('.piece'),s=document.getElementById('strings');p.forEach((e,i)=>{if(i+1<p.length){let a=e.getBoundingClientRect(),b=p[i+1].getBoundingClientRect(),l=document.createElementNS('http://www.w3.org/2000/svg','line');l.setAttribute('x1',a.left+a.width/2);l.setAttribute('y1',a.top+a.height/2);l.setAttribute('x2',b.left+b.width/2);l.setAttribute('y2',b.top+b.height/2);l.setAttribute('stroke','#b30000');l.setAttribute('stroke-width','2');s.appendChild(l);}});");

$placeholders = [
  'cork.jpg.txt' => "2048x2048 seamless cork texture",
  'pin.png.txt' => "128x128 transparent push pin",
  'string.svg.txt' => "Red thread texture",
  'top-banner.jpg.txt' => "1920x400 header image"
];

foreach ($placeholders as $f=>$t) {
  writeFile($assets.'/'.$f, $t);
}

echo "Heist board installed. Open heist-board/plan-board.php";
?>
