<!--
// Copyright © 2020 Anticrm Platform Contributors.
// 
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
  import { createEventDispatcher } from 'svelte'
  import type { IntlString } from '@anticrm/platform'
  import CheckBoxWithLabel from './CheckBoxWithLabel.svelte'
  import Label from './Label.svelte'
  import Add from './icons/Add.svelte'

  export let label: IntlString
  export let items: Array<Object>
  = [
    { description: '15 minute phone call', done: true },
    { description: 'Follow up email', done: false },
    { description: 'First round interview', done: false },
    { description: 'Follow up email', done: false },
    { description: 'Second round interview', done: false },
    { description: 'Third round interview', done: false },
  ]
  export let editable: boolean = false

  const dispatch = createEventDispatcher()
</script>

<div class="checkbox-list">
  {#each items as item}
    <div class="list-item">
      <CheckBoxWithLabel
        bind:label={item.description}
        bind:checked={item.done}
        {editable}
        on:change={() => {
          dispatch('change', item)
        }}
      />
    </div>
  {/each}
  <div
    class="add-item"
    on:click={() => {
      items.push({ description: 'New item', done: false })
      items = items
    }}
  >
    <div class="icon"><Add size={'small'} /></div>
    <div class="label"><Label {label} /></div>
  </div>
</div>

<style lang="scss">
  .checkbox-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin: 0 1rem;

    .list-item + .list-item { margin-top: 1.25rem; }

    .add-item {
      display: flex;
      align-items: center;
      margin-top: 1.25rem;
      cursor: pointer;

      .icon { opacity: .6; }
      .label {
        margin-left: 1rem;
        color: var(--theme-content-color);
      }
      &:hover {
        .icon { opacity: 1; }
        .label { color: var(--theme-caption-color); }
      }
    }
  }
</style>
