@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Contracts.Model
@inherits FsBase
@code {

  [Parameter] public ProspectFilter Filter { get; set; } = new();
  
  [Parameter] public EventCallback<ProspectFilter> FilterChanged { get; set; }
  
  [Parameter] public ProspectStateFilter StateFilter { get; set; }


  private async Task WithoutStepInBriefingChangedAsync(bool arg)
  {
    Filter.WithoutStepInBriefing = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

  private async Task TextChanged(string arg)
  {
    Filter.Text = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

  private async Task WithoutIdCheckChangedAsync(bool arg)
  {
    Filter.WithoutIdCheck = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

  private async Task NoActivityChangedAsync(bool arg)
  {
    Filter.NoActivity = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

  private async Task DeletedOnlyChangedAsync(bool arg)
  {
    Filter.DeletedOnly = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

  private async Task RecentActivityChangedAsync(bool arg)
  {
    Filter.RecentActivity = arg;
    await FilterChanged.InvokeAsync(Filter);
  }

}

<div class="card">
  <div class="card-header" style="padding: .5rem;">
    <i class="fa-solid fa-filter"></i> Suchfilter
  </div>
  <div class="card-body" style="padding: .5rem;">
    
    @if (!AppSettings.DisableStepIn)
    {
      @* WITHOUT STEP IN BRIEFING *@
      @if (new[] { ProspectStateFilter.All, ProspectStateFilter.OnBoarding, ProspectStateFilter.Completed }.Contains(StateFilter))
      {
        <div style="margin-left: 1rem;">
          <Switch TValue="bool" Checked="Filter.WithoutStepInBriefing" CheckedChanged="WithoutStepInBriefingChangedAsync" Color="Color.Primary">Ohne @AppSettings.Terms.StepInName</Switch>
        </div>
      }
    }

    @* WITHOUT ID CHECK *@
    @if (new[] { ProspectStateFilter.All, ProspectStateFilter.Verification, ProspectStateFilter.Completed }.Contains(StateFilter))
    {
      <div style="margin-left: 1rem;">
        <Switch TValue="bool" Checked="Filter.WithoutIdCheck" CheckedChanged="WithoutIdCheckChangedAsync" Color="Color.Primary">Perso noch nicht geprüft</Switch>
      </div>
    }

    @* RECENT ACTIVITY *@
    @if (new[] { ProspectStateFilter.All, ProspectStateFilter.OnBoarding, ProspectStateFilter.Verification }.Contains(StateFilter))
    {
      <div style="margin-left: 1rem;">
        <Switch TValue="bool" Checked="Filter.RecentActivity" CheckedChanged="RecentActivityChangedAsync" Color="Color.Primary">Kürzlich geändert (&lt; 6 Monate)</Switch>
      </div>
    }
    
    @* NO ACTIVITY *@
    @if (new[] { ProspectStateFilter.All, ProspectStateFilter.OnBoarding, ProspectStateFilter.Verification }.Contains(StateFilter))
    {
      <div style="margin-left: 1rem;">
        <Switch TValue="bool" Checked="Filter.NoActivity" CheckedChanged="NoActivityChangedAsync" Color="Color.Primary">Lange keine Aktivität (&gt; 6 Monate)</Switch>
      </div>
    }

    @* DELETED ONLY *@
    @if (new[] { ProspectStateFilter.All }.Contains(StateFilter))
    {
      <div style="margin-left: 1rem;">
        <Switch TValue="bool" Checked="Filter.DeletedOnly" CheckedChanged="DeletedOnlyChangedAsync" Color="Color.Primary">Gelöschte</Switch>
      </div>
    }

    <TextEdit Text="@Filter.Text" TextChanged="TextChanged" Placeholder="Suchen..." Debounce="true" DebounceInterval="200"/>
  </div>
</div>