import { GraphSubComponentSpec } from '../../types'

export const SET_SUB_COMPONENT = 'COMPONENT_SET_SUB_COMPONENT'
export const SET_SUB_COMPONENT_CHILDREN = 'COMPONENT_SET_SUB_COMPONENT_CHILDREN'
export const APPEND_SUB_COMPONENT_CHILDREN =
  'COMPONENT_APPEND_SUB_COMPONENT_CHILDREN'
export const REMOVE_SUB_COMPONENT_CHILDREN =
  'COMPONENT_REMOVE_SUB_COMPONENT_CHILDREN'
export const REMOVE_SUB_COMPONENT = 'COMPONENT_REMOVE_SUB_COMPONENT'
export const SET_SIZE = 'COMPONENT_SET_SIZE'
export const REORDER_SUB_COMPONENT = 'COMPONENT_REORDER_SUB_COMPONENT'

export const makeSetSubComponentAction = (
  id: string,
  spec: GraphSubComponentSpec
) => {
  return {
    type: SET_SUB_COMPONENT,
    data: {
      id,
      spec,
    },
  }
}

export const makeSetSubComponentChildrenAction = (
  id: string,
  children: string[]
) => {
  return {
    type: SET_SUB_COMPONENT,
    data: {
      id,
      children,
    },
  }
}

// TODO
export const wrapAppendSubComponentChildrenAction = (data: any) => {
  return {
    type: APPEND_SUB_COMPONENT_CHILDREN,
    data,
  }
}

export const makeAppendSubComponentChildrenAction = (
  id: string,
  slotName: string,
  children: string[]
) => {
  return wrapAppendSubComponentChildrenAction({
    id,
    slotName,
    children,
  })
}

export const makeRemoveSubComponentChildrenAction = (
  id: string,
  children: string[]
) => {
  return {
    type: REMOVE_SUB_COMPONENT_CHILDREN,
    data: {
      id,
      children,
    },
  }
}

export const makeRemoveSubComponentAction = (id: string) => {
  return {
    type: REMOVE_SUB_COMPONENT,
    data: {
      id,
    },
  }
}

export const makeSetSizeAction = (
  id: string,
  width: number,
  height: number
) => {
  return {
    type: SET_SIZE,
    data: {
      id,
      width,
      height,
    },
  }
}

export const makeReorderSubComponentAction = (
  parentId: string | null,
  childId: string,
  from: number,
  to: number
) => {
  return {
    type: REORDER_SUB_COMPONENT,
    data: {
      parentId,
      childId,
      from,
      to,
    },
  }
}
