<commit_before>module Draw.ManageAttachments
  ( drawManageAttachments
  )
where

import           Prelude ()
import           Prelude.MH

import           Brick
import           Brick.Widgets.List
import           Brick.Widgets.Center
import           Brick.Widgets.Border
import qualified Brick.Widgets.FileBrowser as FB
import           Lens.Micro.Platform ( (^.) )

import           Types
import           Themes
import           Draw.Main ( drawMain )


drawManageAttachments :: ChatState -> [Widget Name]
drawManageAttachments st =
    topLayer : drawMain st
    where
        topLayer = case appMode st of
            ManageAttachments -> drawAttachmentList st
            ManageAttachmentsBrowseFiles -> drawFileBrowser st
            _ -> error "BUG: drawManageAttachments called in invalid mode"

drawAttachmentList :: ChatState -> Widget Name
drawAttachmentList st =
    centerLayer $
    hLimit 60 $
    vLimit 15 $
    joinBorders $
    borderWithLabel (txt "Attachments") $
    vBox [ renderList renderAttachmentItem True (st^.csEditState.cedAttachmentList)
         , hBorder
         , hCenter $ withDefAttr clientMessageAttr $
                     txt "n:new d:delete"
         ]

renderAttachmentItem :: Bool -> AttachmentData -> Widget Name
renderAttachmentItem _ d =
    padRight Max $ str $ FB.fileInfoSanitizedFilename $ attachmentDataFileInfo d

drawFileBrowser :: ChatState -> Widget Name
drawFileBrowser st =
    centerLayer $
    hLimit 60 $
    vLimit 20 $
    borderWithLabel (txt "Find file") $
    FB.renderFileBrowser True (st^.csEditState.cedFileBrowser)<commit_msg>UI nit<commit_after>module Draw.ManageAttachments
  ( drawManageAttachments
  )
where

import           Prelude ()
import           Prelude.MH

import           Brick
import           Brick.Widgets.List
import           Brick.Widgets.Center
import           Brick.Widgets.Border
import qualified Brick.Widgets.FileBrowser as FB
import           Lens.Micro.Platform ( (^.) )

import           Types
import           Themes
import           Draw.Main ( drawMain )


drawManageAttachments :: ChatState -> [Widget Name]
drawManageAttachments st =
    topLayer : drawMain st
    where
        topLayer = case appMode st of
            ManageAttachments -> drawAttachmentList st
            ManageAttachmentsBrowseFiles -> drawFileBrowser st
            _ -> error "BUG: drawManageAttachments called in invalid mode"

drawAttachmentList :: ChatState -> Widget Name
drawAttachmentList st =
    centerLayer $
    hLimit 60 $
    vLimit 15 $
    joinBorders $
    borderWithLabel (txt "Attachments") $
    vBox [ renderList renderAttachmentItem True (st^.csEditState.cedAttachmentList)
         , hBorder
         , hCenter $ withDefAttr clientMessageAttr $
                     txt "n:new d:delete"
         ]

renderAttachmentItem :: Bool -> AttachmentData -> Widget Name
renderAttachmentItem _ d =
    padRight Max $ str $ FB.fileInfoSanitizedFilename $ attachmentDataFileInfo d

drawFileBrowser :: ChatState -> Widget Name
drawFileBrowser st =
    centerLayer $
    hLimit 60 $
    vLimit 20 $
    borderWithLabel (txt "Attach File") $
    FB.renderFileBrowser True (st^.csEditState.cedFileBrowser)
{'fraction_non_alphanumeric': 0.06581009088060169, 'fraction_numerical': 0.005014102162331557, 'mean_word_length': 2.546666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '900528', 'n_tokens_mistral': 913, 'n_tokens_neox': 895, 'n_words': 232}