<?php if($article['status'] == true): ?>
<?php $__currentLoopData = $article['data']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php  
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
        $url = "https://";   
    else  
        $url = "http://";   
        // Append the host(domain name, ip) to the URL.   
        $url.= $_SERVER['HTTP_HOST'];
        // Append the requested resource location to the URL   
        $url.= $_SERVER['REQUEST_URI'];
        // echo $url;  
?>
<?php $__env->startPush('header'); ?>
<meta property="og:url" content="<?php echo e($url); ?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="KM DOH" />
<meta property="og:description" content="<?php echo e($ad['name']); ?>" />
<meta property="og:image" content="<?php echo e(asset('../storage/km/cover/'.$ad['photo'])); ?>" />
<?php $__env->stopPush(); ?>
<div class="row mx-md-n5 margin-down">
    <div class="kitem-1 ">
        <div class="d-flex bd-highlight">
            <div class="w-100 bd-highlight">
                <h3 class="txtorange-1"><?php echo e($ad['name']); ?></h3>
            </div>
            <div class="lex-shrink-1 bd-highlight" style="flex-basis: 100px;">
                <button type="button" class="btn btn-link back" style="color: #808080;">ย้อนกลับ</button>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-2">
            <p class="kitem-1">
                <i class="fas fa-barcode"></i>
                <strong>รหัสความรู้:</strong>
            </p>
        </div>
        <div class="col-sm-10">
            <p class="kitem-1"><?php echo e($ad['code']); ?></p>
        </div>
        <div class="col-sm-2">
            <p class="kitem-1">
                <i class="fas fa-folder-open"></i>
                <strong>ประเภท:</strong>
            </p>
        </div>
        <div class="col-sm-10">
            <p class="kitem-1"><?php echo e($ad['group']['name']); ?></p>
        </div>
        <div class="col-sm-2">
            <p class="kitem-1">
                <i class="fas fa-tags"></i>
                <strong> คำสำคัญ :</strong>
            </p>
        </div>
        <div class="col-sm-10 div-taghilight">
            <?php if(count($ad['article_tags']) > 0): ?>
            <?php $__currentLoopData = $ad['article_tags']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $at): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php if($at['status'] == 1): ?>
            <div>
                <span class="taghilight">
                    <a><?php echo e($at['name']); ?></a>
                </span>
            </div>
            <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
        </div>
    </div>

