import { defineConfig, presetUno } from 'unocss'

const DIRECTION_MAPPIINGS = { t: 'top', r: 'right', b: 'bottom', l: 'left' }

export default defineConfig({
  presets: [presetUno],
  rules: [
    [
      /^b(t|r|b|l|d)-(.*)/,
      ([, d, c]) => {
        const direction = DIRECTION_MAPPIINGS[d] || ''
        const p = direction ? `border-${direction}` : 'border'
        const attrs = c.split('_')
        if (
          // 属性中不包含 border-style 则默认 solid
          !attrs.some((item) =>
            /^(none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset)$/.test(item),
          )
        ) {
          attrs.push('solid')
        }
        // 属性中不包含 border-width 则默认 1px
        if (!attrs.some((item) => /^\d/.test(item))) {
          attrs.push('1px')
        }
        return {
          [p]: attrs.join(' '),
        }
      },
    ],
  ],
})
