<?php
$this->css($this->assetModule('front/front.css'));
$this->headMeta('noindex', 'robots');
?>

<div class="row user-section-wrapper">
    <div class="col-md-3">
        <?php include $this->template('./profile-sidebar.phtml'); ?>
    </div>
    <div class="col-md-9">
        <?php include $this->template('flash-messenger'); ?>
        <div class="mb-3">
            <h1><?php _e('My profile'); ?></h1>
        </div>
        <?php include $this->template('./profile-topbar.phtml'); ?>
        <div class="user-min-body user-profile-list">
            <?php foreach ($groups as $group) { ?>
                <div class="user-profile-item">
                    <div class="clearfix row user-legend" >
                        <?php if ($group['compound']) {
                            $editUrl = $this->url('', ['controller' => 'profile', 'action' => 'edit.compound', 'group' => $group['id']]);
                            $addUrl  = $editUrl . '#user-info-add';
                        } else {
                            $editUrl = $this->url('', ['controller' => 'profile', 'action' => 'edit.profile', 'group' => $group['id']]);
                        } ?>
                        <h4 class="col-8"><?php echo _escape($group['title']); ?></h4>
                        <div class="col-4 text-right">
                            <a class="btn btn-secondary" href="<?php echo $editUrl; ?>">
                                <i class="fas fa-pencil-alt"></i>
                                <?php _e('Edit'); ?>
                            </a>
                        </div>
                    </div>
                    <div class="user-legend-linea mb-3"></div>
                    <?php if (!empty($group['fields']) && $group['fields']) { ?>
                        <div class="user-field">
                            <?php
                            foreach ($group['fields'] as $set => $fields) {
                                echo '<dl class="row dl-horizonta user-field-d">';
                                foreach ($fields as $field) {
                                    echo sprintf(
                                        '<dt class="float-left col-lg-6 col-md-6 col-12">%s<dd class="col-lg-6 col-md-6 col-12">%s',
                                        $field['title'],
                                        $field['value'] ? _escape($field['value']) : '<em class="text-muted">' . __('Unfiled') . '</em>'
                                    );
                                }
                                echo '</dl>';
                            }
                            ?>
                        </div>
                    <?php } else { ?>
                        <a href="<?php echo $addUrl; ?>" class="card bg-light mb-3 text-center show">
                            <?php echo sprintf(__('Add %s'), $group['title']); ?>
                        </a>
                    <?php } ?>
                </div>
            <?php } ?>
        </div>
    </div>
</div>