<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<?php if ($error = session('error')): echo $viewDatas['service']->getHelper()->alert($error) ?><?php endif ?>
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
<!-- Layout Middle Start -->
<table class="layout_middle">
  <tr>
    <td class="layout_left">
      <!-- Layout Left Start -->
      <?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
      <!-- Layout Left End -->
    </td>
    <td class="layout_right">
      <!-- Layout Right Start -->
      <div class="layout_header"><?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?></div>
      <div id="container" class="layout_content">
        <link href="/css/<?= $viewDatas['layout'] ?>/index.css" media="screen" rel="stylesheet" type="text/css" />
        <div class="index_body">
          <table class="index_table data table table-bordered table-hover table-striped" data-rtc-resizable-table="reisze_table">
            <thead>
              <tr>
                <th class="index_head_short_column" style="width:40px;">번호</th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('site', lang("{$viewDatas['class_path']}.label.site"), $viewDatas) ?>
                  / <?= $viewDatas['service']->getHelper()->getListLabel('location', lang("{$viewDatas['class_path']}.label.location"), $viewDatas) ?>
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('clientinfo_uid', lang("{$viewDatas['class_path']}.label.clientinfo_uid"), $viewDatas) ?>
                </th>
                <th class="index_head_short_column" style="width:650px;">
                  <span class="float-start rounded border border-primary" style="cursor:pointer;" onclick="copyServerPartsToClipboard()">ALL 📋</span>서버정보
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('amount', lang("{$viewDatas['class_path']}.label.sale"), $viewDatas) ?>
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('amount', lang("{$viewDatas['class_path']}.label.amount"), $viewDatas) ?>
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('billing_at', lang("{$viewDatas['class_path']}.label.billing_at"), $viewDatas) ?> / 미지급
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('status', lang("{$viewDatas['class_path']}.label.status"), $viewDatas) ?>
                </th>
                <th class="index_head_short_column">
                  <?= $viewDatas['service']->getHelper()->getListLabel('start_at', lang("{$viewDatas['class_path']}.label.start_at"), $viewDatas) ?>
                </th>
            </thead>
            <tbody>
              <?php $cnt = 0 ?>
              <?php foreach ($viewDatas['entities'] as $entity): ?>
                <?php $viewDatas['entity'] = $entity; ?>
                <tr <?= $entity->getStatus() === $entity::DEFAULT_STATUS ? "" : 'class="table-danger"' ?>>
                  <?php $num = $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt); ?>
                  <td nowrap class="text-center"><?= $num ?></td>
                  <td nowrap>
                    <?= $viewDatas['service']->getHelper()->getFieldView('site', $entity->site, $viewDatas) ?>
                    / <?= $viewDatas['service']->getHelper()->getFieldView('location', $entity->getLocation(), $viewDatas) ?>
                  </td>
                  <td nowrap>
                    <?= $viewDatas['service']->getHelper()->getFieldView('clientinfo_uid', $entity->getClientInfoUID(), $viewDatas) ?>
                  </td>
                  <td nowrap>
                    <?php foreach ($viewDatas['childServers'][$entity->getPK()] as $serverEntity): ?>
                      <?= view_cell("\App\Cells\Equipment\ServerPartCell::parttable", [
                        'serverinfo_uid' => $serverEntity->getPK(),
                        'types' => SERVERPART['SERVICE_PARTTYPES'],
                        'template' => 'partlist_service'
                      ]) ?>
                    <?php endforeach ?>
                  </td>
                  <td nowrap class=" text-end">
                    <?= $viewDatas['service']->getHelper()->getFieldView('sale', $entity->getSale(), $viewDatas) ?>
                  </td>
                  <td nowrap class="text-end">
                    <?= $viewDatas['service']->getHelper()->getFieldView('amount', $entity->getAmount(), $viewDatas) ?>
                  </td>
                  <td nowrap>
                    <?= $viewDatas['service']->getHelper()->getFieldView('billing_at', $entity->getBillingAt(), $viewDatas) ?>
                  </td>
                  <td nowrap>
                    <?= $viewDatas['service']->getHelper()->getFieldView('status', $entity->getStatus(), $viewDatas) ?>
                  </td>
                  <td nowrap><?= $viewDatas['service']->getHelper()->getFieldView('start_at', $entity->getStartAt(), $viewDatas) ?></td>
                </tr>
                <?php $cnt++ ?>
              <?php endforeach ?>
            </tbody>
          </table>
        </div>
      </div>
      <div class=" layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
    </td>
  </tr>
</table>
<div class="layout_bottom"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?></div>
<script src="/js/admin/clipboard.js"></script>
<?= $this->endSection() ?>