<?php
$usr_level = session('usr_level');

?>
<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<style>
  table th {
    vertical-align: middle;
    line-height: 1.2;
  }

  .tbl_basic2 th {
    padding: 0 10px;
    height: 27px;
    line-height: 27px;
    vertical-align: middle;
    border: solid 1px #d8d9de;
    background-color: #eff0f4;
    letter-spacing: -1px;
    font-weight: normal;
    color: #5a5f69;
    text-align: left;
  }

  .num {
    font-family: Tahoma;
    color: #b68556;
    font-size: 17px;
  }

  .table-scroll {
    max-height: 300px;
    overflow-y: scroll;
  }
</style>

<div class="app-page-title">
  <div class="page-title-wrapper">
    <div class="page-title-heading">
      <div>현장확인매물 상세 내용</div>
    </div>
  </div>
</div>

<div class="col-md-12 col-xl-12">
  <div class="col-lg-12">

    <div class="main-card mb-3 card">
      <div class="card-header" style="width:100%; max-width:100%; min-width:600px; padding:0; border:0;">
        <table style="width:100%; min-width:600px; padding:0; border:0;" cellpadding="0" cellspacing="0" border="0">
          <tbody>
            <tr>
              <td style="width: 50%; padding-left: 20px">
                <span class="tit">매물ID :</span>
                <span class="num"><?= esc($data['rcpt_atclno'] ?? '') ?></span>
              </td>
              <td style="text-align: right; padding-right: 20px;">
                <span class="tit">CP ID :</span>
                <span class="num"><?= esc($data['rcpt_cpid'] ?? '') ?></span>
              </td>
            </tr>
            <tr>
              <td height="15"></td>
              <td></td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="card-body">
        <h5 class="card-title">공인 중개사 정보</h5>

        <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
          <colgroup>
            <col width="15%" />
            <col width="35%" />
            <col width="15%" />
            <col width="35%" />
          </colgroup>
          <tbody>
            <tr>
              <th>중개사ID</th>
              <td><?= esc($data['agent_id'] ?? '') ?></td>
              <th>중개사명</th>
              <td><?= esc($data['agent_nm'] ?? '') ?></td>
            </tr>
            <tr>
              <th>대표전화</th>
              <td><?= esc($data['agent_head_tel'] ?? '') ?></td>
              <th>담당자전화</th>
              <td><?= esc($data['agent_contact_tel'] ?? '') ?></td>
            </tr>
            <tr>
              <th>검증방식</th>
              <td>
                <?= (($data['isSiteVRVerification'] ?? '') === 'Y')
                  ? "<span style='color:red;'>현장V2</span>"
                  : "현장"; ?>
              </td>
              <th>연락가능전화</th>
              <td>
                <?php $agent_tel = str_replace("-", "", $data['agent_tel'] ?? ''); ?>
                <div class="d-flex align-items-center gap-2">
                  <input type="text" id="agent_tel" name="agent_tel" class="form-control form-control-sm" maxlength="16"
                    value="<?= esc($agent_tel) ?>" style="max-width: 220px;" />
                  <button type="button" class="btn btn-sm btn-outline-light" onclick="fn_save_tel();">저장</button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>

      </div>
    </div>

    <!-- 매물정보 -->
    <form id="rcptFrm" enctype="multipart/form-data" onsubmit="return false;">
      <input type="hidden" name="rcpt_sq" value="<?= $data['rcpt_sq'] ?>" />
      <input type="hidden" name="rsrv_sq" value="<?= $data['rsrv_sq'] ?>" />
      <input type="hidden" name="rcpt_atclno" value="<?= $data['rcpt_atclno'] ?>" />
      <input type="hidden" name="rcpt_key" value="<?= $data['rcpt_key'] ?>" />
      <input type="hidden" name="rcpt_product" id="rcpt_product" value="<?= $data['rcpt_product'] ?>" />
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">매물 정보</h5>

          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <colgroup>
              <col width="15%" />
              <col width="35%" />
              <col width="15%" />
              <col width="35%" />
            </colgroup>
            <tbody>
              <tr>
                <th>등록일</th>
                <td>
                  <?= $data['insert_tm'] ?>
                </td>
                <th>예약(촬영)요청일</th>
                <td>
                  <?= $data['rsrv_date'] ?>
                  <?= $data['rsrv_tm_ap'] ?>
                  <?= $data['rsrv_tm_hour'] ?>
                </td>
              </tr>
              <tr>
                <th>현장확인(촬영)일자</th>
                <td>
                  <?= $data['photo_save_dt'] ?>
                </td>
                <th>가주소 여부</th>
                <td>
                  <?php if ($data['virAddr_yn'] == 'Y') { ?><span style="font-weight: bold;color: red;">가주소</span>
                  <?php } else {
                    echo $data['virAddr_yn'];
                  } ?>
                </td>
              </tr>
              <tr>
                <th>매물구분</th>
                <td><?= $data['rcpt_product_nm'] ?></td>
                <th>거래구분</th>
                <td>
                  <select class="form-select" id="trade_type" onchange="trade_type_onchange();" disabled>
                    <option value="">거래구분</option>
                    <?php foreach ($codes as $c): ?>
                      <?php if ($c['category'] === "TRADE_TYPE"): ?>
                        <option value="<?= $c['cd'] ?>" <?php if ($c['cd'] === $data['trade_type']) {
                            echo "selected";
                          } ?>>
                          <?= $c['cd_nm'] ?>
                        </option>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
                </td>
              </tr>
              <tr>
                <th rowspan="3">지역구분</th>
                <td rowspan="3">
                  <?= $data['addr'] ?>
                </td>
                <th>리 주소</th>
                <td>
                  <input type="hidden" class="form-control" name="rcpt_dtl_addr" id="rcpt_dtl_addr"
                    value="<?= $data['rcpt_dtl_addr'] ?>" size="50" disabled="disabled" />
                  <input type="text" class="form-control" name="rcpt_dtl_addr1" id="rcpt_dtl_addr1"
                    value="<?= $data['rcpt_li_addr'] ?>" size="50" disabled="disabled" /><br />
                </td>
              </tr>
              <tr>
                <th>상세주소</th>
                <td class="d-flex gap-1">
                  <?php if (empty($data['rcpt_jibun_addr'])) { ?>
                    <input type="hidden" class="form-control" name="rcpt_dtl_addr2a" id="rcpt_dtl_addr2a"
                      value="<?= $data['rcpt_jibun_addr'] ?>" size="50" disabled="disabled" />
                    <input type="hidden" class="form-control" name="rcpt_dtl_addr2b" id="rcpt_dtl_addr2b"
                      value="<?= $data['rcpt_etc_addr'] ?>" size="50" disabled="disabled" />
                    <input type="text" class="form-control" name="rcpt_dtl_addr2" id="rcpt_dtl_addr2"
                      value="<?= $data['rcpt_dtl_addr'] ?>" size="50" disabled="disabled" /><br />
                    <input type="text" class="form-control" name="rcpt_dtl_addr3" id="rcpt_dtl_addr3"
                      value="<?= $data['rcpt_ho'] ?>" size="50" disabled="disabled" />
                    <input type="hidden" class="form-control" name="rcpt_ho" id="rcpt_ho" value="<?= $data['rcpt_ho'] ?>"
                      size="50" disabled="disabled" />
                  <?php } else { ?>
                    <input type="hidden" class="form-control" name="rcpt_dtl_addr2" id="rcpt_dtl_addr2"
                      value="<?= $data['rcpt_dtl_addr'] ?>" size="50" disabled="disabled" />
                    <input type="hidden" class="form-control" name="rcpt_dtl_addr3" id="rcpt_dtl_addr3"
                      value="<?= $data['rcpt_ho'] ?>" size="50" disabled="disabled" />
                    <input type="text" class="form-control" name="rcpt_dtl_addr2a" id="rcpt_dtl_addr2a"
                      value="<?= $data['rcpt_jibun_addr'] ?>" size="50" disabled="disabled" /><br />
                    <input type="text" class="form-control" name="rcpt_dtl_addr2b" id="rcpt_dtl_addr2b"
                      value="<?= $data['rcpt_etc_addr'] ?>" size="50" disabled="disabled" />
                    <input type="hidden" class="form-control" name="rcpt_ho" id="rcpt_ho" value="<?= $data['rcpt_ho'] ?>"
                      size="50" disabled="disabled" />
                  <?php } ?>
                </td>
              </tr>
              <tr>
                <th>기타주소</th>
                <td>
                  <input type="text" class="form-control" name="rcpt_ref_addr" id="rcpt_ref_addr"
                    value="<?= $data['rcpt_ref_addr'] ?>" size="50" disabled="disabled" />
                </td>
              </tr>
              <tr>
                <th>단지명</th>
                <td></td>
                <th>가격</th>
                <td>
                  <?php
                  // 숫자 콤마 제거(표시용)
                  $v2 = str_replace(',', '', $data['rcpt_product_info2'] ?? '');
                  $v3 = str_replace(',', '', $data['rcpt_product_info3'] ?? '');
                  $v4 = str_replace(',', '', $data['rcpt_product_info4'] ?? '');
                  $v5 = str_replace(',', '', $data['rcpt_product_info5'] ?? '');

                  // 분양가/프리미엄 노출 조건
                  $chk_array = ['B01', 'B02', 'B03'];
                  $show_sale_premium = (in_array(($data['rcpt_product'] ?? ''), $chk_array) || ($data['trade_type'] ?? '') === 'A1');

                  ?>

                  <!-- 보증금/금액 -->
                  <div class="d-flex flex-column gap-1">
                    <div class="d-flex align-items-center gap-1 flex-wrap">
                      <input type="text" class="form-control form-control-sm" name="rcpt_product_info2"
                        id="rcpt_product_info2" value="<?= esc($v2) ?>" style="width: 110px;" disabled />
                      <span class="small text-nowrap">만원</span>
                    </div>

                    <!-- 월세(월) -->
                    <div id="div_trade_type_price_monthly">
                      <div class="d-flex align-items-center gap-1 flex-wrap">
                        <input type="text" class="form-control form-control-sm" name="rcpt_product_info3"
                          id="rcpt_product_info3" value="<?= esc($v3) ?>" style="width: 110px;" disabled />
                        <span class="small text-nowrap">만원 (월)</span>
                      </div>
                    </div>

                    <!-- 분양가 / 프리미엄 -->
                    <?php if ($show_sale_premium): ?>
                      <div class="d-flex align-items-center gap-2 flex-wrap mt-1">
                        <span class="small text-nowrap">분양가</span>
                        <input type="text" class="form-control form-control-sm" name="rcpt_product_info4"
                          id="rcpt_product_info4" value="<?= esc($v4) ?>" style="width: 110px;" disabled />
                        <span class="small text-nowrap">만원</span>

                        <span class="small text-muted">/</span>

                        <span class="small text-nowrap">프리미엄</span>
                        <input type="text" class="form-control form-control-sm" name="rcpt_product_info5"
                          id="rcpt_product_info5" value="<?= esc($v5) ?>" style="width: 110px;" disabled />
                        <span class="small text-nowrap">만원</span>
                      </div>
                    <?php endif; ?>

                    <!-- 버튼 -->
                    <div class="d-flex align-items-center justify-content-end gap-1 mt-2">
                      <button type="button" class="btn btn-sm btn-outline-light btn-edit"
                        onclick="editPriceInfo();">수정</button>
                      <button type="button" class="btn btn-sm btn-outline-success btn-save"
                        onclick="modifyPriceInfo();">가격수정</button>
                    </div>
                  </div>
                </td>
              </tr>

              <tr>
                <th>평형</th>
                <td></td>
                <?php
                $chk_product_nm = [
                  'C04',				// 전원주택
                  'D03',				// 빌딩,건물
                  'D04',				// 상가,건물
                  'E01',				// 숙박,콘도
                  'E02',				// 공장,창고
                  'Z00'				// 기타		
                ];

                if (in_array($data['rcpt_product'], array('C03', 'C05', 'C06')) && $data['rcpt_product_info1'] == '매매') {
                  echo ("<th>지하층 / 지상층</th>");
                } else if (in_array($data['rcpt_product'], $chk_product_nm)) {
                  echo ("<th>지하층 / 지상층</th>");
                } else {
                  echo ("<th>층 / 총층</th>");
                }
                ?>
                <td class="d-flex gap-1">
                  <input type="text" class="form-control" name="rcpt_floor" id="rcpt_floor"
                    value="<?= $data['rcpt_floor'] ?>" size="8" maxlength="3" disabled="disabled"
                    style="width: 100px;" />
                  <input type="text" class="form-control" name="rcpt_floor2" id="rcpt_floor2"
                    value="<?= $data['rcpt_floor2'] ?>" size="8" maxlength="3" disabled="disabled"
                    style="width: 100px;" />
                </td>
              </tr>
              <tr class="spc">
                <th></th>
                <td></td>
                <th>면적확인파일1</th>
                <td>
                  <?php
                  $arrI6 = [];
                  $arrI7 = [];
                  foreach ($images as $key => $img) {
                    switch ($img['img_type']) {
                      case "I6":
                        $arrI6[] = $img;
                        unset($images[$key]);
                        break;

                      case "I7":
                        $arrI7[] = $img;
                        unset($images[$key]);
                        break;
                    }
                  }

                  if (!empty($arrI6)) { ?>
                    <?php foreach ($arrI6 as $img) {
                      $sq = $img['img_sq'];

                      $link = $img['img_path'] . $img['img_filenm'];
                      $temp2 = explode(".", $img['img_filenm']);
                      //$name = $temp2[0]."_thumb.".$temp2[1];
                      $name = $temp2[0] . "_thumb.jpg";
                      $thumblink = $img['img_path'] . $name;

                      if ($img['cloud_upload_yn'] == 'Y') {
                        $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                        $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                      }

                      ?>
                      <div id="img_file_dis_I6" style="padding: 6px 0;">
                        <a onclick="fn_preview('<?= $link ?>')">
                          <img id="photo-display2_I6" src="<?= $thumblink ?>" alt="Image" class="lazy" />
                        </a>
                      </div>
                    <?php } ?>
                  <?php } else { ?>
                    <div id="img_file_dis_I6" style="padding: 10px 0;">
                      <img id="photo-display2_I6" src="/plugin/img/photo.gif" alt="No Image" />
                    </div>
                  <?php } ?>
                </td>
              </tr>
              <tr class="spc">
                <th>방</th>
                <td></td>
                <th>면적확인파일2</th>
                <td>
                  <?php if (!empty($arrI7)) { ?>
                    <?php foreach ($arrI7 as $img) {
                      $sq = $img['img_sq'];

                      $link = $img['img_path'] . $img['img_filenm'];
                      $temp2 = explode(".", $img['img_filenm']);
                      //$name = $temp2[0]."_thumb.".$temp2[1];
                      $name = $temp2[0] . "_thumb.jpg";
                      $thumblink = $img['img_path'] . $name;

                      if ($img['cloud_upload_yn'] == 'Y') {
                        $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                        $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                      }

                      ?>
                      <div id="img_file_dis_I6" style="padding: 6px 0;">
                        <a onclick="fn_preview('<?= $link ?>')">
                          <img id="photo-display2_I6" src="<?= $thumblink ?>" alt="Image" class="lazy" />
                        </a>
                      </div>
                    <?php } ?>
                  <?php } else { ?>
                    <div id="img_file_dis_I6" style="padding: 10px 0;">
                      <img id="photo-display2_I6" src="/plugin/img/photo.gif" alt="No Image" />
                    </div>
                  <?php } ?>

                </td>
              </tr>
              <tr>
                <th>지도좌표</th>
                <td class="d-flex text-nowrap gap-1">
                  <div class="d-flex flex-nowrap gap-1">

                    <!-- 좌표 입력 -->
                    <div class="d-flex align-items-center gap-2 flex-wrap">
                      <div class="d-flex align-items-center gap-1">
                        <span class="small text-nowrap">경도</span>
                        <input type="text" class="form-control form-control-sm" name="rcpt_x" id="rcpt_x"
                          value="<?= esc($data['rcpt_x'] ?? '') ?>" style="width: 140px;" disabled />
                      </div>

                      <div class="d-flex align-items-center gap-1">
                        <span class="small text-nowrap">위도</span>
                        <input type="text" class="form-control form-control-sm" name="rcpt_y" id="rcpt_y"
                          value="<?= esc($data['rcpt_y'] ?? '') ?>" style="width: 140px;" disabled />
                      </div>
                    </div>

                    <!-- 버튼 -->
                    <div class="d-flex align-items-center gap-1 flex-wrap">
                      <button type="button" class="btn btn-sm btn-outline-light" id="btnSilverReadLatLng"
                        onclick="ajax_get_geocode();" disabled>
                        주소좌표
                      </button>

                      <button type="button" class="btn btn-sm btn-outline-light" id="btnSilverModifyMap"
                        onclick="modifyMap();" disabled>
                        지도좌표
                      </button>
                    </div>

                  </div>
                </td>
                <th></th>
                <td colspan="2" class="d-flex gap-1 justify-content-end">
                  <button type="button" class="btn btn-sm btn-outline-light" id="btnSilverReadLatLng" onclick="">
                    수정
                  </button>

                  <button type="button" class="btn btn-sm btn-outline-light" id="btnSilverModifyMap" onclick="">
                    저장
                  </button>
                </td>
              </tr>
            </tbody>
          </table>

        </div>
      </div>

      <!-- 거주여부 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">거주여부</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <th>거주여부</th>
                <td id="db_yn0">
                  <select class="form-select" name="resYn" id="resYn" onchange="dbYn_change(this.value);">
                    <option value="Y">Y</option>
                    <option value="N" selected="">N</option>
                  </select>
                </td>
                <th>
                  <div id="db_yn1">DB활용동의여부</div>
                </th>
                <td>
                  <div id="db_yn2">
                    <select class="form-select" name="dbUsageAgrYn" id="dbUsageAgrYn">
                      <option value="N" selected="">N</option>
                      <option value="Y">Y</option>
                    </select>
                  </div>
                </td>
                <td style="text-align: center;">
                  <button type="button" class="btn btn-sm btn-outline-light">저장</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 평면도요청 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">평면도요청</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <th style="width: 100px;">
                  <div id="ground_plan">평면도요청</div>
                </th>
                <td>
                  <select class="form-select" name="ground_plan" id="ground_plan" style="width: 100px;">
                    <option value="N">N</option>
                    <option value="Y" selected="">Y</option>
                  </select>
                </td>
                <th style="width: 200px;">평면도 등록 여부</th>
                <td>
                  <?php
                  $intAptChk = 0;
                  $typeArray = ['아파트', '주상복합', '오피스텔'];
                  if (empty($apt_ground))
                    $apt_ground = [];
                  foreach ($apt_ground as $gval) {


                    $addr = $gval['addr2'];
                    $hscp_no = $gval['hscp_no'];

                    if (in_array($data['rcpt_product_nm'], $typeArray)) {
                      if (strpos($data['rcpt_atclno'], $hscp_no) !== false) {
                        $intAptChk++;
                      }
                    } else {

                      $strAddrArray = explode(" ", $data['rcpt_dtl_addr']);

                      if ($addr == $strAddrArray['0']) {
                        $intAptChk++;

                      }
                    }
                  }

                  if ($intAptChk > 0) {
                    echo "Y";
                  } else {
                    echo "N";
                  }
                  ?>
                </td>
                <td style="text-align: center;">
                  <button type="button" class="btn btn-sm btn-outline-light" onclick="res_ground();">저장</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 예약확정 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">예약확정</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <colgroup>
              <col width="15%" />
              <col width="35%" />
              <col width="15%" />
              <col width="35%" />
            </colgroup>
            <tbody>
              <tr>
                <th>방문희망일시</th>
                <td class="d-flex gap-1" colspan="3">
                  <input type="text" name="rsrv_date" id="rsrv_date" class="form-control"
                    value="<?= $data['rsrv_date'] ?>" size="13" readonly />
                  <select class="form-select" name="rsrv_tm_ap" onchange="rsrv_tm_ap_onchange(this.value)">
                    <option value="">오전/오후</option>
                    <option value="00" <?php if (empty($data['rsrv_tm_ap']))
                      echo "selected"; ?>>무관</option>
                    <option value="AM" <?php if ($data['rsrv_tm_ap'] == 'AM')
                      echo "selected"; ?>>오전</option>
                    <option value="PM" <?php if ($data['rsrv_tm_ap'] == 'PM')
                      echo "selected"; ?>>오후</option>
                  </select>
                  <select class="form-select" name="rsrv_tm_hour" id="rsrv_tm_hour">
                    <option value="">-시-</option>
                    <option value="00" <? if ('00' == $data['rsrv_tm_hour'])
                      echo "selected"; ?>>무관</option>
                    <?php for ($i = 1; $i <= 24; $i++) {
                      $hh = sprintf("%02s", $i);
                      ?>
                      <option value="<?= $hh ?>" <? if ($hh == $data['rsrv_tm_hour'])
                          echo "selected"; ?>>
                        <?= $hh ?>시
                      </option>
                    <?php } ?>
                  </select>
                </td>
              </tr>
              <tr>
                <th>방문날짜</th>
                <td>
                  <?= $data['rsrv_date'] ?>
                  <?= $data['rsrv_tm_ap'] ?>
                  <?php if (!empty($data['rsrv_tm_hour']))
                    echo $data['rsrv_tm_hour'] . "시"; ?>
                </td>
                <th>담당자</th>
                <td class="d-flex gap-1">
                  <select class="form-select" id="bonbu">
                    <option value="">본부선택</option>
                    <?php

                    foreach ($bonbu as $b): ?>
                      <option value="<?= $b['dept_sq'] ?>">
                        <?= $b['dept_nm'] ?>
                      </option>
                    <?php endforeach; ?>
                  </select>
                  <select class="form-select" id="team">
                    <option value="">팀선택</option>
                    <?php
                    $team_dept = $data['dept_sq'];
                    if (empty($data['dept_sq'])) {
                      $team_dept = $data['region_dept_sq'];
                    }
                    foreach ($team as $t): ?>
                      <option value="<?= $t['dept_sq'] ?>" <?php if ($t['dept_sq'] === $team_dept) {
                          echo "selected";
                        } ?>>
                        <?= $t['dept_nm'] ?>
                      </option>
                    <?php endforeach; ?>
                  </select>
                  <select class="form-select" id="user">
                    <option value="">담당자선택</option>
                  </select>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="card-footer justify-content-end">
          <button type="button" class="btn btn-sm btn-outline-success">저장</button>
        </div>
      </div>

      <!-- 동영상촬영여부 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">동영상촬영여부</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <th style="width: 200px;">
                  동영상촬영여부
                </th>
                <td>
                  <select class="form-select" name="exp_movie_yn" id="exp_movie_yn" style="width: 150px;">\
                    <option value="">-선택-</option>
                    <option value="N" <?php if ($data['exp_movie_yn'] == 'N')
                      echo "selected"; ?>>N</option>
                    <option value="Y" <?php if ($data['exp_movie_yn'] == 'N')
                      echo "selected"; ?>>Y</option>
                  </select>
                </td>
                <td style="text-align: center;">
                  <button type="button" class="btn btn-sm btn-outline-light" onclick="requestMovie();">저장</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 중개인 요청사항 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">중개인 요청사항</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <th style="width: 200px;">
                  중개인 요청사항
                </th>
                <td>
                  <textarea class="form-control" id="request_msg" style="height:100px;resize: none;">
                    <?= $data['request_msg'] ?>
                  </textarea>
                </td>
                <td style="text-align: center;">
                  <button type="button" class="btn btn-sm btn-outline-light" onclick="requestMessage();">저장</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 시간대별 통계 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">
            담당자 예약현황 (<?= $data['rsrv_date'] ?>)
          </h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <?php if ($tmCount): ?>
                  <?php foreach ($tmCount as $tm): ?>
                    <th>
                      <?= $tm['rsrv_tm_ap'] ?>
                      <?= $tm['rsrv_tm_hour'] ?> 시
                    </th>
                  <?php endforeach; ?>
                <?php endif; ?>
              </tr>
              <tr>
                <?php if ($tmCount): ?>
                  <?php foreach ($tmCount as $tm): ?>
                    <td><?= $tm['cnt'] ?> 건</td>
                  <?php endforeach; ?>
                <?php endif; ?>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 취소 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">취소</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tbody>
              <tr>
                <th style="width: 100px;">
                  <div id="ground_plan">취소</div>
                </th>
                <td class="d-flex gap-1">
                  <select class="form-select" name="result_cd2" id="result_cd2" style="width: 100px;">
                    <option value="">분류1</option>
                    <?php foreach ($codes as $c): ?>
                      <?php if ($c['category'] === "RECEIPT_STATUS2"): ?>
                        <?php if (substr($c['cd'], 0, 2) == "90"): ?>
                          <option value="<?= $c['cd'] ?>" <?php if ($c['cd'] === $data['result_cd2']) {
                              echo "selected";
                            } ?>>
                            <?= $c['cd_nm'] ?>
                          </option>
                        <?php endif; ?>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
                  <select class="form-select" name="result_cd3" id="result_cd3" style="width: 100px;">
                    <option value="">분류2</option>
                  </select>
                </td>
                <th style="width: 150px;">취소사유</th>
                <td>
                  <input type="text" class="form-control" id="result_msg" value="<?= $data['result_msg'] ?>" />
                </td>
                <td style="text-align: center;">
                  <button type="button" class="btn btn-sm btn-outline-light" onclick="rsrvcancel();">저장</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 매물 상태 정보 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">매물 상태 정보
            <div class="d-flex justify-content-end">
              <?php
              if (in_array($usr_level, ['1'])): ?>
                <button type="button" class="btn btn-outline-warning">검수지연으로 상태변경</button>
              <?php endif; ?>
            </div>

          </h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <?php
            $stat1 = $data['rsrv_delay_dt_dt'] . "<br/>" . $data['rsrv_delay_dt_tm'];		//예약지연
            $stat2 = $data['rsrv_cplt_dt_dt'] . "<br/>" . $data['rsrv_cplt_dt_tm'];		//에약확인
            if ($data['req_rec_yn'] == "Y") {												//촬영
              $stat3 = $data['photo_save_dt_dt'] . "<br/>" . $data['photo_save_dt_tm'] . "<br/>녹취필요";
            } else {
              $stat3 = $data['photo_save_dt_dt'] . "<br/>" . $data['photo_save_dt_tm'];
            }
            $stat4 = $data['check_delay_dt_dt'] . "<br/>" . $data['check_delay_dt_tm'];	//검수지연
            $stat5 = $data['check_fail_dt_dt'] . "<br/>" . $data['check_fail_dt_tm'];	//검수실패
            $stat6 = $data['check_dt_dt'] . "<br/>" . $data['check_dt_tm'];				//검수
            $stat7 = $data['check_cplt_dt_dt'] . "<br/>" . $data['check_cplt_dt_tm'];		//검수완료
            $stat8 = $data['cancel_dt_dt'] . "<br/>" . $data['cancel_dt_tm'];				//취소
            
            $currStat = substr($data['rcpt_stat'], 0, 2);
            $currStat2 = substr($data['rcpt_stat'], 2, 2);

            if ($currStat == 15) {		//예약지연
              $stat1 = "<b><font color='red'>" . $stat1 . "</font></b>";
            } else if ($currStat == 20) {		//예약확인
              $stat2 = "<b><font color='red'>" . $stat2 . "</font></b>";
            } else if ($currStat == 40) {		//촬영
              $stat3 = "<b><font color='red'>" . $stat3 . "</font></b>";
            } else if ($currStat == 50) {		//검수
              $stat6 = "<b><font color='red'>" . $stat6 . "</font></b>";
            } else if ($currStat == 60) {		//검수완료
              $stat7 = "<b><font color='red'>" . $stat7 . "</font></b>";
            } else if ($currStat == 70) {		//검수지연
              $stat4 = "<b><font color='red'>" . $stat4 . "<br/>" . $data['rcpt_stat_nm'] . "</font></b>";
            }
            if ($currStat == 90 && $currStat2 != 50) {		//취소
              $stat8 = "<b><font color='red'>" . $stat8 . "<br/>" . $data['result_cd2_nm'] . "</font></b>";
            } else if ($currStat == 90 && $currStat2 == 50) {		//검수실패
              $stat5 = "<b><font color='red'>" . $stat5 . "<br/>" . $data['rcpt_stat_nm'] . "</font></b>";
            }
            ?>
            <tr>
              <th rowspan="2" width="100" style="text-align:center">현장확인<br />진행상황</th>
              <th style="text-align:center">예약지연</th>
              <th style="text-align:center">예약확인</th>
              <th style="text-align:center">촬영</th>
              <th style="text-align:center">검수지연</th>
              <th style="text-align:center">검수실패</th>
              <th style="text-align:center">검수</th>
              <th style="text-align:center">검수완료</th>
              <th style="text-align:center">취소</th>
            </tr>
            <tr>
              <td style="text-align:center; height: 50px;">
                <?= $stat1 ?>
              </td>
              <td style="text-align:center">
                <?= $stat2 ?>
              </td>
              <td style="text-align:center">
                <?= $stat3 ?>
              </td>
              <td style="text-align:center">
                <?= $stat4 ?>
              </td>
              <td style="text-align:center">
                <?= $stat5 ?>
              </td>
              <td style="text-align:center">
                <?= $stat6 ?>
              </td>
              <td style="text-align:center">
                <?= $stat7 ?>
              </td>
              <td style="text-align:center">
                <?= $stat8 ?>
              </td>
            </tr>
            <?php if (!in_array($usr_level, [])): ?>
              <tr>
                <th>상태변경</th>
                <?php if ($currStat == 10) { ?>
                  <td height="33" style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(150000);">예약지연</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(200000);">예약확인</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                  </td>
                  <td style="text-align:center">
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                  </td>
                  <td style="text-align:center"></td>
                  <td style="text-align:center"></td>
                <?php } else if ($currStat == 15) { ?>
                    <td height="33" style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(200000);">예약확인</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                    </td>
                    <td style="text-align:center">
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                    </td>
                    <td style="text-align:center"></td>
                    <td style="text-align:center"></td>
                <?php } else if ($currStat == 20) { ?>
                      <td height="33" style="text-align:center">
                        <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                      </td>
                      <td style="text-align:center">
                        <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                      </td>
                      <td style="text-align:center">
                        <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(400000);">촬영</button>
                      </td>
                      <td style="text-align:center">
                        <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                      </td>
                      <td style="text-align:center">
                      </td>
                      <td style="text-align:center">
                        <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                      </td>
                      <td style="text-align:center"></td>
                      <td style="text-align:center"></td>
                <?php } else if ($currStat == 40) { ?>
                        <td height="33" style="text-align:center">
                          <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                        </td>
                        <td style="text-align:center">
                          <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                        </td>
                        <td style="text-align:center">
                          <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                        </td>
                        <td style="text-align:center">
                          <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(700000);">검수지연</button>
                        </td>
                        <td style="text-align:center">
                        </td>
                        <td style="text-align:center">
                          <button type="button" class="btn btn-sm btn-success"
                            onclick="chgStatus(500000, '<?= $data['rcpt_product'] ?>', '<?= $data['chg_floor_yn'] ?>');">검수</button>
                        </td>
                        <td style="text-align:center"></td>
                        <td style="text-align:center"></td>
                <?php } else if ($currStat == 70) { ?>
                          <td height="33" style="text-align:center">
                            <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                          </td>
                          <td style="text-align:center">
                            <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                          </td>
                          <td style="text-align:center">
                            <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                          </td>
                          <td style="text-align:center">
                            <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                          </td>
                          <td style="text-align:center">
                          </td>
                          <td style="text-align:center">
                            <button type="button" class="btn btn-sm btn-success"
                              onclick="chgStatus(500000, '<?= $data['rcpt_product'] ?>', '<?= $data['chg_floor_yn'] ?>');">검수</button>
                          </td>
                          <td style="text-align:center;"> </td>
                          <td style="text-align:center"></td>
                <?php } else if ($currStat == 50) { ?>
                            <td height="33" style="text-align:center">
                              <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                            </td>
                            <td style="text-align:center">
                              <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                            </td>
                            <td style="text-align:center">
                              <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(400000);">촬영</button>
                            </td>
                            <td style="text-align:center">
                              <button type="button" class="btn btn-sm btn-success" onclick="chgStatus(700000);">검수지연</button>
                            </td>
                            <td style="text-align:center">
                            </td>
                            <td style="text-align:center">
                              <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                            </td>
                            <td style="text-align:center"></td>
                            <td style="text-align:center"></td>
                <?php } else if ($currStat == 60) {	//검수완료 ?>
                              <td height="33" style="text-align:center">
                                <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                              </td>
                              <td style="text-align:center">
                                <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                              </td>
                              <td style="text-align:center">
                                <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                              </td>
                              <td style="text-align:center">
                                <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                              </td>
                              <td style="text-align:center">
                              </td>
                              <td style="text-align:center">
                                <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                              </td>
                              <td style="text-align:center"></td>
                              <td style="text-align:center"></td>
                <?php }
                if ($currStat == 90 && $currStat2 != 50) { 	//취소 ?>
                  <td height="33" style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                  </td>
                  <td style="text-align:center">
                  </td>
                  <td style="text-align:center">
                    <button type="button" class="btn btn-sm btn-success" disabled>검수</button>
                  </td>
                  <td style="text-align:center"></td>
                  <td style="text-align:center"></td>
                <?php } else if ($currStat == 90 && $currStat2 == 50) {	//검수실패 ?>
                    <td height="33" style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>예약지연</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>예약확인</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>촬영</button>
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success" disabled>검수지연</button>
                    </td>
                    <td style="text-align:center">
                    </td>
                    <td style="text-align:center">
                      <button type="button" class="btn btn-sm btn-success"
                        onclick="chgStatus(500000, '<?= $data['rcpt_product'] ?>', '<?= $data['chg_floor_yn'] ?>');">검수</button>
                    </td>
                    <td style="text-align:center"></td>
                    <td style="text-align:center"></td>
                <?php } ?>
              </tr>
            <?php endif; ?>
          </table>
        </div>
      </div>

      <!-- SMS 보내기 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">SMS 보내기</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <?php
            $smsList = [];
            foreach ($codes as $c) {
              if ($c['category'] === "SMS_MSG_TYPE") {
                array_push($smsList, $c);
              }
            }

            $smsTot = sizeof($smsList);
            $rowspan = ceil($smsTot / 6);
            ?>
            <tr>
              <th rowspan="<?= $rowspan ?>" style="text-align:center">
                상황별<br />SMS선택
              </th>
              <?php
              $smsCnt = 1;
              foreach ($smsList as $sms1):
                if (!in_array($sms1['cd'], ["S10", "S3", "S7", "S15"])) {
                  continue;
                }
                ?>
                <td style="text-align:center">
                  <a href="javascript:viewSmsPop('<?= $sms1['cd'] ?>');">
                    <?= $sms1['category_nm'] ?>
                  </a>
                </td>
                <?php
                if ($smsCnt % 6 == 0) {
                  echo "</tr><tr>";
                }
                $smsCnt++;
              endforeach; ?>
            </tr>
          </table>
        </div>
      </div>

      <!-- 매물 위치 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">매물 위치</h5>
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <colgroup>
              <col width="25%">
            </colgroup>

            <tr>
              <td colspan="2" style="padding:5px;">
                <div id="mapArea" style="width:100%;height:300px;"></div>
              </td>
            </tr>
          </table>
        </div>
      </div>

      <!-- 확인 정보 및 사진 정보 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">확인 정보 및 사진 정보</h5>
          <div class="row g-3">

            <!-- 홍보확인서 -->
            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">홍보확인서</div>

                  <!-- 업로드 버튼(기존 input file 유지) -->
                  <label class="btn btn-sm btn-outline-secondary mb-0">
                    파일
                    <input type="file" id="img_file_I1" name="img_file_I1" accept=".jpg,.jpeg,.png,.gif" class="d-none"
                      onclick="type_alert_onclick(event, 'I1', '0')" onchange="imgFind_onchange(event, 'I1', '0')">
                  </label>
                </div>

                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  $arrI1 = array();
                  reset($images);
                  foreach ($images as $key => $img) {
                    if ($img['img_type'] == 'I1') {
                      $arrI1[] = $img;
                      unset($images[$key]);
                    }
                  }
                  if (!empty($arrI1)) {
                    foreach ($arrI1 as $img) {
                      list($filename, $ext) = explode(".", $img['img_filenm']);
                      $thumbname = $filename . "_thumb.jpg";

                      $imgPath = $img['img_path'] . $thumbname;
                      $link = $img['img_path'] . $img['img_filenm'];

                      $link = realFilePath($link);
                      $imgPath = realFilePath($imgPath);

                      if ($img['cloud_upload_yn'] == 'Y') {
                        $imgPath = NCLOUD_OBJECT_STORAGE_URL . $img['img_path'] . $thumbname;
                        $link = NCLOUD_OBJECT_STORAGE_URL . $img['img_path'] . $img['img_filenm'];
                      }

                      $sq = $img['img_sq'];
                    }
                    ?>
                    <a onclick="fn_preview('<?= $link ?>')">
                      <img id="photo-display2_I1" src="<?= $link ?>" alt="홍보확인서" class="w-100  object-fit-contain">
                    </a>
                  <?php } else { ?>
                    <img id="photo-display2_I1" src="/plugin/img/photo.gif" alt="홍보확인서" class="w-100  object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>

            <!-- 촬영동의서 -->
            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">촬영동의서</div>
                  <button type="button" class="btn btn-sm btn-outline-secondary"
                    onclick="viewFilePop('I10', '')">파일</button>
                </div>

                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  if (isset($imgs_count['I10']) && $imgs_count['I10'] != 0) {
                    foreach ($images as $img) {
                      if ($img['img_type'] == 'I10') {
                        $temp2 = explode(".", $img['img_filenm']);
                        //$name = $temp2[0]."_thumb.".$temp2[1];
                        $name = $temp2[0] . "_thumb.jpg";

                        $image_name = $img['img_path'] . $img['img_filenm'];
                        $thumbnail_image_name = $img['img_path'] . $name;
                        $agreement_image = realFilePath($image_name);
                        $agreement_image_thumbnail = realFilePath($thumbnail_image_name);

                        if ($img['cloud_upload_yn'] == 'Y') {
                          $agreement_image_thumbnail = NCLOUD_OBJECT_STORAGE_URL . $thumbnail_image_name;
                          $agreement_image = NCLOUD_OBJECT_STORAGE_URL . $img['img_path'] . $img['img_filenm'];
                        }
                        ?>

                        <a onclick="fn_preview('<?= $agreement_image ?>')">
                          <img src="<?= $agreement_image_thumbnail ?>" alt="촬영동의서" class="w-100  object-fit-contain">
                        </a>
                        <?php
                      }
                    }
                  } else {
                    ?>
                    <img src="/plugin/img/photo.gif" alt="촬영동의서" class="w-100  object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>

            <!-- 현장확인내역서 -->
            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">현장확인내역서</div>
                  <button type="button" class="btn btn-sm btn-outline-secondary"
                    onclick="viewFilePop('I2', '')">파일</button>
                </div>

                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  if (isset($imgs_count['I2']) && $imgs_count['I2'] != 0) {
                    foreach ($images as $img) {
                      if ($img['img_type'] == 'I2') {
                        $temp2 = explode(".", $img['img_filenm']);
                        //$name = $temp2[0]."_thumb.".$temp2[1];
                        $name = $temp2[0] . "_thumb.jpg";
                        $image_name = $img['img_path'] . $img['img_filenm'];
                        $thumbnail_image_name = $img['img_path'] . $name;
                        $agreement_image = realFilePath($image_name);
                        $agreement_image_thumbnail = realFilePath($thumbnail_image_name);

                        if ($img['cloud_upload_yn'] == 'Y') {
                          $agreement_image_thumbnail = NCLOUD_OBJECT_STORAGE_URL . $thumbnail_image_name;
                          $agreement_image = NCLOUD_OBJECT_STORAGE_URL . $img['img_path'] . $img['img_filenm'];
                        }
                        ?>
                        <a onclick="fn_preview('<?= $agreement_image ?>')">
                          <img src="<?= $agreement_image_thumbnail ?>" alt="현장확인내역서" class="w-100  object-fit-contain">
                        </a>
                        <?php
                      }
                    }
                  } else {
                    ?>
                    <img src="/plugin/img/photo.gif" alt="현장확인내역서" class="w-100  object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>
          </div>

          <hr class="my-3">

          <!-- 분양권(썸네일 여러개 + 파일 버튼) -->
          <div class="mb-3">
            <div class="d-flex justify-content-between align-items-center mb-2">
              <div class="fw-semibold">분양권 (최대 5장)</div>
              <button type="button" class="btn btn-sm btn-outline-secondary"
                onclick="viewFilePop('I8', '0')">파일</button>
            </div>

            <div class="d-flex flex-wrap gap-2">
              <!-- NOTE: 기존 코드가 id 중복(photo-display2_I8)이라 반드시 고쳐야 함 -->
              <div class="thumb-box">
                <?php
                $arrI8 = array();
                reset($images);
                foreach ($images as $key => $img) {
                  if ($img['img_type'] == 'I8') {
                    $arrI8[] = $img;
                    unset($images[$key]);
                  }
                }
                if (!empty($arrI8)) {

                  foreach ($arrI8 as $img) {
                    list($filename, $ext) = explode(".", $img['img_filenm']);
                    $thumbname = $filename . "_thumb.jpg";

                    $imgPath = $img['img_path'] . $thumbname;
                    $link = $img['img_path'] . $img['img_filenm'];
                    $agreement_image = realFilePath($link);
                    $agreement_image_thumbnail = realFilePath($imgPath);

                    $sq = $img['img_sq'];

                    if ($img['cloud_upload_yn'] == 'Y') {
                      $agreement_image_thumbnail = NCLOUD_OBJECT_STORAGE_URL . $imgPath;
                      $agreement_image = NCLOUD_OBJECT_STORAGE_URL . $link;
                    }
                    ?>
                    <a onclick="fn_preview('<?= $agreement_image ?>')">
                      <img src="<?= $agreement_image_thumbnail ?>" alt="분양권1" class="w-100  object-fit-contain">
                    </a>
                  <?php } ?>
                <?php } else { ?>
                  <img id="photo-display2_I8_1" src="/plugin/img/photo.gif" alt="분양권1" class="thumb-img">
                <?php } ?>
              </div>
            </div>
          </div>

          <hr class="my-3">

          <!-- 매물사진 -->
          <div class="mb-3">
            <div class="d-flex justify-content-between align-items-center mb-2">
              <div class="fw-semibold">매물사진 (최대 15장)</div>

              <div class="d-flex gap-1 flex-wrap">
                <button type="button" class="btn btn-sm btn-outline-primary" onclick="viewFilePop('I4', '')">파일</button>
                <button type="button" class="btn btn-sm btn-outline-secondary"
                  onclick="saveImgOrder('I4', 'M201')">저장</button>
                <button type="button" class="btn btn-sm btn-outline-danger"
                  onclick="btnSilverDeleteAllImage_onclick('I4')">일괄삭제</button>
                <button type="button" class="btn btn-sm btn-outline-focus"
                  onclick="btnSilverDownloadAllImage_onclick()">일괄다운로드</button>
              </div>
            </div>

            <div class="d-flex flex-wrap gap-2">
              <!-- 기존 li+table 구조 대신 썸네일 카드로 -->
              <!-- 필요 개수만큼 반복 -->
              <?php
              if (isset($imgs_count['I4']) && $imgs_count['I4'] != 0) {
                $cnt = 0;
                foreach ($images as $img) {
                  if ($img['img_type'] == 'I4') {

                    $link = $img['img_path'] . $img['img_filenm'];
                    $temp2 = explode(".", $img['img_filenm']);
                    //$name = $temp2[0]."_thumb.".$temp2[1];
                    $thumbname = $temp2[0] . "_thumb.jpg";
                    $thumblink = $img['img_path'] . $thumbname;

                    $agreement_image = realFilePath($link);
                    $agreement_image_thumbnail = realFilePath($thumblink);

                    if ($img['cloud_upload_yn'] == 'Y') {
                      $agreement_image_thumbnail = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                      $agreement_image = NCLOUD_OBJECT_STORAGE_URL . $link;
                    }

                    $cnt++;
                    ?>


                    <div class="thumb-card">
                      <input type="text" class="form-control form-control-sm mb-1" name="i4_order[]" size="3"
                        value="<?= $img['view_odr'] ?>" />
                      <input type="hidden" name="i4_seq[]" value="<?= $img['img_sq'] ?>" size="2" />
                      <div class="thumb-box">
                        <a onclick="fn_preview('<?= $agreement_image ?>')">
                          <img src="<?= $agreement_image_thumbnail ?>" alt="매물사진" class="thumb-img">
                        </a>
                      </div>
                    </div>
                  <?php }
                } ?>
              <?php } else { ?>
                <div class="thumb-card">
                  <input type="text" class="form-control form-control-sm mb-1" size="3" placeholder="#" />
                  <div class="thumb-box">
                    <img src="/plugin/img/photo.gif" alt="매물사진" class="thumb-img">
                  </div>
                </div>
              <?php } ?>
            </div>
          </div>

          <hr class="my-3">

          <!-- 동영상 / 평면도 / 체크리스트 -->
          <div class="row g-3 mb-3">
            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">동영상</div>
                  <button type="button" class="btn btn-sm btn-outline-secondary"
                    onclick="viewFilePop('V1', '')">파일</button>
                </div>
                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  if (isset($imgs_count['V1']) && $imgs_count['V1'] != 0) {
                    foreach ($images as $img) {
                      if ($img['img_type'] == 'V1') {

                        $link = $img['img_path'] . $img['img_filenm'];
                        $temp2 = explode(".", $img['img_filenm']);
                        //$name = $temp2[0]."_thumb.".$temp2[1];
                        $name = $temp2[0] . "_thumb.jpg";
                        $thumblink = $img['img_path'] . $name;

                        if ($img['cloud_upload_yn'] == 'Y') {
                          $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                          $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                        }
                        ?>

                        <a onclick="fn_preview('<?= $link ?>', 'vdo')">
                          <img src="/plugin/img/video.png" alt="동영상" class="w-100 object-fit-contain">
                        </a>

                        <?php
                      }
                    }
                  } else {
                    ?>
                    <img src="/plugin/img/photo.gif" alt="동영상" class="w-100 object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>

            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">평면도</div>
                  <button type="button" class="btn btn-sm btn-outline-secondary"
                    onclick="viewFilePop('I5', '')">파일</button>
                </div>
                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  if (isset($imgs_count['I5']) && $imgs_count['I5'] != 0) {
                    foreach ($images as $img) {
                      if ($img['img_type'] == 'I5') {
                        $link = $img['img_path'] . $img['img_filenm'];
                        $temp2 = explode(".", $img['img_filenm']);
                        $name = $temp2[0] . "_thumb.jpg";
                        $thumblink = $img['img_path'] . $name;

                        if ($img['cloud_upload_yn'] == 'Y') {
                          $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                          $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                        }
                        ?>
                        <a onclick="fn_preview('<?= $link ?>')">
                          <img id="photo-display2_I1" src="<?= $thumblink ?>" alt="평면도" class="w-100  object-fit-contain">
                        </a>
                      <?php }
                    }
                  } else { ?>

                    <img src="/plugin/img/photo.gif" alt="평면도" class="w-100  object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>

            <div class="col-12 col-lg-4">
              <div class="border rounded-3 p-2 ">
                <div class="d-flex justify-content-between align-items-center mb-2">
                  <div class="fw-semibold">체크리스트</div>
                  <button type="button" class="btn btn-sm btn-outline-secondary"
                    onclick="viewFilePop('I11', '')">파일</button>
                </div>
                <div class="ratio ratio-4x3 rounded-2 overflow-hidden">
                  <?php
                  if (isset($imgs_count['I11']) && $imgs_count['I11'] != 0) {
                    foreach ($images as $img) {
                      if ($img['img_type'] == 'I11') {
                        $link = $img['img_path'] . $img['img_filenm'];
                        $temp2 = explode(".", $img['img_filenm']);
                        $name = $temp2[0] . "_thumb.jpg";
                        $thumblink = $img['img_path'] . $name;

                        if ($img['cloud_upload_yn'] == 'Y') {
                          $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                          $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                        }
                        ?>
                        <a onclick="fn_preview('<?= $link ?>')">
                          <img id="photo-display2_I1" src="<?= $thumblink ?>" alt="체크리스트" class="w-100  object-fit-contain">
                        </a>
                      <?php }
                    }
                  } else { ?>

                    <img src="/plugin/img/photo.gif" alt="체크리스트" class="w-100  object-fit-contain">
                  <?php } ?>
                </div>
              </div>
            </div>
          </div>

          <!-- 평면도중복 -->
          <?php if (!empty($dupleGroundPlan)): ?>
            <div class="border rounded-3 p-3 mb-3 bg-white">
              <div class="d-flex align-items-center justify-content-between mb-2">
                <div class="fw-semibold">평면도 중복</div>
                <span class="badge bg-secondary"><?= count($dupleGroundPlan ?? []) ?>건</span>
              </div>

              <div class="text-muted small py-2">중복된 평면도가 없습니다.</div>

              <div class="vstack gap-2">
                <?php $numbering = 1;
                foreach ($dupleGroundPlan as $row): ?>
                  <div class="border rounded-3 p-2">
                    <div class="d-flex align-items-center justify-content-between">
                      <div class="fw-semibold">
                        <span class="badge bg-dark me-2">중복 <?= $numbering ?></span>
                        <span class="text-muted small">평면도 중복</span>
                      </div>
                    </div>

                    <div class="row g-2 mt-1 small">
                      <div class="col-12 col-md-6">
                        <div class="d-flex align-items-center gap-2">
                          <span class="text-muted">매물번호</span>
                          <span class="fw-semibold"><?= esc($row['rcpt_key'] ?? '') ?></span>
                        </div>
                      </div>
                      <div class="col-12 col-md-6">
                        <div class="d-flex align-items-center gap-2">
                          <span class="text-muted">촬영일자</span>
                          <span class="fw-semibold"><?= esc($row['photo_save_dt'] ?? '') ?></span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <?php $numbering++; endforeach; ?>
              </div>
            </div>
          <?php endif; ?>

          <!-- 매물현장확인 체크리스트 -->
          <?php if ($data['exp_photo_yn'] == 'N'): ?>
            <div class="border rounded-3 p-3 mb-3 bg-white">
              <div class="d-flex align-items-center justify-content-between mb-2">
                <div class="fw-semibold">매물현장확인 체크리스트</div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">엘리베이터</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="elevator_yn" id="elevator_y" value="Y" <?php if ($result_check['elevator_yn'] == 'Y') {
                        echo 'checked="checked"';
                      } ?>>
                      <label class="form-check-label" for="elevator_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="elevator_yn" id="elevator_n" value="N" <?php if ($result_check['elevator_yn'] == 'N') {
                        echo 'checked="checked"';
                      } ?>>
                      <label class="form-check-label" for="elevator_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">관리비/월</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <input type="text" class="form-control" name="maintenance_fee" id="maintenance_fee"
                      value="<?= $result_check['maintenance_fee'] ?>" size="10" maxlength="10" style="width: 150px;" />
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">엘리베이터CCTV</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="elevator_cctv_yn" id="elevator_cctv_y" value="Y"
                        <?php if ($result_check['elevator_cctv_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="elevator_cctv_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="elevator_cctv_yn" id="elevator_cctv_n" value="N"
                        <?php if ($result_check['elevator_cctv_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="elevator_cctv_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">건물내부CCTV</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_in_cctv_yn" id="building_in_cctv_y"
                        value="Y" <?php if ($result_check['building_in_cctv_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_in_cctv_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_in_cctv_yn" id="building_in_cctv_n"
                        value="N" <?php if ($result_check['building_in_cctv_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_in_cctv_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">건물외부CCTV</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_ou_cctv_yn" id="building_ou_cctv_y"
                        value="Y" <?php if ($result_check['building_ou_cctv_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_ou_cctv_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_ou_cctv_yn" id="building_ou_cctv_n"
                        value="N" <?php if ($result_check['building_ou_cctv_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_ou_cctv_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">난방방식</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <input type="text" class="form-control" name="heating_type" id="heating_type"
                      value="<?= $result_check['heating_type'] ?>" size="10" maxlength="10" style="width: 150px;" />
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">경비실</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="security_dept_yn" id="security_dept_y" value="Y"
                        <?php if ($result_check['security_dept_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="security_dept_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="security_dept_yn" id="security_dept_n" value="N"
                        <?php if ($result_check['security_dept_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="security_dept_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>


              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">주차장</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="parking_lot_yn" id="parking_lot_y" value="Y"
                        <?php if ($result_check['parking_lot_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="parking_lot_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="parking_lot_yn" id="parking_lot_n" value="N"
                        <?php if ($result_check['parking_lot_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="parking_lot_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">인터폰</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="interphone_yn" id="interphone_y" value="Y" <?php if ($result_check['interphone_yn'] == 'Y') {
                        echo 'checked="checked"';
                      } ?>>
                      <label class="form-check-label" for="interphone_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="interphone_yn" id="interphone_n" value="N" <?php if ($result_check['interphone_yn'] == 'N') {
                        echo 'checked="checked"';
                      } ?>>
                      <label class="form-check-label" for="interphone_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>

              <div class="row g-2 align-items-center">
                <div class="col-1 col-md-1">
                  <label class="form-label mb-0">출입카드키</label>
                </div>

                <div class="col-12 col-md-9">
                  <div class="d-flex gap-3">
                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_security_yn" id="building_security_y"
                        value="Y" <?php if ($result_check['building_security_yn'] == 'Y') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_security_y">있음</label>
                    </div>

                    <div class="form-check form-check-inline mb-0">
                      <input class="form-check-input" type="radio" name="building_security_yn" id="building_security_n"
                        value="N" <?php if ($result_check['building_security_yn'] == 'N') {
                          echo 'checked="checked"';
                        } ?>>
                      <label class="form-check-label" for="building_security_n">없음</label>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          <?php endif; ?>

          <!-- 검수사항 -->
          <div class="border rounded-3 p-2 mb-3">
            <div class="fw-semibold mb-2">검수사항</div>
            <div class="form-check">
              <input class="form-check-input" type="checkbox" name="chkPromote" id="chkPromote" value="Y">
              <label class="form-check-label" for="chkPromote">홍보확인서 확인</label>
            </div>
            <?php if ($data['rcpt_product'] == 'B01' || $data['rcpt_product'] == 'B02' || $data['rcpt_product'] == 'B03'): ?>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" name="chkBunyang" id="chkBunyang" value="Y">
                <label class="form-check-label" for="chkBunyang">분양권 확인</label>
              </div>
            <?php endif; ?>
          </div>

          <!-- 360이미지 / 촬영위치 -->
          <div class="border rounded-3 p-2">
            <div class="d-flex justify-content-between align-items-center mb-2">
              <div class="fw-semibold">360이미지 (최대 5장) / 촬영위치</div>
              <button type="button" class="btn btn-sm btn-outline-secondary" onclick="viewFilePop('I9', '')">파일</button>
            </div>

            <div class="d-flex flex-wrap gap-2">
              <?php
              if (isset($imgs_count['I9']) && $imgs_count['I9'] != 0) {
                $cnt = 0;
                foreach ($images as $img) {
                  if ($img['img_type'] == 'I9') {
                    $link = $img['img_path'] . $img['img_filenm'];
                    $temp2 = explode(".", $img['img_filenm']);
                    $name = $temp2[0] . "_thumb.jpg";
                    $thumblink = $img['img_path'] . $name;

                    if ($img['cloud_upload_yn'] == 'Y') {
                      $thumblink = NCLOUD_OBJECT_STORAGE_URL . $thumblink;
                      $link = NCLOUD_OBJECT_STORAGE_URL . $link;
                    }
                    $cnt++;
                    ?>
                    <div class="thumb-card">
                      <div class="thumb-box mb-1">
                        <a onclick="fn_preview('<?= $link ?>')">
                          <img src="<?= $thumblink ?>" alt="360이미지" class="thumb-img">
                        </a>
                      </div>
                      <input class="form-control form-control-sm" type="text" name="img_location_<?= $img['img_sq'] ?>"
                        id="img_location_<?= $img['img_sq'] ?>" value="<?= $img['img_location'] ?>" size="11"
                        style="width: 160px;">
                    </div>
                  <?php }
                }
              } else { ?>
                <div class="thumb-card">
                  <div class="thumb-box mb-1">
                    <img src="/plugin/img/photo.gif" alt="360이미지" class="thumb-img">
                  </div>
                  <input class="form-control form-control-sm" type="text" placeholder="촬영위치" style="width: 160px;">
                </div>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>


      <!-- 거주인 정보 및 녹취 내용 -->
      <div class="main-card mb-3 card">
        <div class="card-body">
          <h5 class="card-title">중개인 요청사항</h5>

          <?php
          // 전화번호 분해
          $arrRecTel = ["", "", ""];
          if (!empty($data['rec_tel'])) {
            $tmp = explode("-", $data['rec_tel']);
            $arrRecTel[0] = $tmp[0] ?? "";
            $arrRecTel[1] = $tmp[1] ?? "";
            $arrRecTel[2] = $tmp[2] ?? "";
          }
          ?>

          <table class="table table-bordered table-sm tbl_basic2 apt-info-table mb-0">
            <colgroup>
              <col width="15%" />
              <col width="35%" />
              <col width="15%" />
              <col width="35%" />
            </colgroup>

            <tbody>
              <!-- 1) 거주자 정보 -->
              <tr>
                <th class="align-middle">거주자 전화번호</th>
                <td class="align-middle">
                  <div class="input-group input-group-sm" style="max-width: 340px;">
                    <input type="text" class="form-control" name="rec_tel1" maxlength="4" placeholder="010"
                      value="<?= esc($arrRecTel[0]) ?>" />
                    <span class="input-group-text">-</span>
                    <input type="text" class="form-control" name="rec_tel2" maxlength="4" placeholder="1234"
                      value="<?= esc($arrRecTel[1]) ?>" />
                    <span class="input-group-text">-</span>
                    <input type="text" class="form-control" name="rec_tel3" maxlength="4" placeholder="5678"
                      value="<?= esc($arrRecTel[2]) ?>" />
                  </div>
                </td>

                <th class="align-middle">거주인 이름</th>
                <td class="align-middle">
                  <input type="text" class="form-control form-control-sm" name="rec_nm" style="max-width: 220px;"
                    value="<?= esc($data['rec_nm'] ?? '') ?>" />
                </td>
              </tr>

              <!-- 2) 음성파일 -->
              <tr>
                <th class="align-middle">음성파일</th>
                <td colspan="3" class="align-middle">
                  <div class="d-flex align-items-center flex-wrap gap-2">

                    <!-- 현재 파일 정보 -->
                    <?php if (!empty($record)): ?>
                      <div class="d-flex align-items-center gap-2 flex-wrap">
                        <a class="fw-semibold text-decoration-none"
                          href="/article/receipt/download_file?record_sq=<?= $record['record_sq'] ?>">
                          <?= esc($record['record_orignm']) ?>
                        </a>
                        <span class="badge text-dark border"><?= esc($record['record_size']) ?> KB</span>
                        <span class="badge text-dark border"><?= esc($record['insert_tm']) ?></span>
                      </div>
                    <?php else: ?>
                      <span class="text-muted small">등록된 파일 없음</span>
                    <?php endif; ?>

                    <div class="vr"></div>

                    <!-- 업로드 버튼 + 파일명 -->
                    <label class="btn btn-sm btn-outline-secondary mb-0">
                      파일 업로드
                      <input type="file" id="rec_file" name="rec_file" accept=".wav" class="d-none"
                        onchange="showFileName(this);">
                    </label>
                    <span id="file_name" class="text-muted small"></span>

                    <div class="vr"></div>

                    <!-- 체크박스 -->
                    <div class="form-check mb-0">
                      <input class="form-check-input" type="checkbox" name="chk_record" id="chk_record" value="Y"
                        <?= empty($record) ? 'disabled' : 'checked' ?>>
                      <label class="form-check-label" for="chk_record">
                        녹취파일 확인
                      </label>
                    </div>
                  </div>
                </td>
              </tr>

              <!-- 3) 거주인 요청사항 -->
              <tr>
                <th class="align-middle">거주인 요청사항</th>
                <td colspan="3">
                  <textarea class="form-control form-control-sm" name="rec_remark" rows="2"
                    placeholder="요청사항을 입력하세요"><?= esc($data['remark'] ?? '') ?></textarea>
                </td>
              </tr>
            </tbody>
          </table>
        </div>

        <div class="card-footer d-flex justify-content-end gap-1">
          <?php if (!in_array($usr_level, [])): ?>
            <button type="button" class="btn btn-sm btn-outline-primary" onclick="saveRecInfo();">저장</button>
          <?php endif; ?>
          <button type="button" class="btn btn-sm btn-outline-focus" onclick="viewSmsPop('S14');">완료안내</button>
        </div>
      </div>
    </form>

    <!-- 정보변경 이력 -->
    <div class="main-card mb-3 card">
      <div class="card-body ">
        <h5 class="card-title">정보변경 이력</h5>
        <div class="table-scroll">
          <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
            <tr>
              <th style="text-align: center;">진행상태</th>
              <th style="text-align: center;">변경내용</th>
              <th style="text-align: center;">처리자(ID)</th>
              <th style="text-align: center;">처리일시</th>
              <th style="text-align: center;">세부내용</th>
            </tr>
            <?php if (!empty($history)) { ?>
              <?php foreach ($history as $h) { ?>
                <tr>
                  <td style="text-align: center;">
                    <?= $h['rcpt_stat_nm'] ?>
                  </td>
                  <td style="text-align: center;">
                    <?= $h['changed_type_nm'] ?>
                  </td>
                  <td style="text-align: center;">
                    <?= $h['changed_id'] ?>
                  </td>
                  <td style="text-align: center;">
                    <?= $h['changed_tm'] ?>
                  </td>
                  <td>
                    <?= $h['remark'] ?>
                  </td>
                </tr>
              <?php } ?>
            <?php } ?>
          </table>
        </div>
      </div>
    </div>

  </div>
</div>

<?= $this->section('modals') ?>
<div class="modal" id="previewModal" tabindex="-1">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">미리보기</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>
      <div class="modal-body p-0">
        <img id="imgPreview" src="" alt="미리보기" width="100%" height="auto">
        <video id="vdoPreview" controls playsinline preload="metadata" style="display: none;height: 500px;width: 100%;">
          <source id="videoSource" src="" type="video/mp4">
          브라우저가 video 태그를 지원하지 않습니다.
        </video>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="uploadModal" tabindex="-1">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">파일 업로드</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>
      <div class="modal-body p-0">
        <form id="frm_file_info" method="post" enctype="multipart/form-data" onsubmit="return false;">
          <input type="hidden" name="rcpt_key" value="">

          <!-- 버튼 툴바 -->
          <div class="d-flex justify-content-end gap-2 mb-3" style="padding: 16px 10px 0 0;">
            <button type="button" class="btn btn-primary" id="uploadPick">
              <i class="pe-7s-up-arrow"></i> 파일선택
            </button>

            <button type="button" class="btn btn-success" id="btnUpload">
              <i class="pe-7s-up-arrow"></i> 파일업로드
            </button>

            <button type="button" class="btn btn-danger" id="btnRemove">
              <i class="pe-7s-less"></i> 업로드취소
            </button>
          </div>

          <!-- Dropzone 영역 -->
          <div id="myDropzone" class="dropzone border rounded-3 p-4" style="max-height: 400px;overflow-y: scroll;">
            <div class="dz-message dz-message-fixed needsclick text-center">
              <i class="pe-7s-upload mb-2" style="font-size:42px;"></i><br>
              <strong class="fs-6">파일을 드래그하거나 클릭해서 추가하세요</strong><br>
            </div>
          </div>

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

<div class="modal fade" id="smsModal" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-md">
    <div class="modal-content">

      <div class="modal-header">
        <h5 class="modal-title">SMS 보내기</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <form id="smsForm" onsubmit="return false;">
        <input type="hidden" name="rcpt_key" value="<?= $data['rcpt_key'] ?>" />
        <input type="hidden" name="rcpt_sq" value="<?= $data['rcpt_sq'] ?>" />
        <input type="hidden" name="rsrv_sq" value="<?= $data['rsrv_sq'] ?>" />
        <input type="hidden" name="cd" />
        <div class="modal-body">
          <div class="mb-3">
            <label for="smsPhone" class="form-label">수신번호</label>
            <input type="tel" class="form-control" id="smsPhone" name="phone" placeholder="010-0000-0000" required>
          </div>

          <div class="mb-3">
            <label for="smsContent" class="form-label">내용</label>
            <textarea class="form-control" id="smsContent" name="content" rows="5" placeholder="메시지 내용을 입력하세요"
              style="resize: none;" required></textarea>
          </div>

        </div>

        <div class="modal-footer justify-content-center gap-1">
          <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">
            닫기
          </button>
          <button type="submit" class="btn btn-sm btn-outline-primary" id="btnSendSms">
            보내기
          </button>
        </div>
      </form>

    </div>
  </div>
</div>
<?= $this->endSection() ?>

<script type="text/javascript" src="https://oapi.map.naver.com/openapi/v3/maps.js?ncpKeyId=dtounkwjc5"></script>
<script src="https://unpkg.com/dropzone@6.0.0-beta.1/dist/dropzone-min.js"></script>
<link href="https://unpkg.com/dropzone@6.0.0-beta.1/dist/dropzone.css" rel="stylesheet" type="text/css" />
</script>
<script type="text/javascript">

  const rcpt_hscp_nm = '<?= $data['rcpt_hscp_nm'] ?>';
  const spc_stat = '<?= $data['spc_stat'] ?>'

  const lat = parseFloat("<?= esc($data['rcpt_y'] ?? '0') ?>");
  const lng = parseFloat("<?= esc($data['rcpt_x'] ?? '0') ?>");

  const smsArr = <?= json_encode($sms ?? [], JSON_UNESCAPED_UNICODE); ?>;

  var map;

  $(function () {

    trade_type_onchange();

    if (isDefined(rcpt_hscp_nm)) {
      $(".spc").hide();
    }

    map = new naver.maps.Map('mapArea', {
      center: new naver.maps.LatLng(lat, lng),
      useStyleMap: true,
      zoom: 17,
      minZoom: 10,
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: naver.maps.MapTypeControlStyle.BUTTON,
        position: naver.maps.Position.TOP_LEFT
      },
      zoomControl: true,
      zoomControlOptions: {
        position: naver.maps.Position.TOP_RIGHT
      }
    });

    marker = new naver.maps.Marker({
      position: new naver.maps.LatLng(lat, lng),
      map: map
    });


    /**
             *  파일 Dropzone
             * */
    const dz = new Dropzone("#myDropzone", {
      url: "/m712/m712a/uploadFile",
      method: "post",
      paramName: "files",
      autoProcessQueue: false,   // 자동 업로드 끄기
      uploadMultiple: false,
      parallelUploads: 20,
      maxFilesize: 100,
      // acceptedFiles: '.ogg,.mp3,.wma,.wav,.au,.rm,.mid,.MP3,.OGG,.WMA,.WAV,.AU,.RM,.MID,.gsm',
      addRemoveLinks: true,
      dictRemoveFile: "삭제",
      dictDefaultMessage: "파일을 여기에 드래그하거나 클릭해서 추가하세요",
      dictFallbackMessage: "브라우저가 드래그앤드롭을 지원하지 않습니다.",
      dictFileTooBig: "파일이 너무 큽니다 (최대 {{maxFilesize}}MB)",
      dictInvalidFileType: "허용되지 않은 파일 형식입니다.",
      dictResponseError: "서버 오류가 발생했습니다.",
      dictCancelUpload: "업로드 취소",
      dictRemoveFile: "삭제",
      dictMaxFilesExceeded: "더 이상 파일을 추가할 수 없습니다.",
      init: function () {
        this.on("addedfile", function (file) {

          if (this.files.length > 1) {
            alert("파일은 1개만 업로드할 수 있습니다.");
            this.removeFile(file);
            return;
          }
        });
      },
    });

    dz.on("addedfile", function (file) {
      const removeBtn = file.previewElement.querySelector(".dz-remove");

      if (removeBtn) {
        removeBtn.classList.add(
          "btn",
          "btn-sm",
          "btn-outline-danger",
          "mt-2"
        );
      }
    });


    let isFormDataAppended = false;
    dz.on("sending", function (file, xhr, formData) {
      if (isFormDataAppended) return;

      formData.append("vr_sq", $("#frm_file_info [name=vr_sq]").val());

      isFormDataAppended = true;
    });

    dz.on("queuecomplete", function () {
      location.reload();
    });

    dz.on("successmultiple", function () {
      isFormDataAppended = false;
    });
    dz.on("errormultiple", function () {
      isFormDataAppended = false;
    });
    dz.on("canceledmultiple", function () {
      isFormDataAppended = false;
    });
    dz.on("processingmultiple", function () { });

    // 업로드파일 선택
    $("#uploadPick").on("click", function () {
      isFormDataAppended = false;
      dz.hiddenFileInput.click();
    });

    $("#btnUpload").on("click", function () {
      dz.processQueue(); // 업로드 실행
      isFormDataAppended = false;
    });

    $("#btnRemove").on("click", function () {
      const files = dz.getAcceptedFiles();

      if (files.length === 0) {
        alert("삭제할 파일이 없습니다.");
        return;
      }

      files.forEach(function (file) {
        dz.removeFile(file);
      });
    });


    // 파일업로드 open
    $("#btnUploadModal").on("click", function () {

      $("#uploadModal").modal("show");
    });

  });

  //공백 값 체크 
  function isDefined(str) {
    var isResult = false;
    str_temp = str + "";
    str_temp = str_temp.replace(" ", "");
    if (str_temp != "undefined" && str_temp != "" && str_temp != "null") {
      isResult = true;
    }

    return isResult;
  }

  function trade_type_onchange() {
    var trade_type = $('#trade_type').val();
    if (trade_type == 'B2' || trade_type == 'B3') {
      // 월세...
      $('#div_trade_type_price_monthly').show();
    } else {
      $('#div_trade_type_price_monthly').hide();
    }
  }

  // 가격수정 btn
  function editPriceInfo() {
    var rcpt_product = $('#rcpt_product').val();
    var trade_type = $('#trade_type').val();

    $("#trade_type").prop("disabled", false);

    $("#rcpt_product_info2").prop("disabled", false);
    $("#rcpt_product_info3").prop("disabled", false);

    if (trade_type == "A1") {
      if (rcpt_product == 'A01' || rcpt_product == 'A02' || rcpt_product == 'A03' || rcpt_product == 'B01' || rcpt_product == 'B02' || rcpt_product == 'B03') {
        $("#rcpt_product_info4").prop("disabled", false);
        $("#rcpt_product_info5").prop("disabled", false);
      }
    }
  }

  // 가격수정 저장
  function modifyPriceInfo() {
    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        var params = {
          'rcpt_sq': '<?= $data['rcpt_sq'] ?>',
          'agent_tel': $("#agent_tel").val(),
        };

        callAjax("/article/receipt/modifyPriceInfo", params, fn_result);
      }
    });
  }

  // 연락가능전화 저장
  function fn_save_tel() {
    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        var params = {
          'rcpt_sq': '<?= $data['rcpt_sq'] ?>',
          'agent_tel': $("#agent_tel").val(),
        };

        callAjax("/article/receipt/saveAptMemo", params, fn_result);
      }
    });
  }

  // 평면도요청 저장
  function res_ground() {
    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/resGround", $("#rcptFrm").serialize(), fn_result);
      }
    });
  }

  //등록일로부터 3개월 체크
  function assign(mon, menuid) {
    var frm = document.getElementById('rcptFrm');
    var to = frm.rsrv_date.value;
    var mon_chk = mon.split("-");
    var to_chk = to.split("-");
    var date1 = new Date(mon_chk[0], mon_chk[1], mon_chk[2]).valueOf();
    var date2 = new Date(to_chk[0], to_chk[1], to_chk[2]).valueOf();
    if (date2 - date1 < 0) {
      assignRegist(menuid);
    } else {
      Swal.fire({
        title: "등록일로부터 3개월 이전만 가능합니다.",
        icon: "warning"
      })
      return;
    }
  }

  /**
 * 배정자 등록
 */
  function assignRegist(menuid) {
    var frm = document.rcptFrm;

    if (frm.rsrv_date.value == "") {
      Swal.fire({
        title: "방문희망일시를 선택해 주세요.",
        icon: "warning"
      })
      return;
    }

    var date = new Date();
    var yy = date.getFullYear();
    var mm = date.getMonth() + 1;
    var dd = date.getDate();
    if (mm < 10) mm = "0" + mm;
    if (dd < 10) dd = "0" + dd;
    var today = yy + mm + dd;
    var rsrv = frm.rsrv_date.value.replace(/-/gi, "");

    if (parseInt(today) > parseInt(rsrv)) {
      Swal.fire({
        title: "방문희망일시는 금일 이전날짜는 불가능합니다.",
        icon: "warning"
      })
      return;
    }
    if (frm.rsrv_tm_ap.value == "") {
      Swal.fire({
        title: "오전/오후를 선택해 주세요.",
        icon: "warning"
      })
      return;
    }
    if (frm.rsrv_tm_hour.value == "") {
      Swal.fire({
        title: "시간을 선택해 주세요.",
        icon: "warning"
      })
      return;
    }
    if (frm.bonbu.value == "") {
      Swal.fire({
        title: "본부를 선택해 주세요.",
        icon: "warning"
      })
      return;
    }
    if (frm.dept_sq.value == "") {
      Swal.fire({
        title: "팀을 선택해 주세요.",
        icon: "warning"
      })
      return;
    }
    if (frm.usr_sq.value == "") {
      Swal.fire({
        title: "담당자를 선택해 주세요.",
        icon: "warning"
      })
      return;
    }


    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/assignRegist", $("#rcptFrm").serialize(), fn_result);
      }
    });
  }

  // 동영상 촬영여부저장
  function requestMovie() {
    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/requestMovie", $("#rcptFrm").serialize(), fn_result);
      }
    });
  }

  // 중개사메모 저장
  function requestMessage() {
    swal.fire({
      text: "저장 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/requestMessage", $("#rcptFrm").serialize(), fn_result);
      }
    });
  }

  // 예약취소
  function rsrvcancel() {
    var stat = frm.rcpt_stat1.value;
    var cd2 = frm.result_cd2.value;

    if (stat == '70' && cd2 == '9030') {
      Swal.fire({
        title: "방문 전 취소가 불가능합니다.",
        icon: "warning"
      })
      return;
    }

    if (frm.result_cd2.value == "") {
      Swal.fire({
        title: "분류1을 선택해 주세요.",
        icon: "warning"
      })
      return;
    }
    if (frm.result_cd3.value == "") {
      Swal.fire({
        title: "분류2를 선택해 주세요.",
        icon: "warning"
      })
      return;
    }

    if (frm.result_msg.value == "") {
      Swal.fire({
        title: "취소사유를 입력해 주세요.",
        icon: "warning"
      })
      return;
    }

    swal.fire({
      text: "취소 하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/rsrvcancel", $("#rcptFrm").serialize(), fn_result);
      }
    });
  }

  // 상태변경
  function chgStatus(cd, rcpt_product, chg_floor_yn) {
    if (cd == "") return;

    var frm = document.rcptFrm;
    var i1 = frm.I1.value;					//	홍보확인서
    var i4 = frm.I4.value;					//	매물사진 
    var rr_yn = frm.req_rec_yn.value;		//녹취필요여부
    var chk_record = frm.chk_record.value;	//녹취파일 확인 체크
    var r_yn = frm.rec_yn.value;			//녹취 완료여부
    var req_rec_yn = "N";

    var rcpt_product = frm.rcpt_product.value;
    var r = '';

  }

  // 문자발송 modal
  function viewSmsPop(cd) {

    if (smsArr.length > 0) {
      var tel = "";
      if (cd == "S7" || cd == "S14") {
        tel = '<?= $data['rec_tel'] ?>';
      } else if (cd == "S10") {
        tel = '<?= $data['agent_contact_tel'] ?>';
      } else if (cd == "15") {
        tel = '<?= $data['agent_contact_tel'] ?>';
      } else {
        tel = '<?= $data['agent_head_tel'] ?>';
      }


      for (const sms of smsArr) {
        if (sms.cd == cd) {
          $("#smsForm [name=cd]").val(cd);
          $("#smsForm [name=phone]").val(tel);
          $("#smsForm [name=content]").val(sms.cd_nm);
        }
      }
    }

    $("#smsModal").modal("show");
  }

  // 문자발송
  function sendSms() {
    if ($("#smsForm [name=phone]").val() == "") {
      Swal.fire({
        title: "수신번호를 입력해 주세요.",
        icon: "warning"
      })
      return;
    }

    if ($("#smsForm [name=content]").val() == "") {
      Swal.fire({
        title: "내용을 입력해 주세요.",
        icon: "warning"
      })
      return;
    }

    swal.fire({
      text: "SMS를 발송하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        callAjax("/article/receipt/sendSms", $("#smsForm").serialize(), fn_result);
      }
    });
  }

  function showFileName(input) {
    if (input.files && input.files.length > 0) {
      document.getElementById('file_name').textContent = input.files[0].name;
    }
  }

  // 거주인 녹취정보 저장
  function saveRecInfo() {
    const rec_tel1 = $("#rec_tel1").val();
    const rec_tel2 = $("#rec_tel2").val();
    const rec_tel3 = $("#rec_tel3").val();

    if (rec_tel1 == "" || rec_tel2 == "" || rec_tel3 == "") {
      Swal.fire({
        title: "거주자 전화번호를 입력해 주세요.",
        icon: "warning"
      });

      return;
    }

    swal.fire({
      text: "거주인정보를 저장하시겠습니까?",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "예",
      cancelButtonText: "아니오",
      closeOnConfirm: false,
      closeOnCancel: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
    }).then((result) => {
      if (result.isConfirmed) {
        var form = $('#rcptFrm')[0];
        var formData = new FormData(form);

        $.ajax({
          url: "/article/receipt/saveRecInfo",
          method: 'POST',
          data: formData,
          processData: false,
          contentType: false,
          cache: false,
          beforeSend: function () {
            blockUI.blockPage({
              message: tpl
            })
          },
          complete: function () {
            blockUI.unblockPage()
          },
          success: function (result) {
            if (result.code == '0') {
              Swal.fire({
                title: "정상 처리되었습니다.",
                icon: "success",
                draggable: true
              }).then(() => {
                // 녹취파일 체크박스 활성화 및 체크
                $('#chk_record').prop('disabled', false).prop('checked', true);
              });
            } else {
              Swal.fire({
                title: result.msg,
                icon: "error",
                draggable: true
              })
            }
          }
        });
      }
    });


  }



  function fn_preview(src, type = 'img') {

    const $img = $('#imgPreview');
    const $video = $('#vdoPreview');
    const video = document.getElementById('vdoPreview');
    const source = document.getElementById('videoSource');

    if (type === 'vdo') {
      // 이미지 숨김
      $img.hide().attr('src', '');

      // video source 세팅
      source.src = src;

      // video 표시 + 로드
      $video.show();
      video.load();

      $('#previewTitle').text('동영상 미리보기');
    } else {
      // video 정지 및 초기화
      video.pause();
      source.src = '';
      video.load();
      $video.hide();

      // 이미지 표시
      $img.attr('src', src).show();

      $('#previewTitle').text('이미지 미리보기');
    }

    const modal = new bootstrap.Modal(document.getElementById('previewModal'));
    modal.show();
  }

  function callAjax(target, params, callback) {
    $.ajax({
      url: target,
      contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
      method: "POST",
      data: params,
      beforeSend: function () {
        blockUI.blockPage({
          message: tpl
        })
      },
      complete: function () {
        blockUI.unblockPage()
      },
      success: function (result) {
        callback(result);
      }
    });
  }


  function fn_result(result) {
    if (result.code == '0') {
      Swal.fire({
        title: "정상 처리되었습니다.",
        icon: "success",
        draggable: true
      })


      setTimeout(() => {
        location.reload();
      }, 1000);
    } else {
      Swal.fire({
        title: result.msg,
        icon: "error",
        draggable: true
      })
    }
  }

</script>

<?= $this->endSection() ?>