<?php
$is_edit = isset($store) && $store;
$action  = $is_edit ? site_url('store/update/' . $store->id) : site_url('store/store');
?>
<div class="card" style="max-width:520px;">
  <?= form_open($action) ?>

  <div class="form-group">
    <label>Nama Toko <span style="color:red">*</span></label>
    <input type="text" name="name" class="form-control"
      value="<?= htmlspecialchars(set_value('name', $store->name ?? '')) ?>"
      placeholder="Contoh: Warung Kopi Saya"
      required maxlength="100">
    <?= form_error('name', '<p class="text-danger" style="color:#D32F2F; font-size:12px; margin-top:4px;">', '</p>') ?>
  </div>

  <div class="form-group">
    <label>Alamat</label>
    <input type="text" name="address" class="form-control"
      value="<?= htmlspecialchars(set_value('address', $store->address ?? '')) ?>"
      placeholder="Jl. Contoh No. 1, Kota"
      maxlength="255">
  </div>

  <div class="form-group">
    <label>Nomor Telepon</label>
    <input type="text" name="phone" class="form-control"
      value="<?= htmlspecialchars(set_value('phone', $store->phone ?? '')) ?>"
      placeholder="08xxxxxxxxxx"
      maxlength="30">
  </div>

  <div class="form-group">
    <label>Teks Footer Struk</label>
    <input type="text" name="footer_text" class="form-control"
      value="<?= htmlspecialchars(set_value('footer_text', $store->footer_text ?? 'Terima kasih atas kunjungan Anda')) ?>"
      placeholder="Pesan yang tampil di bawah struk"
      maxlength="255">
  </div>

  <div class="form-actions">
    <button type="submit" class="btn btn-primary">
      <?= $is_edit ? '💾 Simpan Perubahan' : '+ Simpan Toko' ?>
    </button>
    <a href="<?= site_url('store') ?>" class="btn btn-light">Batal</a>
  </div>

  <?= form_close() ?>
</div>
