<template>
  <div class="text-style-panel">
    <div class="preset-style">
      <div 
        class="preset-style-item"
        v-for="item in presetStyles"
        :key="item.label"
        :style="item.style"
        @click="emitBatchRichTextCommand(item.cmd)"
      >{{item.label}}</div>
    </div>
    
    <Divider v-if="mode==1" />
    <div v-if="mode==1" class="row items-center">
      <div class="col">图层名称：</div>
      <el-input style="width:60%;" v-model="layerName" @input="updateLayerName"></el-input>
    </div>
    

    <ElementDataMapping v-if="mode==0||mode==2"></ElementDataMapping>

    <Divider />
    
    <SelectGroup class="row formatFontsBox">
      <span class="selectText">
        <el-select v-model="richTextAttrs.fontname" placeholder="" filterable
        @change="emitRichTextCommand('fontname', richTextAttrs.fontname)">
          <el-option
              v-for="item in formatFonts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :style="{'font-family':item.reduce!=''?item.reduce:item.label}"
          />
        </el-select>
      </span>
      <span class="selectTextInput">
        <el-autocomplete
          v-model="fontsize"
          :fetch-suggestions="(queryString: string, cb: any)=>querySearchFont(queryString,cb,'fontsize')"
          class="inline-input w-50"
          placeholder="字号"
          @select="handleSelect('fontsize')"
          @blur="handleSelect('fontsize')"
          @keyup.enter="handleSelect('fontsize')">
          <template #suffix>
            <IconAddText />
          </template>
      </el-autocomplete>
      </span>
      <!-- <Select
        class="font-select"
        style="width: 60%;"
        :value="richTextAttrs.fontname"
        @update:value="value => emitRichTextCommand('fontname', value as string)"
        :options="[
          ...formatFonts
        ]"
      >
        <template #icon>
          <IconFontSize />
        </template>
      </Select>
      <Select
        style="width: 40%;"
        :value="richTextAttrs.fontsize"
        @update:value="value => emitRichTextCommand('fontsize', value as string)"
        :options="fontSizeOptions.map(item => ({
          label: item, value: item
        }))"
      >
        <template #icon>
          <IconAddText />
        </template>
      </Select> -->
    </SelectGroup>

    <ButtonGroup class="row" passive>
      <Popover trigger="click" style="width: 30%;">
        <template #content>
          <ColorPicker
            :modelValue="richTextAttrs.color"
            @update:modelValue="value => emitRichTextCommand('color', value)"
          />
        </template>
        <TextColorButton first v-tooltip="'文字颜色'" :color="richTextAttrs.color">
          <IconText />
        </TextColorButton>
      </Popover>
      <Popover trigger="click" style="width: 30%;">
        <template #content>
          <ColorPicker
            :modelValue="richTextAttrs.backcolor"
            @update:modelValue="value => emitRichTextCommand('backcolor', value)"
          />
        </template>
        <TextColorButton v-tooltip="'文字高亮'" :color="richTextAttrs.backcolor">
          <IconHighLight />
        </TextColorButton>
      </Popover>
      <Button 
        class="font-size-btn"
        style="width: 20%;"
        v-tooltip="'增大字号'"
        @click="emitRichTextCommand('fontsize-add')"
      ><IconFontSize />+</Button>
      <Button
        last
        class="font-size-btn"
        style="width: 20%;"
        v-tooltip="'减小字号'"
        @click="emitRichTextCommand('fontsize-reduce')"
      ><IconFontSize />-</Button>
    </ButtonGroup>

    <ButtonGroup class="row">
      <CheckboxButton 
        style="flex: 1;"
        :checked="richTextAttrs.bold"
        v-tooltip="'加粗'"
        @click="emitRichTextCommand('bold')"
      ><IconTextBold /></CheckboxButton>
      <CheckboxButton 
        style="flex: 1;"
        :checked="richTextAttrs.em"
        v-tooltip="'斜体'"
        @click="emitRichTextCommand('em')"
      ><IconTextItalic /></CheckboxButton>
      <CheckboxButton 
        style="flex: 1;"
        :checked="richTextAttrs.underline"
        v-tooltip="'下划线'"
        @click="emitRichTextCommand('underline')"
      ><IconTextUnderline /></CheckboxButton>
      <CheckboxButton 
        style="flex: 1;"
        :checked="richTextAttrs.strikethrough"
        v-tooltip="'删除线'"
        @click="emitRichTextCommand('strikethrough')"
      ><IconStrikethrough /></CheckboxButton>
    </ButtonGroup>

    <ButtonGroup class="row">
      <CheckboxButton
        style="flex: 1;"
        :checked="richTextAttrs.superscript"
        v-tooltip="'上标'"
        @click="emitRichTextCommand('superscript')"
      >A²</CheckboxButton>
      <CheckboxButton
        style="flex: 1;"
        :checked="richTextAttrs.subscript"
        v-tooltip="'下标'"
        @click="emitRichTextCommand('subscript')"
      >A₂</CheckboxButton>
      <CheckboxButton
        style="flex: 1;"
        :checked="richTextAttrs.code"
        v-tooltip="'行内代码'"
        @click="emitRichTextCommand('code')"
      ><IconCode /></CheckboxButton>
      <CheckboxButton
        style="flex: 1;"
        :checked="richTextAttrs.blockquote"
        v-tooltip="'引用'"
        @click="emitRichTextCommand('blockquote')"
      ><IconQuote /></CheckboxButton>
    </ButtonGroup>

    <ButtonGroup class="row" passive>
      <CheckboxButton
        first
        style="flex: 1;"
        v-tooltip="'清除格式'"
        @click="emitRichTextCommand('clear')"
      ><IconFormat /></CheckboxButton>
      <CheckboxButton
        style="flex: 1;"
        :checked="!!textFormatPainter"
        v-tooltip="'格式刷（双击连续使用）'"
        @click="toggleTextFormatPainter()"
        @dblclick="toggleTextFormatPainter(true)"
      ><IconFormatBrush /></CheckboxButton>
      <Popover placement="bottom-end" trigger="click" v-model:value="linkPopoverVisible" style="width: 33.33%;">
        <template #content>
          <div class="link-popover">
            <Input v-model:value="link" placeholder="请输入超链接" />
            <div class="btns">
              <Button size="small" :disabled="!richTextAttrs.link" @click="updateLink()" style="margin-right: 5px;">移除</Button>
              <Button size="small" type="primary" @click="updateLink(link)">确认</Button>
            </div>
          </div>
        </template>
        <CheckboxButton
          last
          style="width: 100%;"
          :checked="!!richTextAttrs.link"
          v-tooltip="'超链接'"
          @click="openLinkPopover()"
        ><IconLinkOne /></CheckboxButton>
      </Popover>
    </ButtonGroup>

    <Divider />

    <RadioGroup 
      class="row" 
      button-style="solid" 
      :value="richTextAttrs.align"
      @update:value="value => emitRichTextCommand('align', value)"
    >
      <RadioButton value="left" v-tooltip="'左对齐'" style="flex: 1;"><IconAlignTextLeft /></RadioButton>
      <RadioButton value="center" v-tooltip="'居中'" style="flex: 1;"><IconAlignTextCenter /></RadioButton>
      <RadioButton value="right" v-tooltip="'右对齐'" style="flex: 1;"><IconAlignTextRight /></RadioButton>
      <RadioButton value="justify" v-tooltip="'两端对齐'" style="flex: 1;"><IconAlignTextBoth /></RadioButton>
    </RadioGroup>

    <div class="row" passive>
      <ButtonGroup style="flex: 1;">
        <Button
          first
          :type="richTextAttrs.bulletList ? 'primary' : 'default'"
          style="flex: 1;"
          v-tooltip="'项目符号'"
          @click="emitRichTextCommand('bulletList')"
        ><IconList /></Button>
        <Popover trigger="click" v-model:value="bulletListPanelVisible">
          <template #content>
            <div class="list-wrap">
              <ul class="list" 
                v-for="item in bulletListStyleTypeOption" 
                :key="item" 
                :style="{ listStyleType: item }"
                @click="emitRichTextCommand('bulletList', item)"
              >
                <li class="list-item" v-for="key in 3" :key="key"><span></span></li>
              </ul>
            </div>
          </template>
          <Button last class="popover-btn"><IconDown /></Button>
        </Popover>
      </ButtonGroup>
      <div style="width: 10px;"></div>
      <ButtonGroup style="flex: 1;" passive>
        <Button
          first
          :type="richTextAttrs.orderedList ? 'primary' : 'default'"
          style="flex: 1;"
          v-tooltip="'编号'"
          @click="emitRichTextCommand('orderedList')"
        ><IconOrderedList /></Button>
        <Popover trigger="click" v-model:value="orderedListPanelVisible">
          <template #content>
            <div class="list-wrap">
              <ul class="list" 
                v-for="item in orderedListStyleTypeOption" 
                :key="item" 
                :style="{ listStyleType: item }"
                @click="emitRichTextCommand('orderedList', item)"
              >
                <li class="list-item" v-for="key in 3" :key="key"><span></span></li>
              </ul>
            </div>
          </template>
          <Button last class="popover-btn"><IconDown /></Button>
        </Popover>
      </ButtonGroup>
    </div>

    <div class="row">
      <ButtonGroup style="flex: 1;" passive>
        <Button first style="flex: 1;" v-tooltip="'减小段落缩进'" @click="emitRichTextCommand('indent', '-1')"><IconIndentLeft /></Button>
        <Popover trigger="click" v-model:value="indentLeftPanelVisible">
          <template #content>
            <PopoverMenuItem @click="emitRichTextCommand('textIndent', '-1')">减小首行缩进</PopoverMenuItem>
          </template>
          <Button last class="popover-btn"><IconDown /></Button>
        </Popover>
      </ButtonGroup>
      <div style="width: 10px;"></div>
      <ButtonGroup style="flex: 1;" passive>
        <Button first style="flex: 1;" v-tooltip="'增大段落缩进'" @click="emitRichTextCommand('indent', '+1')"><IconIndentRight /></Button>
        <Popover trigger="click" v-model:value="indentRightPanelVisible">
          <template #content>
            <PopoverMenuItem @click="emitRichTextCommand('textIndent', '+1')">增大首行缩进</PopoverMenuItem>
          </template>
          <Button last class="popover-btn"><IconDown /></Button>
        </Popover>
      </ButtonGroup>
    </div>

    <Divider />

    <div class="row">
      <div style="width: 40%;">行间距：</div>
      <span class="selectText selectTextLH border2">
        <el-autocomplete
          v-model="lineHeight"
          :fetch-suggestions="(queryString: string, cb: any)=>querySearchFont(queryString,cb,'lineHeight')"
          class="inline-input w-50"
          placeholder="字体行间距"
          @select="handleSelect('lineHeight')"
          @blur="handleSelect('lineHeight')"
          @keyup.enter="handleSelect('lineHeight')">
          <template #suffix>
            <IconRowHeight />
          </template>
      </el-autocomplete>
      </span>
      <!-- <Select style="width: 60%;"
        :value="lineHeight || 1"
        @update:value="value => updateLineHeight(value as number)"
        :options="lineHeightOptions.map(item => ({
          label: item + '倍', value: item
        }))"
      >
        <template #icon>
          <IconRowHeight />
        </template>
      </Select> -->
    </div>
    <div class="row">
      <div style="width: 40%;">段间距：</div>
      <span class="selectText selectTextLH border2">
        <el-autocomplete
          v-model="paragraphSpace"
          :fetch-suggestions="(queryString: string, cb: any)=>querySearchFont(queryString,cb,'paragraphSpace')"
          class="inline-input w-50"
          placeholder="字体段间距"
          @select="handleSelect('paragraphSpace')"
          @blur="handleSelect('paragraphSpace')"
          @keyup.enter="handleSelect('paragraphSpace')">
          <template #suffix>
            <IconVerticalSpacingBetweenItems />
          </template>
      </el-autocomplete>
      </span>
      <!-- <Select style="width: 60%;"
        :value="paragraphSpace || 0"
        @update:value="value => updateParagraphSpace(value as number)"
        :options="paragraphSpaceOptions.map(item => ({
          label: item + 'px', value: item
        }))"
      >
        <template #icon>
          <IconVerticalSpacingBetweenItems />
        </template>
      </Select> -->
    </div>
    <div class="row">
      <div style="width: 40%;">字间距：</div>
      <span class="selectText selectTextLH border2">
        <el-autocomplete
          v-model="wordSpace"
          :fetch-suggestions="(queryString: string, cb: any)=>querySearchFont(queryString,cb,'wordSpace')"
          class="inline-input w-50"
          placeholder="字体字间距"
          @select="handleSelect('wordSpace')"
          @blur="handleSelect('wordSpace')"
          @keyup.enter="handleSelect('wordSpace')">
          <template #suffix>
            <IconFullwidth />
          </template>
      </el-autocomplete>
      </span>
      <!-- <Select style="width: 60%;"
        :value="wordSpace || 0"
        @update:value="value => updateWordSpace(value as number)"
        :options="wordSpaceOptions.map(item => ({
          label: item + 'px', value: item
        }))"
      >
        <template #icon>
          <IconFullwidth />
        </template>
      </Select> -->
    </div>
    <div class="row">
      <div style="width: 40%;">文本框填充：</div>
      <Popover trigger="click" style="width: 60%;">
        <template #content>
          <ColorPicker
            :modelValue="fill"
            @update:modelValue="value => updateFill(value)"
          />
        </template>
        <ColorButton :color="fill" />
      </Popover>
    </div>

    <Divider />
    <ElementOutline />
    <Divider />
    <ElementShadow />
    <Divider />
    <ElementOpacity />
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore,useFontStore } from '@/store'
import type { PPTTextElement } from '@/types/slides'
import emitter, { EmitterEvents, type RichTextAction } from '@/utils/emitter'
import { WEB_FONTS } from '@/configs/font'
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
import useTextFormatPainter from '@/hooks/useTextFormatPainter'
import message from '@/utils/message'

