<?php  if($this->session->flashdata('success')): ?>
<div class="row">
    <div class="alert alert-block alert-success" style="margin-bottom: 5px">
        <button type="button" class="close" data-dismiss="alert">
            <i class="ace-icon fa fa-times"></i>
        </button>
        <i class="ace-icon fa fa-check green"></i>
        <?php echo $this->session->flashdata('success'); ?>
    </div>
</div>
<?php endif; ?>
<?php if($this->session->flashdata('error')): ?>
<div class="row">
    <div class="alert alert-block alert-danger" style="margin-bottom: 5px">
        <button type="button" class="close" data-dismiss="alert">
            <i class="ace-icon fa fa-times"></i>
        </button>
        <i class="ace-icon fa fa-times"></i>
        <?php echo $this->session->flashdata('error'); ?>
    </div>
</div>
<?php endif; ?>
<?php if(isset($track[0])): ?>
<div class="row">
    <div class="col-lg-12">
        <a class="btn btn-sm btn-success" href="<?php echo base_url('backend/cmsTrack/addSinger/'.$track[0]['id']);?>">
            <i class="glyphicon-plus"></i> Cập nhật Ca sĩ
        </a>
        <a class="btn btn-sm btn-primary" href="<?php echo base_url('backend/cmsTrack/addComposer/'.$track[0]['id']);?>">
            <i class="glyphicon-plus"></i> Cập nhật Nhạc sĩ
        </a>
        <a class="btn btn-sm btn-warning" href="<?php echo base_url('backend/cmsTrack/updateTrackImage/'.$track[0]['id'].'/null');?>">
            <i class="glyphicon-plus"></i> Cập nhật ảnh bài hát
        </a>
    </div>
</div>
<br>
<div class="row">
    <div class="profile-user-info profile-user-info-striped">
        <div class="profile-info-row">
            <div class="profile-info-name"> ID </div>
            <div class="profile-info-value">
                <span>#<?php echo $track[0]['id']?></span>
            </div>
        </div>

        <div class="profile-info-row">
            <div class="profile-info-name">Ảnh</div>
            <div class="profile-info-value">
                <span>
                    <img src="<?php echo MyHelper::getArtByTrack($track[0]['art'], false, $track[0]['art_type']) ?>"
                        style="max-width: 200px; max-height: 200px">
                </span>
            </div>
        </div>

        <div class="profile-info-row">
            <div class="profile-info-name">Tên Bài hát</div>
            <div class="profile-info-value">
                <span><?php echo $track[0]['title']; ?></span>
            </div>
        </div>

        <div class="profile-info-row">
            <div class="profile-info-name">Sáng tác</div>
            <div class="profile-info-value">
                <span><?php echo $track[0]['artist']; ?></span>
            </div>
        </div>

        <div class="profile-info-row">
            <div class="profile-info-name">Số người biểu diễn</div>
            <div class="profile-info-value">
                <span><?php echo count($singers); ?></span>
            </div>
        </div>

        <div class="profile-info-row">
            <div class="profile-info-name">Biểu diễn</div>
            <div class="profile-info-value">
                <?php if(count($singers) > 0) : ?>
                <?php foreach ($singers as $key => $singer) : ?>
                <div style="<?php if(count($track) >1 ) : echo 'width: 50%; float:left; text-align: left;'; endif; if(count($track) -1 > $key) : echo 'border-right: solid #dddddd 2px;'; endif; ?>">
                    <?php echo $singer['name_singer']; ?>
                    <a href="<?php echo base_url('backend/cmsTrack/removeSinger/'.$track[0]['id'].'/'.$singer['id_singer']); ?>"
                        title="Click để xóa Ca sĩ">
                        <i class="ace-icon fa fa-trash bigger-150" style="color: red;"></i>
                    </a>
                </div>
                <?php endforeach; ?>
                <?php else: echo '<span class="text-danger">Chưa có, cập nhật </span> <a href="' . base_url('backend/cmsTrack/addSinger/'.$track[0]['id']) .'">tại đây.</a>'; ?>
                <?php endif ?>
            </div>
        </div>
        <div class="profile-info-row">
            <div class="profile-info-name color-red" style="color: red">Không lấy lượt nghe ở trang nào thì tích chọn</div>
            <div class="profile-info-value">
                <label>
                    <input type="checkbox" value="zing" id="chk_zing"
                           onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, '<?php echo str_replace(["'", '"'], [","], $track[0]['title']); ?>', 'zing')"
                        <?php echo (in_array('zing', $blacklist) ? 'checked' : '') ?>>&nbsp;Zing
                </label><br>
                <label>
                    <input type="checkbox" value="nct" id="chk_nct"
                           onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, '<?php echo str_replace(["'", '"'], [","], $track[0]['title']); ?>', 'nct')"
                        <?php echo (in_array('nct', $blacklist) ? 'checked' : '') ?>>&nbsp;NCT
                </label><br>
                <label>
                    <input type="checkbox" value="keeng" id="chk_keeng"
                           onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, '<?php echo str_replace(["'", '"'], [","], $track[0]['title']); ?>', 'keeng')"
                        <?php echo (in_array('keeng', $blacklist) ? 'checked' : '') ?>>&nbsp;Keeng
                </label>
            </div>
        </div>

    </div>
</div>
<br>
<div class="row">
    <div class="col-lg-3">
        <a href="<?php echo base_url('backend/cmsTrack/listTrack');?>">
            <button type="button" class="btn btn-sm btn-default">
                <i class="ace-icon fa fa-arrow-left"></i>Quay lại
            </button>
        </a>
    </div>
</div>
<?php else: ?>
<p>Không tìm thấy thông tin Bài hát!</p>
<?php endif; ?>
<script>
    function updateBlacklistByAjax(track_id, title, src) {
        var selected = 0;

        if ($('#chk_' + src).is(":checked")) {
            selected = 1;
        } else {
            selected = 0;
        }

        callAjax(track_id, title, src, selected);
    }

    function callAjax(track_id, title, src, selected) {
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var url = '<?php echo base_url("backend/cmsTrack/updateBlacklistByAjax"); ?>';
        var dataReq = {
            csrf_name: csrf_value,
            track_id: track_id,
            title: title,
            src: src,
            selected: selected
        };
        //Ajax
        $.ajax({
            type: "POST",
            url: url,
            data: dataReq,
            dataType: "JSON",
            cache: false,
            success: function(data) {
                console.log(data);
                //$('#data-loading').hide();
            }
        });
    }
</script>
