<?php
$shop = $shop ?? null;
$currentLg = $currentLg ?? null;
if ($shop === null) {
    return;
}
$v = fn ($key, $default = '') => old($key) !== null && old($key) !== '' ? old($key) : ($shop->{$key} ?? $default);
?>
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
  <span class="text-sm font-bold text-gray-700">지정판매소 수정</span>
</section>
<div class="border border-gray-300 p-4 mt-2 bg-white max-w-3xl">
  <form action="<?= base_url('admin/designated-shops/update/' . (int) $shop->ds_idx) ?>" method="POST" class="space-y-4">
    <?= csrf_field() ?>

    <?php if ($currentLg !== null): ?>
    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">지자체</label>
      <div class="text-sm">
        <span class="font-semibold"><?= esc($currentLg->lg_name) ?></span>
        <span class="text-gray-500 ml-2">(<?= esc($currentLg->lg_code) ?>)</span>
      </div>
    </div>
    <?php endif; ?>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">판매소번호</label>
      <div class="text-sm font-mono"><?= esc($shop->ds_shop_no) ?></div>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">구코드</label>
      <div class="text-sm font-mono"><?= esc($shop->ds_gugun_code) ?></div>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">상호명 <span class="text-red-500">*</span></label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-72" name="ds_name" type="text" value="<?= esc($v('ds_name')) ?>" required/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">사업자번호 <span class="text-red-500">*</span></label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-48" name="ds_biz_no" type="text" value="<?= esc($v('ds_biz_no')) ?>" required/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">대표자명 <span class="text-red-500">*</span></label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-48" name="ds_rep_name" type="text" value="<?= esc($v('ds_rep_name')) ?>" required/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">가상계좌</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="ds_va_number" type="text" value="<?= esc($v('ds_va_number')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">우편번호</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-32" name="ds_zip" type="text" value="<?= esc($v('ds_zip')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">도로명주소</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-96" name="ds_addr" type="text" value="<?= esc($v('ds_addr')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">지번주소</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-96" name="ds_addr_jibun" type="text" value="<?= esc($v('ds_addr_jibun')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">일반전화</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-48" name="ds_tel" type="text" value="<?= esc($v('ds_tel')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">대표 휴대전화</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-48" name="ds_rep_phone" type="text" value="<?= esc($v('ds_rep_phone')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">이메일</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-60" name="ds_email" type="email" value="<?= esc($v('ds_email')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">지정일자</label>
      <input class="border border-gray-300 rounded px-3 py-1.5 text-sm w-40" name="ds_designated_at" type="date" value="<?= esc($v('ds_designated_at')) ?>"/>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <label class="block text-sm font-bold text-gray-700 w-28">영업상태</label>
      <select class="border border-gray-300 rounded px-3 py-1.5 text-sm w-40" name="ds_state">
        <option value="1" <?= (string) $v('ds_state', '1') === '1' ? 'selected' : '' ?>>정상</option>
        <option value="2" <?= (string) $v('ds_state', '1') === '2' ? 'selected' : '' ?>>폐업</option>
        <option value="3" <?= (string) $v('ds_state', '1') === '3' ? 'selected' : '' ?>>직권해지</option>
      </select>
    </div>

    <div class="flex gap-2 pt-2">
      <button type="submit" class="bg-btn-search text-white px-4 py-1.5 rounded-sm text-sm shadow hover:opacity-90 transition">수정</button>
      <a href="<?= base_url('admin/designated-shops') ?>" class="bg-white text-black border border-btn-print-border px-4 py-1.5 rounded-sm text-sm shadow hover:bg-gray-50 transition">목록</a>
    </div>
  </form>
</div>