import ElementOpacity from '../common/ElementOpacity.vue'
import ElementOutline from '../common/ElementOutline.vue'
import ElementShadow from '../common/ElementShadow.vue'
import ElementDataMapping from '../common/ElementDataMapping'
import ColorButton from '../common/ColorButton.vue'
import TextColorButton from '../common/TextColorButton.vue'
import CheckboxButton from '@/components/CheckboxButton.vue'
import ColorPicker from '@/components/ColorPicker/index.vue'
import Divider from '@/components/Divider.vue'
import Input from '@/components/Input.vue'
import Button from '@/components/Button.vue'
import ButtonGroup from '@/components/ButtonGroup.vue'
import RadioButton from '@/components/RadioButton.vue'
import RadioGroup from '@/components/RadioGroup.vue'
import Select from '@/components/Select.vue'
import SelectGroup from '@/components/SelectGroup.vue'
import Popover from '@/components/Popover.vue'
import PopoverMenuItem from '@/components/PopoverMenuItem.vue'
import { query } from '@/utils/common'
import { useScreenStore } from "@/store/screen";
const { model } = storeToRefs(useScreenStore())

// 注意，存在一个未知原因的BUG，如果文本加粗后文本框高度增加，画布的可视区域定位会出现错误
// 因此在执行预置样式命令时，将加粗命令放在尽可能靠前的位置，避免字号增大后再加粗
const presetStyles = [
  {
    label: '大标题',
    style: {
      fontSize: '26px',
      fontWeight: 700,
    },
    cmd: [
      { command: 'clear' },
      { command: 'bold' },
      { command: 'fontsize', value: '66px' },
      { command: 'align', value: 'center' },
    ],
  },
  {
    label: '小标题',
    style: {
      fontSize: '22px',
      fontWeight: 700,
    },
    cmd: [
      { command: 'clear' },
      { command: 'bold' },
      { command: 'fontsize', value: '40px' },
      { command: 'align', value: 'center' },
    ],
  },
  {
    label: '正文',
    style: {
      fontSize: '20px',
    },
    cmd: [
      { command: 'clear' },
      { command: 'fontsize', value: '20px' },
    ],
  },
  {
    label: '正文[小]',
    style: {
      fontSize: '18px',
    },
    cmd: [
      { command: 'clear' },
      { command: 'fontsize', value: '18px' },
    ],
  },
  {
    label: '注释 1',
    style: {
      fontSize: '16px',
      fontStyle: 'italic',
    },
    cmd: [
      { command: 'clear' },
      { command: 'fontsize', value: '16px' },
      { command: 'em' },
    ],
  },
  {
    label: '注释 2',
    style: {
      fontSize: '16px',
      textDecoration: 'underline',
    },
    cmd: [
      { command: 'clear' },
      { command: 'fontsize', value: '16px' },
      { command: 'underline' },
    ],
  },
]