</div>
<div class="row mx-md-n5 margin-down">
    <div class="col-md-3">
        <img src="<?php echo e(asset('../storage/km/cover/'.$ad['photo'])); ?>" class="img-fluid">
    </div>
    <div class="col-md-9">
        <div class="row">
            <div class="col-sm-4">
                <p class="kitem-1">
                    <i class="fas fa-user-alt"></i>
                    <strong> ชื่อผู้จัดทำ:</strong>
                </p>
            </div>
            <div class="col-sm-8">
                <p class="kitem-1"><?php echo e($ad['author']); ?></p>
            </div>
            <div class="col-sm-4">
                <p class="kitem-1">
                    <i class="fas fa-building"></i>
                    <strong> หน่วยงาน:</strong>
                </p>
            </div>
            <div class="col-sm-8">
                <p class="kitem-1"><?php echo e($ad['organization']['name']); ?></p>
            </div>
            <div class="col-sm-4">
                <p class="kitem-1">
                    <i class="fas fa-calendar-alt"></i>
                    <strong> ปีที่จัดทำ:</strong>
                </p>
            </div>
            <div class="col-sm-8">
                <p class="kitem-1 year_format"><?php echo e($ad['year_of']); ?></p>
            </div>
            <div class="col-sm-4">
                <p class="kitem-1">
                    <i class="fas fa-folder-open"></i>
                    <strong> หมวดหมู่เนื้อหาความรู้:</strong>
                </p>
            </div>
            <div class="col-sm-8">
                <p class="kitem-1"><?php echo e($ad['type']['name']); ?></p>
            </div>
            <div class="col-sm-4">
                <p class="kitem-1">
                    <i class="fas fa-users"></i>
                    <strong> จำนวนผู้เข้าชม:</strong>
                </p>
            </div>
            <div class="col-sm-8">
                <p class="kitem-1"><?php echo e($ad['visitor_count']); ?></p>
            </div>
            <?php if( $ad['publish'] == 1): ?>
            <!-- Load Facebook SDK for JavaScript -->
            <div id="fb-root"></div>
            <script async defer crossorigin="anonymous"
                src="https://connect.facebook.net/th_TH/sdk.js#xfbml=1&version=v12.0" nonce="wAHgYi8N">
            </script>
            <!-- Your share button code -->
            <div class="fb-share-button" data-href="<?php echo e($url); ?>" data-layout="button" data-size="small">
                <a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo e($url); ?>&amp;src=sdkpreparse"
                    class="fb-xfbml-parse-ignore">
                    แชร์
                </a>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<div class="accordion" id="accordionGroup">
    <div class="accordion-item">
        <h2 class="accordion-header" id="headingTwo">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo"
                aria-expanded="true" aria-controls="collapseTwo">
                <h5>รายละเอียด</h5>
            </button>
        </h2>
        <div id="collapseTwo" class="accordion-collapse collapse show" aria-labelledby="headingTwo">
            <div class="accordion-body">
                <div class="row">
                    <?php if(isset($ad['detail'])): ?>
                    <div class="row">
                        <div class="col-12">
                            <p class="kitem-1"><?php echo e($ad['detail']); ?></p>
                        </div>
                    </div>
                    <?php else: ?>
                    <div class="row">
                        <div class="col-12">
                            <p class="kitem-1">ไม่พบข้อมูล</p>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headingThree">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree"
                aria-expanded="true" aria-controls="collapseThree">
                <h5>ภาพอินโฟกราฟิก</h5>
            </button>
        </h2>
        <div id="collapseThree" class="accordion-collapse collapse show" aria-labelledby="headingThree">
            <div class="accordion-body">
                <div class="row">
                    <div class="table-responsive">
                        <table id="listinfo" class="table" style="width: 100%">
                            <tbody>
                                <tr>
                                    <?php if(count($ad['file']) > 0): ?>
                                    <?php ($info = 0); ?>
                                    <?php $__currentLoopData = $ad['file']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $af): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($af['type'] == 1): ?>
                                    <?php ($info = $info + 1); ?>
                                    <td style="width: 20%; text-align: center; border-bottom-width: 0px">
                                        <div class="box">
                                            <div class="box-body">
                                                <img src="<?php echo e(asset('../storage/km/articles/'.$af['name'])); ?>"
                                                    class="margin content-cover opacity-img" title="View"
                                                    data-index="<?php echo e($af['name']); ?>" width="140px" height="210px" />
                                            </div>
                                            <div class="box-footer" style="text-align: center">
                                                <a data-index="<?php echo e($af['id']); ?>"
                                                    href="<?php echo e(asset('../storage/km/articles/'.$af['name'])); ?>" download
                                                    class="kitem-1 p-hover" title="Download">
                                                    <i class="fas fa-download "></i>
                                                    <span class="numLoadInfo<?php echo e($af['id']); ?>">
                                                        <?php echo e($af['download_count']); ?>

                                                    </span>
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                    <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($info == 0): ?>
                                    <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                    <?php elseif($info < 5): ?> <?php for($i=$info; $i < 5; $i++): ?> <td
                                        style="width: 20%; border-bottom-width: 0px">
                                        </td>
                                        <?php endfor; ?>
                                        <?php endif; ?>
                                        <?php else: ?>
                                        <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                            <p class="kitem-1">ไม่พบข้อมูล</p>
                                        </td>
                                        <?php endif; ?>
                                        <!-- <td style="width: 20%; text-align: center">
                                                <div class="box">
                                                    <div class="box-body">
                                                        <a href="">
                                                            <img src="image/cover/cover200x250.jpg"
                                                                class="margin content-cover" width="140px"
                                                                height="210px" />
                                                        </a>
                                                    </div>
                                                    <div class="box-footer" style="text-align: center">
                                                        <p><i class="fas fa-download "></i>000</p>
                                                    </div>
                                                </div>
                                            </td>
                                            <td style="width: 20%; text-align: center">
                                                <div class="box">
                                                    <div class="box-body">
                                                        <a href="">
                                                            <img src="image/cover/cover200x250.jpg"
                                                                class="margin content-cover" width="140px"
                                                                height="210px" />
                                                        </a>
                                                    </div>
                                                    <div class="box-footer" style="text-align: center">
                                                        <p><i class="fas fa-download "></i>000</p>
                                                    </div>
                                                </div>
                                            </td> -->
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headingFour">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseFour"
                aria-expanded="true" aria-controls="collapseFour">
                <h5>วีดีโอ</h5>
            </button>
        </h2>
        <div id="collapseFour" class="accordion-collapse collapse show" aria-labelledby="headingFour">
            <div class="accordion-body">
                <div class="row">
                    <div class="table-responsive">
                        <table id="listvideo" class="table" style="width: 100%">
                            <tbody>
                                <tr>
                                    <?php if(count($ad['file']) > 0): ?>
                                    <?php ($video = 0); ?>
                                    <?php $__currentLoopData = $ad['file']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $af): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($af['type'] == 2): ?>
                                    <?php ($video = $video + 1); ?>
                                    <td style="width: 20%; text-align: center; border-bottom-width: 0px">
                                        <div class="box">
                                            <div class="box-body">
                                                <iframe width="230" height="180" src="<?php echo e($af['name']); ?>"
                                                    title="YouTube video player" frameborder="0"
                                                    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                                                    allowfullscreen>
                                                </iframe>
                                            </div>
                                        </div>
                                    </td>
                                    <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    <?php if($video == 0): ?>
                                    <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                    <?php elseif($video < 3): ?> <?php for($i=$video; $i < 5; $i++): ?> <td
                                        style="width: 20%; border-bottom-width: 0px">
                                        </td>
                                        <?php endfor; ?>
                                        <?php endif; ?>
                                        <?php else: ?>
                                        <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                            <p class="kitem-1">ไม่พบข้อมูล</p>
                                        </td>
                                        <?php endif; ?>
                                        <!-- <td style="width: 20%; text-align: center">
                                                <div class="box">
                                                    <div class="box-body">
                                                        <iframe width="230" height="180"
                                                            src="https://www.youtube.com/embed/kdYi2n9IoeQ"
                                                            title="YouTube video player" frameborder="0"
                                                            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                                                            allowfullscreen>
                                                        </iframe>
                                                    </div>
                                                    <div class="box-footer" style="text-align: center">
                                                        <p>ชื่อวีดีโอ</p>
                                                    </div>
                                                </div>
                                            </td>
                                            <td style="width: 20%; text-align: center">
                                                <div class="box">
                                                    <div class="box-body">
                                                        <iframe width="230" height="180"
                                                            src="https://www.youtube.com/embed/kdYi2n9IoeQ"
                                                            title="YouTube video player" frameborder="0"
                                                            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                                                            allowfullscreen>
                                                        </iframe>
                                                    </div>
                                                    <div class="box-footer" style="text-align: center">
                                                        <p>ชื่อวีดีโอ</p>
                                                    </div>
                                                </div>
                                            </td> -->
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headingFive">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseFive"
                aria-expanded="true" aria-controls="collapseFive">
                <h5>ไฟล์เอกสาร</h5>
            </button>
        </h2>
        <div id="collapseFive" class="accordion-collapse collapse show" aria-labelledby="headingFive">
            <div class="accordion-body">
                <div class="row">
                    <div class="table-responsive">
                        <table id="listfile" class="table" style="width: 100%; cursor: pointer;">
                            <tbody>
                                <?php if(count($ad['file']) > 0): ?>
                                <?php ($doc = 0); ?>
                                <?php $__currentLoopData = $ad['file']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $af): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($af['type'] == 3): ?>
                                <?php ($doc = $doc + 1); ?>
                                <tr data-index="<?php echo e($af['name']); ?>" class="tr-hover" title="Download">
                                    <td style="width: 90%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1"><?php echo e($af['name']); ?></p>
                                    </td>
                                    <td style=" width: 10%; text-align: left; border-bottom-width: 0px">
                                        <a data-index="<?php echo e($af['id']); ?>"
                                            href="<?php echo e(asset('../storage/km/articles/'.$af['name'])); ?>" download
                                            class="kitem-1 p-hover" title="Download" hidden></a>
                                        <i class="fas fa-download kitem-1"></i>
                                        <span class="numLoadFile<?php echo e($af['id']); ?> kitem-1"><?php echo e($af['download_count']); ?></span>                                        
                                    </td>
                                </tr>
                                <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php if($doc == 0): ?>
                                <tr>
                                    <td style=" width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                                <?php else: ?>
                                <tr>
                                    <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headingSix">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseSix"
                aria-expanded="true" aria-controls="collapseSix">
                <h5>ลิงก์ความรู้</h5>
            </button>
        </h2>
        <div id="collapseSix" class="accordion-collapse collapse show" aria-labelledby="headingSix">
            <div class="accordion-body">
                <div class="row">
                    <div class="table-responsive">
                        <table id="listlink" class="table" style="width: 100%; cursor: pointer;">
                            <tbody>
                                <?php if(count($ad['file']) > 0): ?>
                                <?php ($doc = 0); ?>
                                <?php $__currentLoopData = $ad['file']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $af): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($af['type'] == 4): ?>
                                <?php ($doc = $doc + 1); ?>
                                <tr class="tr-hover">
                                    <td style="width: 100%; text-align: left; border-bottom-width: 0px;">
                                        <p class="kitem-1">
                                            <a href="<?php echo e($af['name']); ?>" target="_blank" style="color: #1aa6b7;">
                                                <?php echo e($af['name']); ?>

                                            </a>                                            
                                        </p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php if($doc == 0): ?>
                                <tr>
                                    <td style=" width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                                <?php else: ?>
                                <tr>
                                    <td style="width: 100%; text-align: left; border-bottom-width: 0px">
                                        <p class="kitem-1">ไม่พบข้อมูล</p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php else: ?>
