<section class="content-header">
    <h1>
        Нийтлэл
        <small>засах</small>
    </h1>
</section>

<section class="content">

    <div class="row">

        <div class="col-md-7">

            <div class="nav-tabs-custom">

                <ul class="nav nav-tabs">

                    <li class="active"><a href="#info" data-toggle="tab">Ерөнхий мэдээлэл</a></li>

                </ul>

                <?php echo Form::open(['method' => 'put', 'url' => '/admin/posts/' . $item->id, 'files' => true]); ?>


                <div class="box-body">

                    <div class="tab-content">

                        <div class="tab-pane active" id="info">

                            <div class="form-group <?php echo $errors->has('lang_id') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('lang_id', 'Хэл'); ?>


                                <select name="lang_id" id="lang_id" class="form-control">

                                    <?php foreach($languages as $value): ?>

                                        <option value="<?php echo $value->id; ?>" <?php echo ($value->id == $item->lang_id) ? 'selected' : ''; ?>>
                                            <?php echo $value->title; ?>

                                        </option>

                                    <?php endforeach; ?>

                                </select>

                                <span class="help-block">

                                    <?php echo $errors->has('lang_id') ? $errors->first('lang_id') : ''; ?>


                                </span>

                            </div>

                            <div class="form-group <?php echo $errors->has('title') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('title', 'Гарчиг'); ?>


                                <?php echo Form::text('title', $item->title, ['class' => 'form-control', 'placeholder' => 'Нэр', 'required']); ?>


                                <span class="help-block">

                                    <?php echo $errors->has('title') ? $errors->first('title') : ''; ?>


                                </span>

                            </div>

                            <?php echo $__env->make('backend.contents.media.for_edit', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

                            <div class="form-group <?php echo $errors->has('short_content') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('short_content', 'Товч мэдээлэл'); ?>


                                <textarea name="short_content" id="short_content" class="ckeditor" cols="30"
                                          rows="10"><?php echo $item->short_content; ?></textarea>

                                <span class="help-block">

                                    <?php echo $errors->has('short_content') ? $errors->first('short_content') : ''; ?>


                                </span>

                            </div>

                            <div class="form-group <?php echo $errors->has('content') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('content', 'Дэлгэрэнгүй мэдээлэл'); ?>


                                <textarea name="content" id="content" class="ckeditor" cols="30"
                                          rows="10"><?php echo $item->content; ?></textarea>

                                <span class="help-block">

                                    <?php echo $errors->has('content') ? $errors->first('content') : ''; ?>


                                </span>

                            </div>

                            <div class="form-group <?php echo $errors->has('custom_date') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('custom_date', 'Нийтэлсэн огноо'); ?>


                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" value="<?php echo substr($item->custom_date, 0, 10); ?>"
                                           name="custom_date"
                                           class="form-control pull-right" id="datepicker">
                                </div>

                                <span class="help-block">

                                    <?php echo $errors->has('custom_date') ? $errors->first('custom_date') : ''; ?>


                                </span>

                            </div>

                            <div class="form-group">

                                <?php echo Form::label('category', 'Ангилал'); ?>


                                <div class="row">

                                    <div class="col-md-6">

                                        <ul class="category_id">

                                            <?php foreach($category as $value): ?>

                                                <li id="<?php echo $value->id; ?>">

                                                    <?php $has = $value->hasChildren($value->id, $has_posts_in_category) ? true : false ?>

                                                    <span>

                                                        <i class="fa <?php echo ($has) ? 'fa-minus-circle' : 'fa-plus-circle'; ?> pointer"
                                                           onclick="get_child('<?php echo $value->id; ?>')"></i>

                                                        <input type="checkbox" value="<?php echo $value->id; ?>"
                                                               <?php echo in_array($value->id, $has_posts_in_category) ? 'checked' : ''; ?>

                                                               name="category_id[]" class="flat-red">

                                                        <?php /*<i class="fa fa-minus-circle"></i>*/ ?>

                                                        <?php echo $value->title; ?>


                                                    </span>

                                                    <?php if($has): ?>

                                                        <?php echo get_child($value, $has_posts_in_category); ?>


                                                    <?php endif; ?>

                                                </li>

                                            <?php endforeach; ?>

                                        </ul>

                                    </div>

                                </div>

                                <div class="have">
                                    <?php foreach($has_posts_in_category as $value): ?>
                                        <input type="hidden" name="have[]" value="<?php echo $value; ?>">
                                    <?php endforeach; ?>
                                </div>

                            </div>

                            <div class="form-group <?php echo $errors->has('link') ? 'has-error' : ''; ?>">

                                <?php echo Form::label('link', 'Холбоос'); ?>


                                <?php echo Form::text('link', $item->link, ['class' => 'form-control', 'placeholder' => 'Холбоос']); ?>


                                <span class="help-block">

                                    <?php echo $errors->has('link') ? $errors->first('link') : ''; ?>


                                </span>

                            </div>

                            <div class="form-group">

                                <?php echo Form::label('is_active', 'Идэвхтэй'); ?>


                                <label>
                                    <input type="checkbox" value="1"
                                           <?php echo ($item->is_active == 1) ? 'checked' : ''; ?> name="is_active"
                                           class="flat-red">
                                </label>

                            </div>

                            <div class="form-group">

                                <?php echo Form::submit('Хадгалах', ['class' => 'btn btn-primary']); ?>


                            </div>

                        </div>

                    </div>

                </div>

                <?php echo Form::close(); ?>


            </div>

        </div>

    </div>

</section>

<?php
function get_child($value, $has_posts_in_category)
{
?>

<ul>

    <?php foreach($value->getChildren($value->id) as $v): ?>

        <li id="<?php echo $v->id; ?>">

            <?php $has = $v->hasChildren($v->id, $has_posts_in_category) ? true : false ?>

            <span>

                <i class="fa <?php echo ($has) ? 'fa-minus-circle' : 'fa-plus-circle'; ?> pointer"
                   onclick="get_child('<?php echo $v->id; ?>')"></i>
                <input type="checkbox" value="<?php echo $v->id; ?>"
                       <?php echo in_array($v->id, $has_posts_in_category) ? 'checked' : ''; ?>

                       name="category_id[]" class="flat-red">
                <?php echo $v->title; ?>


            </span>

            <?php if($has): ?>

                <?php echo get_child($v, $has_posts_in_category); ?>


            <?php endif; ?>

        </li>

    <?php endforeach; ?>

</ul>

<?php } ?>