<?php
$pietra = get_field('pietra', 'options');
$level_status = getLevelStatus($pietra);
?>

<script type="text/javascript">
    const map_svgs = {
        'pietra': {
            <?php foreach ($pietra as $nr => $pietro): ?>
                <?php if (!$pietro['zablokuj']): ?>
                '<?php echo $pietro['id_pietra'] ?>': {
                    'bg': '<?php echo $pietro['obrazek'] ?>',
                    'svg': '<?php echo str_replace(["\n", "\r", PHP_EOL], "", $pietro['svg']) ?>',
                    'pietro_id': '<?php echo $pietro['id_pietra'] ?>',
                    'pietro_nazwa': '<?php echo $pietro['nazwa_pietra'] ?>',
                },
                <?php endif; ?>
            <?php endforeach; ?>
        },
        <?php foreach ($pietra as $nr => $pietro): ?>
            <?php if (!$pietro['zablokuj']): ?>
            '<?php echo $pietro['id_pietra'] ?>': {
                <?php if ($pietro['mieszkania']): ?>
                    <?php foreach ($pietro['mieszkania'] as $mieszkanie): ?>
                    '<?php echo $mieszkanie['nr'] ?>': {
                        'nr': '<?php echo $mieszkanie['nr'] ?>',
                        'liczba_pokoi': '<?php echo $mieszkanie['liczba_pokoi'] ?>',
                        'metraz': '<?php echo $mieszkanie['metraz'] ?>',
                        'balkon': '<?php echo $mieszkanie['balkon'] ?>',
                        'karta_mieszkania': '<?php echo $mieszkanie['karta_mieszkania'] ?>',
                        'status': '<?php echo $mieszkanie['status'] ?>',
                        'link': '<?php echo $mieszkanie['link'] ?>',
                    },
                    <?php endforeach; ?>
                <?php endif; ?>
            },
            <?php endif; ?>
        <?php endforeach; ?>
    };

    const level_status = {
        <?php foreach ($level_status as $key => $level): ?>
            '<?php echo $key ?>': {
                'free': '<?php echo $level['free'] ?>',
                'reserved': '<?php echo $level['reserved'] ?>',
                'sold': '<?php echo $level['sold'] ?>',
                'level': '<?php echo $level['level'] ?>',
            },
        <?php endforeach; ?>
    };
</script>