{{page-title @model.name}}

<PageHeader @iconName="folder">
  <div class="title">
    <h1>{{@model.name}}</h1>
    <small>{{pluralize @model.applicationsList.length "application"}}</small>
  </div>
  <Pds::CtaLink @route="workspace.projects.project.settings" @model={{@model.name}} @variant="ghost "class="pds--iconStart">
    <FlightIcon @name="settings" class="pds-button__iconStart"/>
    &nbsp;Manage settings
  </Pds::CtaLink>
</PageHeader>

{{#each @model.applicationsList as |app|}}
  <Card>
    <LinkTo @route="workspace.projects.project.app" @model={{app.name}}>
      <div class="row">
        <Hds::IconTile @icon="git-repo" />
        <div class="meta">
          <h2>{{app.name}}</h2>
        </div>
      </div>
    </LinkTo>
  </Card>
{{else}}
  {{#if (or
    (eq @model.latestInitJob.state 0)
    (eq @model.latestInitJob.state 1)
    (eq @model.latestInitJob.state 2)
    (eq @model.latestInitJob.state 3)
    (eq @model.latestInitJob.state 5)
  )}}
    {{! Remote init is UNKNOWN, QUEUED, WAITING, RUNNING, or SUCCESS }}
    <EmptyState>
      <ProjectInitRunning @project={{@model}} />
    </EmptyState>
  {{else if (eq @model.latestInitJob.state 4)}}
    {{! Remote init is ERROR }}
    <EmptyState>
      <ProjectInitError @project={{@model}} />
    </EmptyState>
  {{else}}
    {{! Local init }}
    <EmptyState>
      <p>There are no applications in this project yet</p>
      <p>To create your first application, run
        <CopyableCode @ref="empty-init" @inline="true">
          <code id="empty-init">waypoint init</code>
        </CopyableCode>
        from the CLI</p>
      <p>For more help getting started, refer to the <ExternalLink href="https://waypointproject.io/docs/getting-started">Waypoint documentation</ExternalLink></p>
    </EmptyState>
  {{/if}}
{{/each}}

{{outlet}}
