{"version":3,"file":"use-move.mjs","names":[],"sources":["../../../../../../../packages/components/transfer/src/composables/use-move.ts"],"sourcesContent":["import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { usePropsAlias } from './use-props-alias'\n\nimport type { SetupContext } from 'vue'\nimport type {\n  TransferCheckedState,\n  TransferDataItem,\n  TransferDirection,\n  TransferEmits,\n  TransferKey,\n  TransferProps,\n} from '../transfer'\n\nexport const useMove = (\n  props: Required<\n    Omit<TransferProps, 'filterPlaceholder' | 'filterMethod' | 'renderContent'>\n  >,\n  checkedState: TransferCheckedState,\n  emit: SetupContext<TransferEmits>['emit']\n) => {\n  const propsAlias = usePropsAlias(props)\n\n  const _emit = (\n    value: TransferKey[],\n    direction: TransferDirection,\n    movedKeys: TransferKey[]\n  ) => {\n    emit(UPDATE_MODEL_EVENT, value)\n    emit(CHANGE_EVENT, value, direction, movedKeys)\n  }\n\n  const addToLeft = () => {\n    const currentValue = props.modelValue.slice()\n\n    checkedState.rightChecked.forEach((item) => {\n      const index = currentValue.indexOf(item)\n      if (index > -1) {\n        currentValue.splice(index, 1)\n      }\n    })\n    _emit(currentValue, 'left', checkedState.rightChecked)\n  }\n\n  const addToRight = () => {\n    let currentValue = props.modelValue.slice()\n\n    const itemsToBeMoved = props.data\n      .filter((item: TransferDataItem) => {\n        const itemKey = item[propsAlias.value.key]\n        return (\n          checkedState.leftChecked.includes(itemKey) &&\n          !props.modelValue.includes(itemKey)\n        )\n      })\n      .map((item) => item[propsAlias.value.key])\n\n    currentValue =\n      props.targetOrder === 'unshift'\n        ? itemsToBeMoved.concat(currentValue)\n        : currentValue.concat(itemsToBeMoved)\n\n    if (props.targetOrder === 'original') {\n      currentValue = props.data\n        .filter((item) => currentValue.includes(item[propsAlias.value.key]))\n        .map((item) => item[propsAlias.value.key])\n    }\n\n    _emit(currentValue, 'right', checkedState.leftChecked)\n  }\n\n  return {\n    addToLeft,\n    addToRight,\n  }\n}\n"],"mappings":";;;;AAaA,MAAa,WACX,OAGA,cACA,SACG;CACH,MAAM,aAAa,cAAc,MAAM;CAEvC,MAAM,SACJ,OACA,WACA,cACG;AACH,OAAK,oBAAoB,MAAM;AAC/B,OAAK,cAAc,OAAO,WAAW,UAAU;;CAGjD,MAAM,kBAAkB;EACtB,MAAM,eAAe,MAAM,WAAW,OAAO;AAE7C,eAAa,aAAa,SAAS,SAAS;GAC1C,MAAM,QAAQ,aAAa,QAAQ,KAAK;AACxC,OAAI,QAAQ,GACV,cAAa,OAAO,OAAO,EAAE;IAE/B;AACF,QAAM,cAAc,QAAQ,aAAa,aAAa;;CAGxD,MAAM,mBAAmB;EACvB,IAAI,eAAe,MAAM,WAAW,OAAO;EAE3C,MAAM,iBAAiB,MAAM,KAC1B,QAAQ,SAA2B;GAClC,MAAM,UAAU,KAAK,WAAW,MAAM;AACtC,UACE,aAAa,YAAY,SAAS,QAAQ,IAC1C,CAAC,MAAM,WAAW,SAAS,QAAQ;IAErC,CACD,KAAK,SAAS,KAAK,WAAW,MAAM,KAAK;AAE5C,iBACE,MAAM,gBAAgB,YAClB,eAAe,OAAO,aAAa,GACnC,aAAa,OAAO,eAAe;AAEzC,MAAI,MAAM,gBAAgB,WACxB,gBAAe,MAAM,KAClB,QAAQ,SAAS,aAAa,SAAS,KAAK,WAAW,MAAM,KAAK,CAAC,CACnE,KAAK,SAAS,KAAK,WAAW,MAAM,KAAK;AAG9C,QAAM,cAAc,SAAS,aAAa,YAAY;;AAGxD,QAAO;EACL;EACA;EACD"}