<script>
  import CrudPopup from '@components/admin/popup/CrudPopup.svelte';
  import { addStrikeReason, fetchStrikeReasons } from '@app/admin/strikeReasons/strikeReasons.js';

  // states
  let createPopupOpen = $state(false);

  // lifecycle
  $effect(() => {
    fetchStrikeReasons();
  });
</script>

<div>
  <button class="btn btn-soft w-full" onclick={() => (createPopupOpen = true)}>
    <span class="iconify iconify-[heroicons--plus-16-solid]"></span>
    <span>Neuer Strikegrund</span>
  </button>
</div>

<CrudPopup
  texts={{
    title: 'Strikegrund erstellen',
    submitButtonTitle: 'Erstellen',
    confirmPopupTitle: 'Strikegrund erstellen?',
    confirmPopupMessage: 'Soll der Strikegrund erstellt werden?'
  }}
  target={null}
  keys={[
    [{ key: 'name', type: 'text', label: 'Name', options: { required: true, dynamicWidth: true } }],
    [{ key: 'weight', type: 'number', label: 'Gewichtung', options: { required: true, dynamicWidth: true } }]
  ]}
  onSubmit={addStrikeReason}
  bind:open={createPopupOpen}
/>