<p>ไม่พบข้อมูล</p>
<?php endif; ?>

<script>
$('.taghilight').click(function() {
    var tag = $(this).text().trim();
    // console.log(tag)
    $("#texKey").val(tag);
    $("#selectkey").val("tag");
    $('input[type=checkbox]').prop('checked', false);
    $("#btn-search").click();
});

$('.year_format').each(function(d) {
    $(this).html(moment($(this).html()).add(543, 'years').locale('th').format('YYYY'));
});

$('.back').on('click', function() {
    // console.log('back');
    // id_topic = $(".list-group .active").attr("data-index");
    // urlApi = "";
    // if (id_topic == null) {
    //     id_topic = $(".navbar-nav .active a").attr("data-index");
    // }
    // listHistory(id_topic, urlApi);
    window.history.back();
    return false;
});

// $('#listfile .tr-hover').on('click', function(e) {
//     namefile = $(this).attr("data-index");
//     // e.preventDefault();
//     // window.location.href = '../storage/km/articles/' + namefile;
//     var FilePath = '../storage/km/articles/' + namefile;
//     window.open(FilePath, '_blank');
// });

$('.opacity-img').on('click', function(e) {
    namefile = $(this).attr("data-index");
    // e.preventDefault();
    // window.location.href = '../storage/km/articles/' + namefile;
    var FilePath = '../../storage/km/articles/' + namefile;
    window.open(FilePath, '_blank');
    return false;
});

