'use strict'

############################################################################################################
#
#===========================================================================================================
BRICS =

  #=========================================================================================================
  ### NOTE Future Single-File Module ###
  require_cli_table3a: ->
    #-------------------------------------------------------------------------------------------------------
    _Table                          = require 'cli-table3'
    # _Table                          = require '../../cli-table3'
    { ansi_colors_and_effects: C, } = ( require './ansi-brics' ).require_ansi_colors_and_effects()

    #-------------------------------------------------------------------------------------------------------
    templates =
      mytable:
        horizontal_lines: false
        # chars:
          # 'top':            '═'
          # 'top-mid':        '╤'
          # 'top-left':       '╔'
          # 'top-right':      '╗'
          # 'bottom':         '═'
          # 'bottom-mid':     '╧'
          # 'bottom-left':    '╚'
          # 'bottom-right':   '╝'
          # 'left':           '║'
          # 'left-mid':       '╟'
          # 'right':          '║'
          # 'right-mid':      '╢'
        # colWidths:          [11, 5, 5]
        # wordWrap:           true
        # wrapOnWordBoundary: false

        chars:
          'top':            '─'
          'top-mid':        '┬'
          'top-left':       '┌'
          'top-right':      '┐'
          'bottom':         '─'
          'bottom-mid':     '┴'
          'bottom-left':    '└'
          'bottom-right':   '┘'
          'left':           '│'
          'left-mid':       '├'
          'mid':            '─'
          'mid-mid':        '┼'
          'right':          '│'
          'right-mid':      '┤'
          'middle':         '│'
        # truncate:         '…'
        # colWidths:        []
        # rowHeights:       []
        # colAligns:        []
        # rowAligns:        []
        style:
          'padding-left':   1
          'padding-right':  1
          'head':           [ 'bold', 'brightYellow', 'bgBlue', ]
          'border':         [ 'grey', ]
          'compact':        false
        head: []

    #=======================================================================================================
    class Table extends _Table

      #-----------------------------------------------------------------------------------------------------
      constructor: ( cfg ) ->
        cfg = { templates.mytable..., cfg..., }
        super cfg
        ;undefined

      #-----------------------------------------------------------------------------------------------------
      push: ( row ) ->
        for cell, idx in row
          ### TAINT not a good solution ###
          cell        = "#{cell}"
          unless cell.startsWith '\x1b'
            row[ idx ]  = C.yellow + "#{cell}" + C.default
        row.push '' while row.length < ( @options?.head?.length ? 1 )
        return super row

      #-----------------------------------------------------------------------------------------------------
      toString: ( P... ) ->
        if ( caption = @options?.caption )?
          caption = "#{C.bg_white + C.black + C.bold} #{caption} #{C.bold0 + C.default + C.bg_default}\n"
        else
          caption = ''
        return caption + super P...

    #=======================================================================================================
    return exports = { Table, internals: { templates, }, }

#===========================================================================================================
Object.assign module.exports, BRICS

