export function useLogHeight()

in studio/hooks/use-log-height.ts [21:80]


export function useLogHeight() {
  const fileStore = useFileStore()
  const layoutStore = useLayoutStore()
  const isLogFloatingRef = ref(false)

  const setLogHeight = (height: number) => {
    layoutStore.setFileLogHeight(fileStore.getCurrentFileId, height)
  }
  const setFileLogHeight = (id: number, height: number) =>
    layoutStore.setFileLogHeight(id, height)
  const setCurrentLogHeight = () => {
    if (isLogFloatingRef.value) return
    layoutStore.setLogHeightByFileId(fileStore.getCurrentFileId)
  }
  const getLogMaxHeight = () => layoutStore.getLogMaxHeight
  const getLogMinHeight = () => layoutStore.getLogMinHeight
  const getLogHeight = () => layoutStore.getLogHeight
  const getEditorHeight = () => layoutStore.getEditorHeight
  const setEditorHeight = (height: number) => {
    layoutStore.setEditorHeight(height)
  }
  const toggleLogUpAndDown = () => {
    const logHeight =
      layoutStore.getLogHeight === layoutStore.getLogMinHeight
        ? layoutStore.getLogMaxHeight
        : layoutStore.getLogMinHeight
    setLogHeight(logHeight)
  }
  const toggleLog = () => {
    if (isLogFloatingRef.value) return
    if (layoutStore.logHeight) {
      layoutStore.setPrevLogHeight(layoutStore.logHeight)
    }
    const logHeight = layoutStore.logHeight ? 0 : layoutStore.getPrevLogHeight
    setLogHeight(logHeight)
  }
  const toggleFloatingLogHeight = (logFloating: boolean) => {
    isLogFloatingRef.value = logFloating
    if (logFloating) {
      layoutStore.setLogHeight(0)
    } else {
      setCurrentLogHeight()
    }
  }

  return {
    setLogHeight,
    setFileLogHeight,
    getLogHeight,
    getLogMaxHeight,
    getLogMinHeight,
    getEditorHeight,
    isLogFloatingRef,
    setCurrentLogHeight,
    toggleLogUpAndDown,
    toggleLog,
    setEditorHeight,
    toggleFloatingLogHeight
  }
}