<?php
defined('BASEPATH') OR exit('No direct script access allowed');

if(empty($json['data'])) {
?>
    <h2>Error <?= $json['status'] ?></h2>
    <p class="lead">
        <?= $json['message'] ?>
    </p>
    <?php
} else {
    $json = $json['data'][0];
?>
        <style>
            dt,
            dd {
                font-size: 16px
            }
        </style>
        <div class="row">
            <div class="col-sm-6">
                <dl class="dl-horizontal">
                    <dt><?= lang('twitch_name'); ?></dt>
                    <dd><?= $json['display_name']; ?></dd>
                    <dt><?= lang('twitch_id'); ?></dt>
                    <dd><?= $json['id']; ?></dd>
                    <dt><?= lang('twitch_follower'); ?></dt>
                    <dd><?= number_format($json['followers'], 0, ",", "."); ?> <?= lang('twitch_follower'); ?></dd>
                    <dt><?= lang('twitch_views'); ?></dt>
                    <dd><?= number_format($json['view_count'], 0, ",", "."); ?> <?= lang('twitch_views'); ?></dd>
                    <dt><?= lang('twitch_partner'); ?></dt>
                    <dd><?= $json['partner'] ? lang('twitch_yes') : lang('twitch_no'); ?></dd>
                    <dt><?= lang('twitch_youth'); ?></dt>
                    <dd><?= $json['mature'] ? lang('twitch_no') : lang('twitch_yes'); ?></dd>
                    <dt><?= lang('twitch_language'); ?></dt>
                    <dd><?= $json['language']; ?></dd>
                    <dt><?= lang('twitch_created'); ?></dt>
                    <dd><?= date(lang('twitch_time'), strtotime($json['created_at'])); ?></dd>
                    <dt><?= lang('twitch_changed'); ?></dt>
                    <dd><?= date(lang('twitch_time'), strtotime($json['updated_at'])); ?></dd>
                </dl>
            </div>
            <div class="col-sm-6">
                <h4><?= lang('twitch_stream'); ?></h4>
                <dl class="dl-horizontal">
                    <dt><?= lang('twitch_stream_title'); ?></dt>
                    <dd><?= $json['status']; ?></dd>
                    <dt><?= lang('twitch_stream_game'); ?></dt>
                    <dd><?= $json['game']; ?></dd>
                    <dt><?= lang('twitch_stream_language'); ?></dt>
                    <dd><?= $json['broadcaster_language']; ?></dd>
                    <dt><?= lang('twitch_url'); ?></dt>
                    <dd><a href="<?= $json['url']; ?>" target="_blank"><?= $json['url']; ?></a></dd>
                </dl>
            </div>
        </div>
    <?php if($json['logo'] !== null && $json['profile_banner'] !== null) { ?>
        <div class="row">
            <h4><?= lang('twitch_media'); ?></h4>
            <div class="col-sm-3">
                <a href="<?= $json['logo']; ?>" target="_blank"><img src="<?= $json['logo']; ?>" class="rounded img-fluid"></a>
                <div class="gap"></div>
                <a href="<?= $json['logo']; ?>" target="_blank"><img src="<?= $json['video_banner']; ?>" class="rounded img-fluid"></a>
            </div>
            <div class="col-sm-9">
                <a href="<?= $json['profile_banner']; ?>" target="_blank"><img src="<?= $json['profile_banner']; ?>" class="rounded img-fluid"></a>
            </div>
        </div>
    <?php } ?>
    <?php if($stream['stream'] !== null) { ?>
        <div class="row">
            <h4><?= lang('twitch_livestream'); ?></h4>
            <div class="responsive-video">
                <iframe src="https://player.twitch.tv/?channel=<?= $json['name']; ?>" frameborder="0" scrolling="no" height="378" width="620"></iframe>
            </div>
        </div>
    <?php } ?>
    <?php if(!empty($videos['videos'])) { ?>
        <div class="row">
            <h4>Videos (<?= $videos['_total']; ?>)</h4>
            <?php foreach($videos['videos'] as $v) { ?>
                <div class="col-sm-4">
                    <a href="<?= $v['url']; ?>" target="_blank">
                        <img src="<?= $v['preview']; ?>" alt="" />
                        <h5><?= $v['title']; ?></h5>
                        <div class="col-sm-3">
                            <small><i class="fa fa-clock-o"></i> <?= date('d.m.Y', strtotime($v['created_at'])); ?></small>
                        </div>
                        <div class="col-sm-2">
                            <small><i class="fa fa-eye"></i> <?= number_format($v['views'], 0, '.', ','); ?></small>
                        </div>
                        <div class="col-sm-3">
                            <small><i class="fa fa-hourglass-end"></i> <?= date('i:s', intval($v['length'])); ?></small>
                        </div>
                        <div class="col-sm-4">
                            <small><i class="fa fa-gamepad"></i> <?= $v['game']; ?></small>
                        </div>
                    </a>
                </div>
            <?php } ?>
        </div>
    <?php } ?>
<?php }