<?php
$relatedType = (string) ($relatedType ?? '');
$relatedId = (int) ($relatedId ?? 0);
$types = $types ?? [
    'note' => 'Note',
    'call' => 'Call',
    'email' => 'Email',
    'meeting' => 'Meeting',
];
$formClass = $formClass ?? '';
if (!can_see('tasks') || $relatedType === '' || $relatedId < 1) {
    return;
}
?>
<form class="record-composer is-activity ajax-form mb-3 <?= e($formClass) ?>" action="<?= e(url('activities')) ?>" method="post" enctype="multipart/form-data">
  <?= csrf_field() ?>
  <input type="hidden" name="related_type" value="<?= e($relatedType) ?>">
  <input type="hidden" name="related_id" value="<?= $relatedId ?>">
  <div class="record-composer-head">
    <span class="record-composer-icon"><i class="bi bi-chat-dots"></i></span>
    <div>
      <div class="record-composer-title">Log activity</div>
      <div class="record-composer-sub">Note, call, or meeting. Attach a file if you need it.</div>
    </div>
  </div>
  <div class="record-composer-grid">
    <div>
      <label class="form-label" for="act-type-<?= e($relatedType) ?>-<?= $relatedId ?>">Type</label>
      <select class="form-select" id="act-type-<?= e($relatedType) ?>-<?= $relatedId ?>" name="type">
        <?php foreach ($types as $value => $label): ?>
          <option value="<?= e((string) $value) ?>"><?= e($label) ?></option>
        <?php endforeach; ?>
      </select>
    </div>
    <div>
      <label class="form-label" for="act-subject-<?= e($relatedType) ?>-<?= $relatedId ?>">What happened? *</label>
      <input class="form-control" id="act-subject-<?= e($relatedType) ?>-<?= $relatedId ?>" name="subject" placeholder="Short summary" required>
    </div>
    <div class="record-composer-span">
      <label class="form-label" for="act-body-<?= e($relatedType) ?>-<?= $relatedId ?>">Details</label>
      <textarea class="form-control" id="act-body-<?= e($relatedType) ?>-<?= $relatedId ?>" name="body" rows="2" placeholder="Optional notes"></textarea>
    </div>
    <div class="record-composer-span">
      <label class="form-label">File</label>
      <label class="record-file">
        <i class="bi bi-paperclip"></i>
        <span class="record-file-copy">
          <span class="record-file-name">Choose a file</span>
          <span class="record-file-hint">PDF, Word, JPEG, or PNG · up to 8 MB</span>
        </span>
        <input type="file" name="file" accept=".pdf,.doc,.docx,.jpg,.jpeg,.png,application/pdf,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
      </label>
    </div>
  </div>
  <div class="record-composer-actions">
    <button class="btn btn-primary" type="submit"><i class="bi bi-plus-lg"></i> Add activity</button>
  </div>
</form>
