<?php
$input_title = array(
    'name' => 'title',
    'type' => 'text',
    'value' => isset($title) ? $title : '',
    'placeholder' => 'Tên bài hát',
    'checked' => true,
    'class' => '',
    'style' => 'width: 100%',
    'min' => 1,
    'max' => 50
);

$input_link = array(
    'name' => 'link',
    'type' => 'text',
    'value' => isset($link) ? $link : '',
    'placeholder' => 'Nhập link bài hát',
    'class' => '',
    'style' => 'width: 100%',
    'min' => 1,
    'max' => 50
);

$input_nct_id = array(
    'name' => 'nct_id',
    'type' => 'text',
    'value' => isset($nct_id) ? $nct_id : '',
    'placeholder' => 'Id bài hát trên NCT',
    'class' => '',
    'style' => 'width: 100%',
    'min' => 1,
    'max' => 50
);

$input_zing = array(
    'name' => 'source',
    'id' => 'zing',
    'type' => 'radio',
    'value' => 'zing',
    'min' => 1,
    'max' => 50
);
$input_nct = array(
    'name' => 'source',
    'type' => 'radio',
    'id'=> 'nct',
    'value' => 'nct',
    'min' => 1,
    'max' => 50
);
$input_keeng = array(
    'name' => 'source',
    'type' => 'radio',
    'id' => 'keeng',
    'value' => 'keeng',
    'max' => 50
);
$check = "checked => 1";
(isset($source) && $source == 'zing' )? array_push($input_zing, $check) : '';
?>
<div class="row">
    <div class="widget-box">
        <div class="widget-header">
            <p class="widget-title">Thêm mới bài hát</p>
        </div>
        <div class="widget-body">
            <div class="widget-main">
                <?php
                $attributes = array('class' => 'form-horizontal', 'id' => 'myform');
                echo form_open_multipart(base_url('backend/cmsTrack/addTrack'), $attributes);
                ?>
                <div class="form-group">
                    <label class="col-lg-3"></label>
                    <div class="col-lg-3">
                        <input type="hidden" name="id" value="" />
                        <?php
                        if(validation_errors()){echo form_error('id', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3">Tên bài hát (*)</label>
                    <div class="col-lg-3">
                        <?php
                        echo form_input($input_title);
                        if(validation_errors()){echo form_error('title', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3">Tên Ca sĩ (*)</label>
                    <div class="col-lg-3">
                        <select id='form-field-select-3' name="singer" style='width: 200px;'
                            class="chosen-select form-control" data-placeholder="Choose a State...">
                            <?php if(!$singer):?>
                            <option value="0">Chọn ca sĩ</option>
                            <?php endif; ?>
                            <?php foreach ($list_user as $singers): ?>
                            <option value="<?php echo $singers['id']; ?>"
                                <?php if($singer && $singer == $singers['id']){ echo 'selected="selected"';}else  echo ''; ?>>
                                <?php echo $singers['full_name']; ?>
                            </option>
                            <?php endforeach;
                            ?>
                        </select>
                        <?php if(validation_errors()){echo form_error('singer', '<div class="error">', '</div>');} ?>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3">Tên Người sáng tác (*)</label>
                    <div class="col-lg-3">
                        <select id='form-field-select-3' name="artist" style='width: 200px;'
                            class="chosen-select form-control" data-placeholder="Choose a State...">
                            <option value="0">Chọn người sáng tác</option>
                            <?php foreach ($list_user as $artists): ?>
                            <option value="<?php echo $artists['id']; ?>"
                                <?php if($artist && $artist == $artists['id']){ echo 'selected="selected"';}else  echo ''; ?>>
                                <?php echo $artists['full_name']; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <?php if(validation_errors()){echo form_error('artist', '<div class="error">', '</div>');} ?>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3">Ảnh nhạc sĩ</label>
                    <div class="col-lg-3">
                        <input type="file" name="avatar" size="20" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3">Nguồn nhạc <?php isset($src_option) ? $src_option : ''; ?></label>
                    <div class="col-lg-3" id="source">
                        <div class="row">
                            <div class="col-lg-4">
                                <label class="src-option">
                                    <input name="source" id="zing" value="zing" type="radio"
                                        <?php if ($source == 'zing' || $source != 'nct' || $source != 'keeng') echo 'checked';?>>
                                    Zing
                                </label>
                            </div>
                            <div class="col-lg-4">
                                <label class="src-option">
                                    <input name="source" id="nct" value="nct" type="radio"
                                        <?php if($source == 'nct' ) echo 'checked' ;?>> NCT
                                </label>
                            </div>
                            <div class="col-lg-4">
                                <label class="src-option">
                                    <input name="source" id="keeng" value="keeng" type="radio"
                                        <?php if($source == 'keeng' ) echo 'checked'; ?>> Keeng
                                </label>
                            </div>
                        </div>
                        <?php
                            if(validation_errors()){echo form_error('nct_id', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3">Link nhạc</label>
                    <div class="col-lg-3">
                        <?php
                        echo form_input($input_link);
                        ?>
                    </div>
                </div>

                <div class="form-group" id="nct_id" style="display: none;">
                    <label class="col-lg-3">ID Nhạc của tui </label>
                    <div class="col-lg-3">
                        <?php
                            echo form_input($input_nct_id);
                        ?>
                    </div>
                    <input type="hidden" name="src_option"
                        value="<?php echo isset($src_option) ? $src_option : 'zing'; ?>" id="src_option">
                </div>

                <div class="form-group">
                    <div class="col-lg-3">
                        <a href="<?php echo base_url('backend/cmsTrack/listTrack');?>"
                            onclick="return confirm('Bạn có chắc chắn muốn quay lại Danh sách không?')">
                            <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 class="col-lg-4">
                        <button class="btn btn-sm btn-primary" type="submit" name="btnSave">
                            <i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
                        </button>
                        <button class="btn btn-sm" type="reset">
                            <i class="ace-icon fa fa-undo bigger-110"></i>Xóa form
                        </button>
                    </div>
                </div>
                <?php echo form_close(); ?>
                <p class="text-danger">Chú ý: Có thể cập nhật lại ca sĩ hoặc nhạc sĩ.</p>
            </div>

        </div>
    </div>
</div><!-- /.row -->
<script>
$(document).ready(function() {
    show_src_option($('#src_option').val());
    // Hiện ẩn option khi click nct
    $('input[type="radio"]').click(function() {
        show_src_option($(this).val());
    });

    $('input[name="source"]').click(function() {
        $('#src_option').val($(this).val());
    })

    $('.chosen-select').chosen({
        allow_single_deselect: true,
        no_results_text: "Không có kết quả cần tìm"
    });
    $(window)
        .off('resize.chosen')
        .on('resize.chosen', function() {
            $('.chosen-select').each(function() {
                var $this = $(this);
                $this.next().css({
                    'width': $this.parent().width()
                });
            })
        }).trigger('resize.chosen');
    //resize chosen on sidebar collapse/expand
    $(document).on('settings.ace.chosen', function(e, event_name, event_val) {
        if (event_name != 'sidebar_collapsed') return;
        $('.chosen-select').each(function() {
            var $this = $(this);
            $this.next().css({
                'width': $this.parent().width()
            });
        })
    });

});

function show_src_option(status) {
    if (status == 'nct') {
        $('#nct_id').show();
    } else
        $('#nct_id').hide();
}
</script>