<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php echo form_hidden('rel_id', $id); ?>
<?php echo form_hidden('rel_type', $name); ?>
<?php echo render_datetime_input('date', 'Start date', '', array('data-date-min-date' => _d(date('Y-m-d')), 'data-step' => 30)); ?>
<?php echo render_datetime_input('end_date', '<span style="color:red;">*</span> End date', '', array('data-date-min-date' => _d(date('Y-m-d')), 'data-step' => 30, 'required' => 'required')); ?>
<?php if (is_admin()) { ?>
  <div style="display: none;">
  <?php echo render_select('staff[]', $members, array('staffid', array('firstname', 'lastname')), 'reminder_set_to', get_staff_user_id(), array('data-current-staff' => get_staff_user_id(), 'multiple' => 'multiple'), [], '', '', false); ?>
  <!-- <input type="hidden" name="staff" value="<?php echo get_staff_user_id(); ?>"> -->
  </div>
  <?php } else { ?>
  <input type="hidden" name="staff[]" value="<?php echo get_staff_user_id(); ?>">
<?php } ?>
<?php echo render_select('state_id', $state_data, array('id', array('state_name')), 'Location', $selected, ['required' => 'required']); ?>
<div class="form-group" style="display:none;" id="new_state_toggle">
  <label><span style="color:red;">*</span> Add new state</label>
  <input type="text" class="form-control" id="new_state" name="new_state">
</div>
<!-- multiple selection -->
<!-- <?php echo render_select('state_id[]', $state_data, array('id', array('state_name')), 'State', $selected, ['data-width' => '100%', 'data-none-selected-text' => _l('leads_all'), 'multiple' => true, 'data-actions-box' => true]); ?> -->
<?php /* echo render_textarea('email_note', 'Email note/Zoom link.'); */?>
<?php echo render_textarea('description', 'Special notes for meeting'); ?>
<?php if (is_email_template_active('reminder-email-staff')) { ?>
  <!-- <div class="form-group">
    <div class="checkbox checkbox-primary">
      <input type="hidden" name="notify_by_email" id="notify_by_email" value="on">
      <label for="notify_by_email"><?php echo 'Send also an email and notification for this reminder'; ?></label>
    </div>
  </div> -->
  <input type="hidden" name="notify_by_email" id="notify_by_email" value="on">
<?php } ?>
<script>
  document.getElementById('state_id').addEventListener('change', function () {
    var stateDropdown = document.getElementById('state_id');
    var selectedValue = stateDropdown.options[stateDropdown.selectedIndex].value;
    var newStateInput = document.getElementById('new_state_toggle');
    if (selectedValue == '1000') {
      newStateInput.style.display = 'block';
    } else {
      newStateInput.style.display = 'none';
      document.getElementById('new_state').value = '';
    }
  });
  $('#date').on('change', function () {
    var selectedDate = new Date($(this).val());
    if (!isNaN(selectedDate.getTime())) {
      selectedDate.setMinutes(selectedDate.getMinutes() + 30);
      var year = selectedDate.getFullYear();
      var month = ('0' + (selectedDate.getMonth() + 1)).slice(-2);
      var day = ('0' + selectedDate.getDate()).slice(-2);
      var hours = ('0' + selectedDate.getHours()).slice(-2);
      var minutes = ('0' + selectedDate.getMinutes()).slice(-2);
      var formattedDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
      $('input[name="end_date"]').val(formattedDate);
    }
  });
</script>