{"version":3,"file":"ThreadListSlot.mjs","names":[],"sources":["../../../../src/plugins/SlotLayout/ThreadListSlot.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\nimport { createChatViewSlotBinding, getChatViewEntityBinding } from './slotBinding';\nimport { useChatViewContext } from './ChatView';\nimport { useLayoutViewState } from './hooks/useLayoutViewState';\nimport { Slot } from './layout/Slot';\n\nimport type { PropsWithChildren, ReactNode } from 'react';\nimport type { SlotName } from './layoutController/layoutControllerTypes';\n\nexport type ThreadListSlotProps = PropsWithChildren<{\n  fallback?: ReactNode;\n  slot?: SlotName;\n}>;\n\nconst LIST_BINDING_KEY = 'thread-list';\nconst LIST_ENTITY_KIND = 'threadList';\n\nexport const ThreadListSlot = ({\n  children,\n  fallback = null,\n  slot,\n}: ThreadListSlotProps) => {\n  const { layoutController } = useChatViewContext();\n  const { availableSlots, slotBindings } = useLayoutViewState();\n\n  const requestedSlot = slot && availableSlots.includes(slot) ? slot : undefined;\n  const existingListSlot = availableSlots.find(\n    (candidate) =>\n      getChatViewEntityBinding(slotBindings[candidate])?.kind === LIST_ENTITY_KIND,\n  );\n  const firstFreeSlot = availableSlots.find((candidate) => !slotBindings[candidate]);\n  const listSlot =\n    requestedSlot ?? existingListSlot ?? firstFreeSlot ?? availableSlots[0];\n\n  useEffect(() => {\n    if (!listSlot) return;\n\n    if (requestedSlot && existingListSlot && existingListSlot !== requestedSlot) {\n      layoutController.release(existingListSlot);\n    }\n\n    const existingEntity = getChatViewEntityBinding(slotBindings[listSlot]);\n    if (existingEntity?.kind === LIST_ENTITY_KIND) {\n      return;\n    }\n\n    layoutController.bind(\n      listSlot,\n      createChatViewSlotBinding({\n        key: LIST_BINDING_KEY,\n        kind: LIST_ENTITY_KIND,\n        source: {},\n      }),\n    );\n  }, [existingListSlot, layoutController, listSlot, requestedSlot, slotBindings]);\n\n  if (!listSlot) return <>{fallback}</>;\n\n  return <Slot slot={listSlot}>{children ?? fallback}</Slot>;\n};\n"],"mappings":";;;;;;;AAeA,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAEzB,IAAa,kBAAkB,EAC7B,UACA,WAAW,MACX,WACyB;CACzB,MAAM,EAAE,qBAAqB,mBAAmB;CAChD,MAAM,EAAE,gBAAgB,iBAAiB,mBAAmB;CAE5D,MAAM,gBAAgB,QAAQ,eAAe,SAAS,IAAI,IAAI,OAAO,KAAA;CACrE,MAAM,mBAAmB,eAAe,MACrC,cACC,yBAAyB,aAAa,UAAU,CAAC,EAAE,SAAS,gBAChE;CACA,MAAM,gBAAgB,eAAe,MAAM,cAAc,CAAC,aAAa,UAAU;CACjF,MAAM,WACJ,iBAAiB,oBAAoB,iBAAiB,eAAe;CAEvE,gBAAgB;EACd,IAAI,CAAC,UAAU;EAEf,IAAI,iBAAiB,oBAAoB,qBAAqB,eAC5D,iBAAiB,QAAQ,gBAAgB;EAI3C,IADuB,yBAAyB,aAAa,SACzD,CAAA,EAAgB,SAAS,kBAC3B;EAGF,iBAAiB,KACf,UACA,0BAA0B;GACxB,KAAK;GACL,MAAM;GACN,QAAQ,CAAC;EACX,CAAC,CACH;CACF,GAAG;EAAC;EAAkB;EAAkB;EAAU;EAAe;CAAY,CAAC;CAE9E,IAAI,CAAC,UAAU,OAAO,oBAAA,YAAA,EAAA,UAAG,SAAW,CAAA;CAEpC,OAAO,oBAAC,MAAD;EAAM,MAAM;YAAW,YAAY;CAAe,CAAA;AAC3D"}