// $('.p-hover').on('click', function(e) {
//     idfile = $(this).attr("data-index");
//     console.log(idfile);
//     $.ajax({
//         type: "post",
//         url: 'best/listArticle',
//         data: form_data,
//         headers: {
//             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
//         },
//         processData: false,
//         contentType: false,
//         cache: false,
//         success: function(html) {
//             $('#blade').html(html);
//         }
//     });
// });

// $('.opacity-img').on('click', function(e) {
//     namefile = $(this).attr("data-index");
//     download(namefile, "Download file.");
//     return false;
// });

function download(filename, text) {
    var element = document.createElement('a');
    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    element.setAttribute('download', filename);

    element.style.display = 'none';
    document.body.appendChild(element);

    element.click();

    document.body.removeChild(element);
}

$("#listfile tbody tr").on("click", function(event) {
    // alert("listfile tbody tr");
    var link_url = $(this).find("td").find("a").attr('href');
    var id_url = $(this).find("td").find("a").attr('data-index');

    var link = document.createElement("a");
    link.setAttribute('download', name);
    link.href = link_url;
    document.body.appendChild(link);
    link.click();
    link.remove();

    $.ajax({
        type: "get",
        url: '../helper/countDownload/' + id_url,
        dataType: 'json',
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        success: function(result) {
            // console.log(result);
            if (result.status == true) {
                $(".numLoadFile" + id_url).text(result.data);
            }
        }
    });
});

$('#listinfo tr td a').click(function() {
    // alert("The paragraph was clicked.");
    $id = $(this).data('index');
    console.log($id);
    $.ajax({
        type: "get",
        url: '../helper/countDownload/' + $id,
        dataType: 'json',
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        success: function(result) {
            console.log(result);
            if (result.status == true) {
                $(".numLoadInfo" + $id).text(result.data);
            }
        }
    });
});
</script><?php /**PATH /var/www/html/km-web/resources/views/subpage/detailArticle.blade.php ENDPATH**/ ?>