<?php

use Cake\Utility\Text;

$bid = (count($project->bids) > 0) ? true : false;

$description =  $this->get('description');
?>

<!-- :: Edit popup -->
<div class="modal fade modelEdit" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel1" aria-hidden="true">
    <div class="modal-dialog modal-lg" style="max-width: 1400px;width: 80%;height:80%">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Project Edit</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <?php echo $this->element('Projects/edit'); ?>

            </div>
        </div>
    </div>
</div>


<div class="row">
    <?php if ($bid == 0) { ?>
        <div class='col-xl-8 col-lg-8 col-md-12 task-detail-left' style="max-height:510px">
            <div class='card'>
                <?php echo $description; ?>
            </div>
        </div>
    <?php } else { ?>
        <div class="col-xl-8 col-lg-8 col-md-12 task-detail-right" style="max-height:510px">
            <div class="card">
                <?= $bidHtml ?>

                <!-- <?php if (!isset($project['freelancer']) && empty($project['freelancer']) && !empty($project->bids)) { ?>
                    <div class="card-body table-border-style">
                        <div class="table-responsive dataTables_wrapper dt-bootstrap4" style="overflow: hidden;">
                            <div class="row">
                                <div class="col-sm-6">
                                    <h4><?= __('Placed Bids') ?></h4>
                                </div>
                                <div class="col-sm-6">
                                    <div class="pull-right">
                                        <div id="colum-rendr_filter" class="dataTables_filter">
                                            <label><input type="search" id="myInput" placeholder='Search by freelancer' name="freelancers" onkeyup="myFunction()" class="form-control" aria-controls="bids"></label>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <table cellpadding="0" cellspacing="0" class="table" id="myTable">
                                <thead>
                                    <th scope="col"><?= __('Id') ?></th>
                                    <th scope="col"><?= __('Freelancer') ?></th>
                                    <th scope="col"><?= __('Proposal') ?></th>
                                    <th scope="col"><?= __('Proposal Completion Date') ?></th>
                                    <th scope="col" class="actions"><?= __('Actions') ?></th>
                                </thead>
                                <?php $count = 1;
                                foreach ($project->bids as $bids) :
                                ?>
                                    <tr>
                                        <td><?= $count++ ?></td>
                                        <td><?= $this->Html->link($bids->freelancer->name, ['controller' => 'freelancers', 'action' => 'view', $bids->freelancer_id], ['target' => '_blank'], ['controller' => 'freelancers', 'action' => 'view', $bids->freelancer_id]); ?>
                                        </td>
                                        <td><?= $bids->proposal ?></td>
                                        <td><?= date('d-M-Y', strtotime($bids->proposal_date)) ?></td>
                                        <td class="actions">

                                            <?= $this->Html->link($this->Html->tag('i', '', array('class' => "fas fa-eye btn btn-success", 'title' => 'Bid details', 'traget' => '_blank')), array(), array('class' => 'bid-info', 'escape' => false, 'data-id' => "$bids->id", 'onclick' => "bidDetail($bids->id)", 'target' => '_blank', 'data-toggle' => 'modal', 'data-target' => '.BidInfo'))
                                            ?>

                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </table>
                        </div>
                    </div>
                <?php }  ?> -->

            </div>

        </div>
    <?php } ?>

    <div class="col-xl-4 col-lg-4 col-md-8 task-detail-left" style="max-height:510px">
        <!-- <div class="card">
                    <div class="card-body bg-c-blue">
                        <div class="counter text-center">
                            <h4 id="timer" class="text-white m-0"></h4>
                        </div>
                    </div>
                </div> -->

        <div id="accordion">
            <div class="card">
                <div id="collapseOne" class="collapse show" data-parent="#accordion">
                    <div class="user-card1 overflow-auto" style="max-height:510px">
                        <div class="card-header mb-3">
                            <h4 class="float-left as_task">Project Details</h4>
                            <a href="" class="btn btn-dark pull-right modelEdit" data-toggle="modal" data-target=".modelEdit"><i class="feather icon-edit"></i></a>
                        </div>
                        <div class="mr-4 ml-4 task-details">
                            <table class="table">
                                <tbody>
                                    <tr>
                                        <td><i class="fa fa-book-open m-r-5"></i> Title : </td>
                                        <td class="text-right"><?= ($project->topic); ?></td>
                                    </tr>
                                    <?php if ($bid) : ?>
                                        <tr>
                                            <td><i class="fa fa-book-reader m-r-5"></i> Description : </td>
                                            <td class="text-right p-1 <?= ($bid) ? 'w-50' : ''; ?>"><?= (strlen($project->description) > 50) ? strip_tags(substr($project->description, 0, ($bid) ? 50 : 250)) . '...<a href="" data-toggle="modal" data-target=".bd-example-modal-lg">views more </a>' : ($project->description); ?></td>
                                        </tr>

                                        <tr>
                                            <td><i class="fa fa-book-dead m-r-5"></i> category : </td>
                                            <td class="text-right"><?= (!empty($project->category_id)) ? $this->Custom->getCategoryName($project->category_id) : '-' ?></td>
                                        </tr>
                                        <?php if ($project->category_id != 2) :  ?>
                                            <tr>
                                                <td><i class="fa fa-book-dead m-r-5"></i> type : </td>
                                                <td class="text-right"><?= !empty($project->service) ? $project->service : '-'; ?></td>
                                            </tr>
                                            <tr>
                                                <td><i class="fa fa-stripe m-r-5"></i> Subject : </td>
                                                <td class="text-right"><?= !empty($project->subject) ? $this->Custom->getSubjectName($project->subject) : ' - '; ?></td>
                                            </tr>
                                        <?php endif; ?>
                                        <tr>
                                            <td><i class="fa fa-bookmark m-r-5"></i> Page/Word : </td>
                                            <td class="text-right <?= ($bid) ? 'w-50' : ''; ?>"><?= !empty($project->pages . '/' . $project->words) ? $project->pages . '/' . $project->words : '-' ?></td>
                                        </tr>
                                        <tr>
                                            <td><i class="fa fa-dollar-sign m-r-5"></i> Amount : </td>
                                            <td class="text-right"><?= $project->price ?></td>
                                        </tr>
                                    <?php endif; ?>
                                    <tr>
                                        <td><i class="far fa-calendar m-r-5"></i> Deadline : </td>
                                        <td class="text-right"><?= date('d M, Y', strtotime($project->deadline_date)); ?></td>
                                    </tr>
                                    <tr>
                                        <td><i class="far fa-calendar-alt m-r-5"></i> Bid Expire : </td>
                                        <td class="text-right"><?= date('d M, Y', strtotime($project->bid_expiry_date)); ?></td>
                                    </tr>
                                    <!-- <tr>
                                        <td><i class="far fa-credit-card m-r-5"></i> Created : </td>
                                        <td class="text-right"><?= date('d M, Y', strtotime($project->created)); ?></td>
                                    </tr> -->
                                    <?php if ($project->website != '') { ?>
                                        <tr>
                                            <td id="website"><i class="fas fa-chart-line m-r-5"></i> Website : </td>
                                            <td class="text-right">
                                                <?= h($project->website) ?>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <tr>
                                        <td><i class="fas fa-thermometer-half m-r-5"></i> Status:</td>
                                        <td class="text-right" id="status"><?= @$project->status ?></td>
                                        </tu>
                                </tbody>
                            </table>
                        </div>
                        <?php
                        if (trim($project->file_data) != '') {
                            $fileArr = explode('?|@$', $project->file_data);
                        ?>
                            <div class="card-header " style="padding: 10px 25px 8px 27px !important;">
                                <h6>Attchment Files</h6>
                            </div>
                            <div class="card-body task-attachment">
                                <ul class="media-list p-0">
                                    <?php foreach ($fileArr as $k => $file) { ?>
                                        <li class="media d-flex m-b-15">
                                            <div class="m-r-20 file-attach">
                                                <i class="far fa-file f-28 text-muted"></i>
                                            </div>
                                            <div class="media-body">
                                                <a href="#!" class="m-b-5 d-block text-secondary"><?= $file ?></a>
                                            </div>

                                            <div class="float-right text-muted">
                                                <a target="_blank" download="<?= $file ?>" href="<?= $s3url . '../' . $file ?>"><i class="fas fa-download f-18"></i></a>
                                            </div>
                                        </li>
                                    <?php } ?>
                                </ul>
                            </div>
                        <?php } ?>



                    </div>

                </div>
            </div>
        </div>

    </div>

</div>


<!-- :: Float Notification -->

<script>
    $('.pcoded-navbar').addClass('navbar-collapsed');
    $('#project-edit').submit(function(e) {
        // alert('submit');
        $('.project-email').html('<div class="spinner-border loader spinner-border-sm" role="status"></div> Submit & Close')
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: '<?= $this->Url->build(["controller" => "Projects", "action" => "edit/$project->id"]) ?>',
            data: new FormData(this),
            processData: false,
            contentType: false,
            cache: false,
            timeout: 600000,
            success: function(res) {
                $('.loader').remove();
                location.reload();
            },
        });


    });
</script>