<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<link href="/css/<?= $viewDatas['layout'] ?>/index.css" media="screen" rel="stylesheet" type="text/css" />
<style>
  textarea.note-box {
    width: 100%;
    min-height: 150px;
    height: 100%;
    /* 부모의 높이를 꽉 채움 */
    resize: none;
    box-sizing: border-box;
  }
</style>
<?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">
        <div class="index_body p-4">
          <!-- index_body -->
          <div class="row align-items-end rounded border border-gray p-2 mt-3">
            <table class="table table-bordered table-hover table-striped m-0 p-0">
              <tr class="text-center">
                <th rowspan="2">
                  <div> <?= $viewDatas['entity']->getTitle() ?></div>
                  <div>
                    <?=
                    form_label(
                      "[청구서발행]",
                      'payment_invoice',
                      [
                        "data-src" => "/admin/customer/payment?clientinfo_uid=" . $viewDatas['entity']->getPK() . "&ActionTemplate=popup",
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#modal_action_form",
                        "class" => "text-primary form-label-sm",
                      ]
                    );
                    ?>
                  </div>
                  <div class="mt-3">
                    <?=
                    form_label(
                      '서비스추가',
                      'create_service',
                      [
                        "data-src" => '/admin/customer/service/create?clientinfo_uid=' . $viewDatas['entity']->getPK(),
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#modal_action_form",
                        "class" => "btn btn-sm btn-primary form-label-sm",
                      ]
                    );
                    ?>
                  </div>
                </th>
                <th>도코</th>
                <th>치바</th>
                <th>VPN</th>
                <th>일반</th>
                <th>방어</th>
                <th>전용</th>
                <th>이벤트</th>
                <th>테스트</th>
                <th>대체</th>
                <th>쿠폰</th>
                <th>예치금</th>
                <th>포인트</th>
                <th>전체요금</th>
                <th>전체미납금</th>
              </tr>
              <tr class="text-center">
                <td><?= $viewDatas['totalCounts']['tokyo_summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['chiba_summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['vpn']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['normal']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['defence']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['dedicated']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['event']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['test']['summary'] ?></td>
                <td><?= $viewDatas['totalCounts']['alternative']['summary'] ?></td>
                <td><?= $viewDatas['service']->getHelper()->getListButton("coupon", $viewDatas['entity']->getCouponBalance(), $viewDatas) ?></td>
                <td><?= $viewDatas['service']->getHelper()->getListButton("account", number_format($viewDatas['entity']->getAccountBalance()) . "원", $viewDatas) ?></td>
                <td><?= $viewDatas['service']->getHelper()->getListButton("point", number_format($viewDatas['entity']->getPointBalance()), $viewDatas) ?></td>
                <td><?= array_key_exists($viewDatas['entity']->getPK(), $viewDatas['totalAmounts']) ? number_format($viewDatas['totalAmounts'][$viewDatas['entity']->getPK()]) : 0 ?>원</td>
                <td>
                  <?php if (array_key_exists($viewDatas['entity']->getPK(), $viewDatas['unPaids'])): ?>
                    <?=
                    form_label(
                      sprintf("총:%s건/%s원", $viewDatas['unPaids'][$viewDatas['entity']->getPK()]['cnt'], number_format($viewDatas['unPaids'][$viewDatas['entity']->getPK()]['amount'])),
                      'payment_unpaid',
                      [
                        "data-src"       => "/admin/customer/payment?clientinfo_uid={$viewDatas['entity']->getPK()}&status=unpaid&ActionTemplate=popup",
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#modal_action_form",
                        "class" => "text-primary form-label-sm",
                      ]
                    );
                    ?>
                  <?php endif ?>
                </td>
              </tr>
            </table>
          </div>
          <?= form_open("/admin/customer/client/history/{$viewDatas['entity']->getPK()}?return_url=" . urlencode(current_url()), ['method' => "post"]) ?>
          <div class="row align-items-center rounded border border-gray p-2 mt-3">
            <div class="col-1">
              <div class="text-center fw-bold">고객 비고</div>
            </div>
            <div class="col-10">
              <textarea name="history" class="form-control note-box"><?= $viewDatas['entity']->getHistory() ?></textarea>
            </div>
            <div class="col-1">
              <?= form_submit('', '저장', array("class" => "btn btn-outline btn-primary")); ?>
            </div>
          </div>
          <?= form_close() ?>
          <?= view_cell("\App\Cells\Customer\ServiceCell::detail", ['clientinfo_uid' => $viewDatas['entity']->getPK()]) ?>
          <?= view_cell("\App\Cells\Customer\PaymentCell::detail", ['clientinfo_uid' => $viewDatas['entity']->getPK()]) ?>
        </div>
        <!-- index_body -->
      </div>
      <div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
      <!-- Layout Right End -->
    </td>
  </tr>
</table>
<!-- Layout Middle End -->
<div class="layout_bottom"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?></div>
<?= $this->endSection() ?>