<commit_before>import { Actions, Inputs, ev, nest, unnest, clone, Interfaces, toIt } from '../../core'
import { action, vw, props, toChild, stateOf } from '../../component'
import { StyleGroup, clickable } from '../../style'
import { View, h } from '../../interfaces/view'

import * as Item from './Item'

export const name = 'Root'

export const state = {
  text: '',
  numItems: 0,
  items: {},
}

export type S = typeof state

export const inputs: Inputs<S> = ctx => ({
  action: action(actions),
  inputKeyup: ([idx, [keyCode, text]]) => {
    if (keyCode === 13 && text !== '') {
      nest(ctx, idx, props({ text })(clone(Item)))
      return [
        actions.SetText(''),
        actions.New(),
      ]
    } else {
      return actions.SetText(text)
    }
  },
  setCheckAll: (checked: boolean) => {
    let items = stateOf(ctx).items
    for (let i = 0, keys = Object.keys(items), len = keys.length; i < len; i++) {
      toChild(ctx, keys[i], 'action', ['SetChecked', checked])
    }
  },
  removeChecked: () => {
    let items = stateOf(ctx).items
    for (let i = 0, keys = Object.keys(items), len = keys.length; i < len; i++) {
      if (stateOf(ctx,  keys[i]).checked) {
        toIt(ctx, '$$Item_remove', [keys[i]])
      }
    }
  },
  $$Item_remove: idx => {
    unnest(ctx, idx)
    return actions.Remove(idx)
  },
})

export const actions: Actions<S> = {
  SetText: text => s => {
    s.text = text
    return s
  },
  New: () => s => {
    s.items[s.numItems] = s.numItems
    s.numItems++
    return s
  },
  Remove: idx => s => {
    delete s.items[idx]
    return s
  },
}

const view: View<S> = (ctx, s) => {
  let style = ctx.groups.style

  return h('div', {
    key: ctx.name,
    class: { [style.base]: true },
  }, [
    h('input', {
      class: { [style.input]: true },
      attrs: { placeholder: 'Type and hit enter' },
      props: { value: s.text },
      on: {
        keyup: ev(ctx, 'inputKeyup', s.numItems, [
          ['keyCode'],
          ['target', 'value'],
        ]),
      },<commit_msg>Fix type error in complexList<commit_after>import { Actions, Inputs, ev, nest, unnest, clone, Interfaces, toIt } from '../../core'
import { action, vw, props, toChild, stateOf } from '../../component'
import { StyleGroup, clickable } from '../../style'
import { assoc } from '../../fun'
import { View, h } from '../../interfaces/view'

import * as Item from './Item'

export const name = 'Root'

export const state = {
  text: '',
  numItems: 0,
  items: {},
}

export type S = typeof state

export const inputs: Inputs<S> = ctx => ({
  action: action(actions),
  inputKeyup: ([idx, [keyCode, text]]) => {
    if (keyCode === 13 && text !== '') {
      nest(ctx, idx, props({ text })(clone(Item)))
      return [
        actions.SetText(''),
        actions.New(),
      ]
    } else {
      return actions.SetText(text)
    }
  },
  setCheckAll: (checked: boolean) => {
    let items = stateOf(ctx).items
    let key
    for (key in items) {
      toChild(ctx, key, 'action', ['SetChecked', checked])
    }
  },
  removeChecked: () => {
    let items = stateOf(ctx).items
    let key
    for (key in items) {
      if (stateOf(ctx,  key).checked) {
        toIt(ctx, '$$Item_remove', key)
      }
    }
  },
  $$Item_remove: idx => {
    unnest(ctx, idx)
    return actions.Remove(idx)
  },
})

export const actions: Actions<S> = {
  SetText: assoc('text'),
  New: () => s => {
    s.items[s.numItems] = s.numItems
    s.numItems++
    return s
  },
  Remove: idx => s => {
    delete s.items[idx]
    return s
  },
}

const view: View<S> = (ctx, s) => {
  let style = ctx.groups.style

  return h('div', {
    key: ctx.name,
    class: { [style.base]: true },
  }, [
    h('input', {
      class: { [style.input]: true },
      attrs: { placeholder: 'Type and hit enter' },
      props: { value: s.text },
      on: {
        keyup: ev(ctx, 'inputKeyup', s.numItems, [
          ['keyCode'],
          ['target', 'value'],
        ]),
      },
{'fraction_non_alphanumeric': 0.19045226130653267, 'fraction_numerical': 0.0020100502512562816, 'mean_word_length': 2.3680203045685277, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607566', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1376, 'n_words': 365}