<script lang="ts">
  import type { ProjectResult } from "../models/project";
import type { TaskResult } from "../models/task";
  import type { ModalData } from "../stores/modal";
import projectStore from "../stores/project";
import taskStore from "../stores/tasks";
import Composition from "./Composition.svelte";
  import Option from "./Option.svelte";
  import OptionRow from "./OptionRow.svelte";
  import ParentEntry from "./ParentEntry.svelte";
  import TaskEntry from "./TaskEntry.svelte";

  export let project: ProjectResult = null;
  export let showAllOptions: boolean = false;
  export let hideInactive: boolean = false;
  export let hideProgress: boolean = false;
  export let linkProject: boolean = false;
  export let hideIcon: boolean = false;

  let mdAddTask: ModalData;
  let mdProjectEdit: ModalData;
  let mdProjectDelete: ModalData;

  $: mdAddTask = {name:"task.add", project};
  $: mdProjectEdit = {name:"project.edit", project};
  $: mdProjectDelete = {name:"project.delete", project};
</script>

<ParentEntry 
  full={showAllOptions} 
  entry={project} 
  headerLink={linkProject ? "/projects#"+project.id : ""}
  hideProgress={hideProgress}
  hideIcon={hideIcon}
  showTimeProgress={!hideProgress}
>
  {#if showAllOptions}
    <OptionRow>
      <Option open={mdAddTask}>Add Task</Option>
      <Option open={mdProjectEdit}>Edit</Option>
      <Option open={mdProjectDelete}>Delete</Option>
    </OptionRow>
  {/if}
  {#each project.tasks as task (task.id)}
    {#if !hideInactive || task.active}
      <TaskEntry showAllOptions={showAllOptions} task={task} project={project} />
    {/if}
  {/each}
</ParentEntry>