const mainStore = useMainStore()
const slidesStore = useSlidesStore()
const { formatFonts } = storeToRefs(useFontStore())
const { handleElement, handleElementId, richTextAttrs, availableFonts, textFormatPainter } = storeToRefs(mainStore)
const param = query()
const mode = model.value??1

const { addHistorySnapshot } = useHistorySnapshot()
const { toggleTextFormatPainter } = useTextFormatPainter()

const updateElement = (props: Partial<PPTTextElement>) => {
  slidesStore.updateElement({ id: handleElementId.value, props })
  addHistorySnapshot()
}

const bulletListPanelVisible = ref(false)
const orderedListPanelVisible = ref(false)
const indentLeftPanelVisible = ref(false)
const indentRightPanelVisible = ref(false)
const layerName = ref(handleElement.value?.layerName??'')

const bulletListStyleTypeOption = ref(['disc', 'circle', 'square'])
const orderedListStyleTypeOption = ref(['decimal', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha', 'lower-greek'])

const fill = ref<string>('#000')
const lineHeight = ref<number>()
const wordSpace = ref<number>()
const paragraphSpace = ref<number>()

const fontsize = ref<string>('20')
const fontSizeOptions = [
  '12px', '14px', '16px', '18px', '20px', '22px', '24px', '28px', '32px',
  '36px', '40px', '44px', '48px', '54px', '60px', '66px', '72px', '76px',
  '80px', '88px', '96px', '104px', '112px', '120px',
]
const fontSizes = ref<Array>([])
for(let i=0;i<fontSizeOptions.length;i++){
  let value = fontSizeOptions[i].split('px')
  let obj = {
    label: value[0],
    value: value[0],
  }
  fontSizes.value.push(obj)
}
const lineHeightOptions = [0.9, 1.0, 1.15, 1.2, 1.4, 1.5, 1.8, 2.0, 2.5, 3.0]
const lineHeights = ref<Array>([])
for(let i=0;i<lineHeightOptions.length;i++){
  let obj = {
    label: lineHeightOptions[i]+'倍',
    value: lineHeightOptions[i],
  }
  lineHeights.value.push(obj)
}

const wordSpaceOptions = ref([])
for(let i=0;i<31;i++){
  let obj = {
    label: `${i}`,
    value: i,
  }
  wordSpaceOptions.value.push(obj)
}

const paragraphSpaceOptions = [0, 5, 10, 15, 20, 25, 30, 40, 50, 80]
const paragraphSpaces = ref<Array>([])
for(let i=0;i<paragraphSpaceOptions.length;i++){
  let obj = {
    label: paragraphSpaceOptions[i]+'px',
    value: paragraphSpaceOptions[i],
  }
  paragraphSpaces.value.push(obj)
}

interface RestaurantItem {
  value: string
  label: string
}
const handleSelect = (font:string) => {
  let value
  if(font=='fontsize') {
    value = fontsize.value+'px'
    emitRichTextCommand('fontsize', value as string)
  }else if(font=='lineHeight'){
    value = lineHeight.value
    updateLineHeight(value)
  }else if(font=='paragraphSpace'){
    value = paragraphSpace.value
    updateParagraphSpace(value)
  }else if(font=='wordSpace'){
    value = wordSpace.value
    updateWordSpace(value)
  }
  
}

const createFilter = (queryString: string) => {
  return (restaurant:RestaurantItem) => {
    return (
      restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
    )
  }
}

const querySearchFont = (queryString: string, cb: any, font:string) => {
  let results
  if(font=='fontsize'){
    results = queryString? fontSizes.value.filter(createFilter(queryString))
    : fontSizes.value
  }else if(font=='lineHeight'){
    results = queryString? lineHeights.value.filter(x=>{return x.label.indexOf(queryString)!=-1})
    : lineHeights.value
  }else if(font=='paragraphSpace'){
    results = queryString? paragraphSpaces.value.filter(x=>{return x.label.indexOf(queryString)!=-1})
    : paragraphSpaces.value
  }else if(font=='wordSpace'){
    results = queryString? wordSpaceOptions.value.filter(x=>{return x.label.indexOf(queryString)!=-1})
    : wordSpaceOptions.value
  }
    cb(results)
}

// 设置行高
const updateLineHeight = (value: number) => {
  updateElement({ lineHeight: value })
}

// 设置段间距
const updateParagraphSpace = (value: number) => {
  updateElement({ paragraphSpace: value })
}

// 设置字间距
const updateWordSpace = (value: number) => {
  updateElement({ wordSpace: value })
}

// 设置文本框填充
const updateFill = (value: string) => {
  updateElement({ fill: value })
}

// 发射富文本设置命令
const emitRichTextCommand = (command: string, value?: string) => {
  if(command=='fontname' && value){
    useFontStore().loadFontToDocument([value])
  }
  emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command, value } })
}

