<script lang="ts">
  import type { TaskResult } from "../models/task";
  import Progress from "./Progress.svelte";

  interface ProjectLike {
    tasks?: TaskResult[]
  }

  export let project: ProjectLike;

  let progressAmount: number;
  let progressTarget: number;

  $: progressAmount = (project.tasks||[]).map(t => t.active 
    ? Math.min(t.completedAmount, t.itemAmount) * t.item.groupWeight 
    : t.itemAmount * t.item.groupWeight
  ).reduce((n,m) => n+m, 0);
  $: progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * t.item.groupWeight).reduce((n,m) => n+m, 0), 1);
</script>

<Progress thin green count={progressAmount} target={progressTarget} />
