<div class="card" style="max-width:760px">
  <div class="card-body">
    <form method="post" action="<?= url('/tickets') ?>" enctype="multipart/form-data">
      <?= csrf_field() ?>

      <div class="form-row">
        <div class="form-group">
          <label>Requester <span class="req">*</span></label>
          <select name="contact_id" required>
            <option value="">Select a contact…</option>
            <?php foreach ($contacts as $c) : ?>
              <option value="<?= $c['id'] ?>"><?= e($c['customer_name']) ?> — <?= e($c['name']) ?> (<?= e($c['email']) ?>)</option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="form-group">
          <label>Channel <span class="req">*</span></label>
          <select name="channel" required>
            <option value="Telephone">Telephone</option>
            <option value="Walk-in">Walk-in</option>
            <option value="Email">Email</option>
            <option value="Internal">Internal</option>
          </select>
        </div>
      </div>

      <div class="form-row">
        <div class="form-group">
          <label>Product / Module <span class="req">*</span></label>
          <select name="product_id" required>
            <?php foreach ($products as $p) : ?>
              <option value="<?= $p['id'] ?>"><?= e($p['name']) ?> — <?= e($p['module']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="form-group">
          <label>Category <span class="req">*</span></label>
          <select name="category_id" required>
            <?php foreach ($categories as $c) : ?>
              <option value="<?= $c['id'] ?>"><?= $c['parent_id'] ? '— ' : '' ?><?= e($c['name']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
      </div>

      <div class="form-row">
        <div class="form-group">
          <label>Priority <span class="req">*</span></label>
          <select name="priority_id" required>
            <?php foreach ($priorities as $p) : ?>
              <option value="<?= $p['id'] ?>"><?= e($p['code']) ?> — <?= e($p['name']) ?>: <?= e($p['definition']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="form-group">
          <label>Severity</label>
          <select name="severity">
            <option>Business stopped</option>
            <option selected>Minor impact</option>
            <option>Major impact</option>
            <option>Cosmetic</option>
          </select>
        </div>
      </div>

      <div class="form-group">
        <label>Subject <span class="req">*</span></label>
        <input type="text" name="subject" maxlength="200" required>
      </div>
      <div class="form-group">
        <label>Description <span class="req">*</span></label>
        <textarea name="description" rows="6" required placeholder="What the customer reported, in their words…"></textarea>
      </div>
      <div class="form-group">
        <label>Attachments</label>
        <input type="file" name="attachments[]" multiple data-file-preview="#att-preview-create">
        <div id="att-preview-create" class="help-text"></div>
      </div>

      <div class="flex justify-between mt-3">
        <a href="<?= url('/tickets') ?>" class="btn">Cancel</a>
        <button type="submit" class="btn btn-primary">Create ticket</button>
      </div>
    </form>
  </div>
</div>
