<commit_before>import { useEffect, useState } from 'react'
import lightTheme from 'styles/theme/light'
import darkTheme from 'styles/theme/dark'

const modes = {
  LIGHT: 'LIGHT',
  DARK: 'DARK',
}

export const useDarkMode = () => {
  // 기본은 다크모드
  const [mode, setMode] = useState(modes.DARK)
  const [theme, setTheme] = useState(darkTheme)
  const [isThemeInit, setIsThemeInit] = useState(false)

  // 로컬스토리지에 저장
  const changeMode = mode => {
    window.localStorage.setItem('theme', mode)
    setMode(mode)
    setTheme(mode === modes.LIGHT ? lightTheme : darkTheme)
  }

  const toggleTheme = () => {
    if (mode === modes.LIGHT) {
      changeMode(modes.DARK)
    } else {
      changeMode(modes.LIGHT)
    }
  }

  useEffect(() => {
    const localTheme = window.localStorage.getItem('theme')
    localTheme && changeMode(localTheme)
    setIsThemeInit(true)
  }, [])

  return { mode, theme, toggleTheme, isThemeInit }
}<commit_msg>init theme with system preference<commit_after>import { useEffect, useState } from 'react'
import lightTheme from 'styles/theme/light'
import darkTheme from 'styles/theme/dark'

const modes = {
  LIGHT: 'LIGHT',
  DARK: 'DARK',
}

export const useDarkMode = () => {
  // 기본은 다크모드
  const [mode, setMode] = useState(modes.DARK)
  const [theme, setTheme] = useState(darkTheme)
  const [isThemeInit, setIsThemeInit] = useState(false)

  // 로컬스토리지에 저장
  const changeMode = mode => {
    window.localStorage.setItem('theme', mode)
    setMode(mode)
    setTheme(mode === modes.LIGHT ? lightTheme : darkTheme)
  }

  const toggleTheme = () => {
    if (mode === modes.LIGHT) {
      changeMode(modes.DARK)
    } else {
      changeMode(modes.LIGHT)
    }
  }

  useEffect(() => {
    // 시스템 다크 모드 확인
    const isSystemDarkMode =
      window.matchMedia &&
      window.matchMedia('(prefers-color-scheme: dark)').matches

    let localTheme = window.localStorage.getItem('theme')

    if (!localTheme) {
      localTheme = isSystemDarkMode ? modes.DARK : modes.LIGHT
      window.localStorage.setItem('theme', localTheme)
    }

    changeMode(localTheme)
    setIsThemeInit(true)
  }, [])

  return { mode, theme, toggleTheme, isThemeInit }
}
{'fraction_non_alphanumeric': 0.1349862258953168, 'fraction_numerical': 0.0, 'mean_word_length': 3.4109311740890687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3086733', 'n_tokens_mistral': 764, 'n_tokens_neox': 794, 'n_words': 156}