<?php if ( $docs ) { ?>

<div class="wedocs-shortcode-wrap">
    <div class="ui grid wedocs-docs-list">
        <?php foreach ( $docs as $main_doc ) { ?>
            <?php 
            $total_sections = 0;
            $author_ids     = array();
            $more_than_6    = 0;
            $author_names   = array();
            if ( $main_doc['sections'] ) :
                foreach ( $main_doc['sections'] as $section ) :
                    $total_sections++;

                    if ( array_key_exists( $section->post_author, $author_ids ) ) {
                        continue;
                    }

                    $author_name = get_the_author_meta( 'display_name', $section->post_author );
                    $author_names[ $section->post_author ] = $author_name;
                    
                    $author_ids[ $section->post_author ] = array(
                        'id'           => $section->post_author,
                        'display_name' => $author_name,
                        'gravatar'     => get_avatar_url( $section->post_author )
                    );
                endforeach;
            endif; ?>

            <div class="sixteen wide mobile eight wide computer column wedocs-docs-single">
                <div class="ui raised padded segment">
                    <div class="ui large header">
                        <i class="file alternate outline icon"></i>
                        <div class="content">
                            <a href="<?php echo get_permalink( $main_doc['doc']->ID ); ?>"><?php echo esc_html($main_doc['doc']->post_title); ?></a>
                            <?php if ( $total_sections ) : ?>
                                <div class="sub header">
                                    <?php printf( _n( '%s section in this topic', '%s sections in this topic', $total_sections, 'campoal' ), number_format_i18n( $total_sections ) ); ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <?php if ( $main_doc['sections'] ) { ?>

                        <div class="inside">
                            <div class="ui large list wedocs-doc-sections">
                                <?php 
                                $i = 0;
                                foreach ( $main_doc['sections'] as $section ) {
                                    if ($i == 3) {
                                        break;
                                    } ?>
                                    <div class="item">
                                        <i class="folder outline icon"></i>
                                        <div class="content">
                                            <div class="header">
                                                <a href="<?php echo get_permalink( $section->ID ); ?>"><?php echo esc_html($section->post_title); ?></a>
                                            </div>
                                        </div>
                                    </div>
                                <?php 
                                $i++;
                            } ?>
                            </div>
                        </div>

                    <?php } ?>

                    <div class="ui hidden divider"></div>
                    <div class="wedocs-doc-link">
                        <a class="ui mini circular button" href="<?php echo get_permalink( $main_doc['doc']->ID ); ?>">
                            <?php echo wp_kses_post($more); ?>
                            <i class="angle right icon"></i>
                        </a>
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

<?php }