// 发射富文本设置命令（批量）
const emitBatchRichTextCommand = (action: RichTextAction[]) => {
  emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action })
}

// 设置富文本超链接
const link = ref('')
const linkPopoverVisible = ref(false)

watch(richTextAttrs, () => {
  linkPopoverVisible.value = false
  let value = richTextAttrs.value.fontsize.split('px')
  fontsize.value =  value[0]
})

const openLinkPopover = () => {
  link.value = richTextAttrs.value.link
}
const updateLink = (link?: string) => {
  const linkRegExp = /^(https?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/
  if (!link || !linkRegExp.test(link)) return message.error('不是正确的网页链接地址')

  emitRichTextCommand('link', link)
  linkPopoverVisible.value = false
}

const updateLayerName = (e:any)=>{
  updateElement({ layerName: e })
}

const initMapping = ()=>{
  if(handleElement.value && !handleElement.value.dataMapping && 'TemplateDataSource' in handleElement.value && handleElement.value.TemplateDataSource){
    if(handleElement.value.TemplateDataSource.index!=null && handleElement.value.TemplateDataSource.Content){
      //找出同类
      const resolveElemnts = slidesStore.currentSlide.elements.filter(x=>x.TemplateDataSource && x.TemplateDataSource.index== handleElement.value.TemplateDataSource.index && x.TemplateDataSource.Content && !x.dataMapping)
      if(resolveElemnts){
        resolveElemnts.forEach(x=>{
          const props = {
            below: x.TemplateDataSource.index,
            dataMapping: {
              id: 0,
              filed: x.TemplateDataSource.Content.split('.').reverse()[0],
              name: ''
            }
          }
          slidesStore.updateElement({ id: x.id, props })
        })
        addHistorySnapshot()
      }
      
    }
  }
}

watch(handleElement, () => {
  if (!handleElement.value || handleElement.value.type !== 'text') return

  fill.value = handleElement.value.fill || '#fff'
  lineHeight.value = handleElement.value.lineHeight || 1.5
  wordSpace.value = handleElement.value.wordSpace || 0
  paragraphSpace.value = handleElement.value.paragraphSpace === undefined ? 5 : handleElement.value.paragraphSpace
  initMapping()
}, { deep: true, immediate: true })
</script>

<style lang="scss" scoped>
.selectText.selectTextLH::v-deep(.el-input__wrapper){
  border-radius: 2px;
}
.selectTextInput::v-deep(.el-input__wrapper){
  border-radius: 0 2px 2px 0;
  padding: 1px 10px;
  border-left: 0;
}
.selectTextInput{
  width: 40%;
  position: absolute;
  right: 1px;
  top: 0;
}
.selectText::v-deep(.el-input__wrapper){
  border-radius: 2px 0 0 2px;
  padding: 1px 10px;
}
.selectText{
  width: 140px;
}
.formatFontsBox{
  position: relative;
}
.formatFontsBox::v-deep(.el-input__wrapper):hover{
  border: 0;
}
.text-style-panel {
  user-select: none;
}
.row {
  width: 100%;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.preset-style {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.preset-style-item {
  width: 50%;
  height: 50px;
  border: solid 1px #d6d6d6;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  transition: all $transitionDelay;

  &:hover {
    border-color: $themeColor;
    color: $themeColor;
    z-index: 1;
  }

  &:nth-child(2n) {
    margin-left: -1px;
  }
  &:nth-child(n+3) {
    margin-top: -1px;
  }
}
.font-size-btn {
  padding: 0;
}
.link-popover {
  width: 240px;

  .btns {
    margin-top: 10px;
    text-align: right;
  }
}

.list-wrap {
  width: 176px;
  color: #666;
  padding: 8px;
  margin: -12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}
.list {
  background-color: $lightGray;
  padding: 4px 4px 4px 20px;
  cursor: pointer;

  &:not(:nth-child(3n)) {
    margin-right: 8px;
  }

  &:nth-child(4),
  &:nth-child(5),
  &:nth-child(6) {
    margin-top: 8px;
  }

  &:hover {
    color: $themeColor;

    span {
      background-color: $themeColor;
    }
  }
}
.list-item {
  width: 24px;
  height: 12px;
  position: relative;
  font-size: 12px;
  top: -5px;

  span {
    width: 100%;
    height: 2px;
    display: inline-block;
    position: absolute;
    top: 10px;
    background-color: #666;
  }
}
.popover-btn {
  padding: 0 3px;
}
.formatFontsBox .el-input__wrapper{
  border: 0;
}
</style>