<template>
    <div v-loading="loading" class="boxbx" style="position: relative; height: 100%">
        <div id="boxsj">
            <div id="shushi" :style="containerStyle">
                <div class="bx" id="wave" :style="waveStyle"></div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
import html2canvas from 'html2canvas'
import $ from 'jquery'
import * as echarts from 'echarts'
import { mainHeight } from '@/utils/layout'
import {
    calcShuYAxisRange,
    createWaveLineSeries,
    formatAxisLabel,
    formatWaveAxisTooltip,
    WAVE_AXIS_POINTER,
    WAVE_DATA_ZOOM
} from '@/utils/chartAxisHelper'
import url from '@/assets/img/point.png'

import { buildWaveCacheKey, getWaveCache, setWaveCache, removeWaveCacheByEvent } from '@/utils/waveCache'
import { getShuWorker, buildWorkerPayload } from '@/utils/waveWorkerPool'
import { buildExportBaseName, formatExportDateTime } from '@/utils/echartMethod'

let waveRequestId = 0
const pendingCacheKeys = new Map<number, string>()
let shuWorker: Worker | null = null
interface WaveData {
    instantF: { max: number; min: number }
    instantS: { max: number; min: number }
    shunshiF: {
        shunshiFA: number[][]
        shunshiFB: number[][]
        shunshiFC: number[][]
    }
    shunshiS: {
        shunshiSA: number[][]
        shunshiSB: number[][]
        shunshiSC: number[][]
    }
    title: {
        aTitle: string
        bTitle: string
        cTitle: string
        unit: string
    }
    unit: string
}

interface Props {
    value?: number
    flag?: string | number | boolean
    parentHeight?: any
    DColor?: boolean
    boxoList?: any
    wp?: any
}

const props = withDefaults(defineProps<Props>(), {
    value: 2,
    flag: 3,
    parentHeight: 0,
    DColor: false,
    boxoList: () => ({}),
    wp: () => ({})
})

const loading = ref(true)
const tabvalue = ref(props.value)
const valA: any = ref(0)
const valB: any = ref(0)
const isOpen = ref(false)
const time = ref('')
const type = ref('')
const severity: any = ref('')
const iphasic: any = ref('')
const eventValue = ref('')
const persistTime = ref('')
const lineName = ref('')
const subName = ref('')
const waveDatas = ref<WaveData[]>([])
const ptpass = ref('')
const waveHeight = ref<number>()
const rmsHeight = ref<number>()
const color = ref('#006565')
const charts = ref({})
const arrpoints = ref([])
const titles = ref('')
const zoom = ref(1)
const myChartess = ref<echarts.ECharts | null>(null)
const myChartess1 = ref<echarts.ECharts | null>(null)
const myChartess2 = ref<echarts.ECharts | null>(null)
const myChartess3 = ref<echarts.ECharts | null>(null)
const myChartess4 = ref<echarts.ECharts | null>(null)
const myChartess5 = ref<echarts.ECharts | null>(null)

const vh = computed(() => {
    if (props.parentHeight == 999) {
        return `calc((60vh - 150px) / 2 )`
    } else if (props.parentHeight != 0) {
        return mainHeight(props.parentHeight, 2).height
    }

    if (props.flag == 1) {
        return mainHeight(200).height
    } else {
        return mainHeight(200, 2).height
    }

    // if (props.flag == 1) {
    //     return '690px'
    // } else if (props.parentHeight != 0) {
    //     return '310px'
    // } else {
    //     return '350px'
    // }
})

const vw = computed(() => '100%')

const containerStyle = computed(() => ({
    height: vh.value,
    overflow: 'hidden',
    minHeight: '200px'
}))

const waveStyle = computed(() => ({
    width: '100%',
    height: '100%',
    minHeight: '200px'
}))

const applyChartSize = (el: HTMLElement) => {
    el.style.width = '100%'
    el.style.height = vh.value
}

const finishChartRender = (chart: echarts.ECharts, endLoading = false) => {
    nextTick(() => {
        chart.resize()
        if (endLoading) {
            loading.value = false
        }
    })
}

watch(
    () => props.value,
    () => {
        query()
    }
)

watch(
    () => props.wp,
    () => {
        query()
    }
)

const applyWorkerResult = (data: any) => {
    titles.value = data.titles
    iphasic.value = data.iphasic
    time.value = data.time
    type.value = data.type
    severity.value = data.severity
    initWave(data.waveDatas, data.time, data.type, data.severity, isOpen.value)
    loading.value = false
}

onMounted(() => {
    const zoomValue = document.body.style.getPropertyValue('zoom')
    zoom.value = 1 / (zoomValue ? parseFloat(zoomValue) : 1)

    window.addEventListener('resize', handleResize)
    shuWorker = getShuWorker(data => {
        if (data.requestId !== waveRequestId) return
        if (!data.success) {
            console.error('Worker error:', data.error)
            loading.value = false
            return
        }
        const cacheKey = pendingCacheKeys.get(data.requestId)
        if (cacheKey) {
            setWaveCache(cacheKey, data)
            pendingCacheKeys.delete(data.requestId)
        }
        applyWorkerResult(data)
    })

    nextTick(() => {
        query()
    })
})

onBeforeUnmount(() => {
    waveRequestId++
    pendingCacheKeys.clear()
    removeWaveCacheByEvent(props.wp, props.boxoList)
    backbxlb()
    window.removeEventListener('resize', handleResize)
})

const handleResize = () => {
    const zoomValue = document.body.style.getPropertyValue('zoom')
    zoom.value = 1 / (zoomValue ? parseFloat(zoomValue) : 1)
}

const download = () => {
    const boxsj = document.getElementById('boxsj')
    if (boxsj) {
        html2canvas(boxsj, {
            scale: 2
        }).then(function (canvas) {
            const creatIMg = document.createElement('a')
            creatIMg.download = (props.boxoList.lineName || props.boxoList.measurementPointName || props.boxoList.equipmentName) + '_瞬间波形_' + formatExportDateTime() + '.png'
            creatIMg.href = canvas.toDataURL()
            creatIMg.click()
            creatIMg.remove()
        })
    }
}

const EXTRA_PANEL_CLASS = 'wave-extra-panel'

const resetWaveDom = () => {
    backbxlb()
    $('#shushi').nextAll(`.${EXTRA_PANEL_CLASS}`).remove()
}

const query = () => {
    loading.value = true
    initWaves()
}

const waveData = (instantF: any, instantS: any, shunshiF: any, shunshiS: any, title: any, unit: any): WaveData => {
    return {
        instantF,
        instantS,
        shunshiF,
        shunshiS,
        title,
        unit
    }
}

// 在组件中修改initWaves函数
const initWaves = () => {
    if (!props.wp?.listWaveData?.length) {
        initWave(null, null, null, null, null)
        loading.value = false
        return
    }

    const cacheKey = buildWaveCacheKey('shu', props.wp, props.value, isOpen.value, props.boxoList)
    const cached = getWaveCache<any>(cacheKey)
    if (cached) {
        applyWorkerResult(cached)
        return
    }

    loading.value = true
    iphasic.value = props.wp.iphasic || 1
    const currentRequestId = ++waveRequestId
    pendingCacheKeys.set(currentRequestId, cacheKey)

    shuWorker?.postMessage(
        buildWorkerPayload('shu', props.wp, props.boxoList, {
            requestId: currentRequestId,
            value: props.value,
            isOpen: isOpen.value,
            iphasic: iphasic.value
        })
    )
}

const initWave = (
    waveDatas: WaveData[] | null,
    time: string | null,
    type: string | null,
    severity: string | null,
    isOpen: boolean | null
) => {
    resetWaveDom()
    $('div.bx1').remove()

    let picHeight = vh.value
    const show = !isOpen
    let isvisible = false
    let cu: number[][] = []
    let titleText = ''
    let unit = ''
    let max: any = 0,
        min: any = 0
    let a: string | null = null,
        b: string | null = null,
        c: string | null = null
    let adata: number[][] = [],
        bdata: number[][] = [],
        cdata: number[][] = []
    const colors: string[] = []

    if (!waveDatas) {
        titleText = '该事件暂无波形图'
    } else if (waveDatas.length > 0) {
        titleText = titles.value

        if (Number(eventValue.value) <= 90) {
            isvisible = true
        }

        switch (iphasic.value) {
            case 1:
                a = waveDatas[0].title.aTitle
                if (props.value === 1) {
                    cu = [[0, waveDatas[0].instantF.min]]
                    max = waveDatas[0].instantF.max
                    min = waveDatas[0].instantF.min
                    adata = waveDatas[0].shunshiF.shunshiFA
                } else {
                    cu = [[0, waveDatas[0].instantS.min]]
                    max = waveDatas[0].instantS.max
                    min = waveDatas[0].instantS.min
                    adata = waveDatas[0].shunshiS.shunshiSA
                }
                colors.push('#DAA520', '#000', '#000')
                break
            case 2:
                a = waveDatas[0].title.aTitle
                b = waveDatas[0].title.bTitle
                if (props.value === 1) {
                    cu = [[0, waveDatas[0].instantF.min]]
                    max = waveDatas[0].instantF.max
                    min = waveDatas[0].instantF.min
                    adata = waveDatas[0].shunshiF.shunshiFA
                    bdata = waveDatas[0].shunshiF.shunshiFB
                } else {
                    cu = [[0, waveDatas[0].instantS.min]]
                    max = waveDatas[0].instantS.max
                    min = waveDatas[0].instantS.min
                    adata = waveDatas[0].shunshiS.shunshiSA
                    bdata = waveDatas[0].shunshiS.shunshiSB
                }
                colors.push('#DAA520', '#2E8B57', '#000')
                break
            case 3:
                a = waveDatas[0].title.aTitle
                b = waveDatas[0].title.bTitle
                c = waveDatas[0].title.cTitle
                if (props.value === 1) {
                    cu = [[0, waveDatas[0].instantF.min]]
                    max = waveDatas[0].instantF.max
                    min = waveDatas[0].instantF.min
                    adata = waveDatas[0].shunshiF.shunshiFA
                    bdata = waveDatas[0].shunshiF.shunshiFB
                    cdata = waveDatas[0].shunshiF.shunshiFC
                } else {
                    cu = [[0, waveDatas[0].instantS.min]]
                    max = waveDatas[0].instantS.max
                    min = waveDatas[0].instantS.min
                    adata = waveDatas[0].shunshiS.shunshiSA
                    bdata = waveDatas[0].shunshiS.shunshiSB
                    cdata = waveDatas[0].shunshiS.shunshiSC
                }
                colors.push('#DAA520', '#2E8B57', '#A52a2a')
                break
        }

        if (waveDatas[0].title.unit === '电压') {
            unit = props.value === 1 ? 'kV' : 'V'
        } else {
            unit = 'A'
        }

        for (let step = waveDatas.length - 1; step > 0 && step < waveDatas.length; step--) {
            const waveId = 'wave' + step
            const newDivShunshi = $(`<div class="${EXTRA_PANEL_CLASS}" style="height:${vh.value};overflow: hidden;min-height: 200px;">
        <div class='bx1' id='${waveId}'></div>
      </div>`)
            newDivShunshi.insertAfter($('#shushi'))
            $(`#${waveId}`).css('height', picHeight).css('width', vw.value).css('min-height', '200px')
        }
    } else {
        titleText = `变电站名称：${subName.value} 监测点名称：${lineName.value} 发生时刻：${time} 暂降幅值：${(
            Number(eventValue.value) * 1
        ).toFixed(0)}% 持续时间：${persistTime.value}s`
    }

    const wave = document.getElementById('wave')
    if (!wave) return

    applyChartSize(wave)

    const yRange = calcShuYAxisRange(Number(min), Number(max))

    const existingChart = echarts.getInstanceByDom(wave)
    if (existingChart) existingChart.dispose()

    const myChartes = echarts.init(wave)
    const echartsColor = {
        WordColor: '#000',
        thread: '#000',
        FigureColor: [
            '#07CCCA ',
            '#00BFF5',
            '#FFBF00',
            '#77DA63',
            '#D5FF6B',
            '#Ff6600',
            '#FF9100',
            '#5B6E96',
            '#66FFCC',
            '#B3B3B3',
            '#FF00FF',
            '#CC00FF',
            '#FF9999'
        ]
    }
    let titlename = ''
    if (props.boxoList.systemType == 'ZL' || props.boxoList.systemType == 'YPT') {


        if (props.wp.channelNames[1].includes('L')) {
            titlename = '电网侧'
        }
        if (props.wp.channelNames[1].includes('S')) {
            titlename = '负载侧'
        }



    }

    const option = {
        tooltip: {
            top: '10px',
            trigger: 'axis',
            axisPointer: WAVE_AXIS_POINTER,
            borderColor: 'grey',
            style: {
                color: '#fff',
                fontSize: '15px',
                padding: 10
            },
            formatter: (params: any) => formatWaveAxisTooltip(params),
            textStyle: {
                color: '#fff',
                fontStyle: 'normal',
                opacity: 0.35,
                fontSize: 14
            },
            backgroundColor: 'rgba(0,0,0,0.55)',
            borderWidth: 0
        },
        title: {
            left: 'center',
            text: titleText,
            textStyle: {
                fontSize: '14px',
                color: props.DColor ? '#000' : echartsColor.WordColor
            }
        },
        legend: {
            right: 50,
            top: 25,
            verticalAlign: 'top',
            enabled: true,
            itemDistance: 5,
            textStyle: {
                fontSize: 12,
                color: props.DColor ? '#000' : echartsColor.WordColor,
                rich: { a: { verticalAlign: 'middle' } },
                padding: [0, 0, 0, 0]
            }
        },
        toolbox: {
            right: 20,
            top: 15,
            feature: {
                myCustomDownload: {
                    title: '',
                    icon: 'path://M892.342857 463.238095l-73.142857-68.266666-258.438095 258.438095V29.257143h-97.52381v624.152381L204.8 394.971429 131.657143 463.238095l380.342857 380.342857zM107.27619 897.219048h804.571429v97.523809H107.27619z',
                    onclick: () => download()
                }
            }
        },
        xAxis: {
            type: 'value',
            name: '时间\n(ms)',
            boundaryGap: false,
            min: props.wp?.listWaveData[0][0] || 0,
            max: props.wp?.listWaveData[props.wp?.listWaveData.length - 1][0] + 1 || 1,
            title: {
                text: 'ms',
                textStyle: {
                    fontSize: '12px',
                    color: props.DColor ? '#000' : echartsColor.WordColor
                },
                enabled: true,
                align: 'high'
            },
            splitLine: { show: false },
            nameTextStyle: { fontSize: '12px' },
            axisTick: { alignWithLabel: true },
            axisLine: {
                lineStyle: {
                    color: props.DColor ? '#000' : echartsColor.thread
                },
                onZero: false
            },
            axisLabel: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor,
                formatter: function (value: number) {
                    if (valA.value != (value - 0).toFixed(0)) {
                        valA.value = Number((value - 0).toFixed(0))
                        return (value - 0).toFixed(0)
                    }
                    return ''
                }
            }
        },
        yAxis: {
            type: 'value',
            name: unit + (titlename ? '_' + titlename : ''),
            title: {
                align: 'high',
                offset: 0,
                text: unit,
                rotation: 0,
                y: -10
            },
            boundaryGap: [0, '100%'],
            showLastLabel: true,
            max: yRange.max,
            min: yRange.min,
            interval: yRange.interval,
            minInterval: yRange.interval,
            scale: false,
            opposite: false,
            nameTextStyle: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: props.DColor ? '#000' : echartsColor.thread
                },
                onZero: false
            },
            axisLabel: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor,
                formatter: function (value: number) {
                    return formatAxisLabel(value)
                }
            },
            splitLine: {
                lineStyle: {
                    color: [props.DColor ? '#000' : echartsColor.thread],
                    type: 'dashed',
                    opacity: 0.5
                }
            }
        },
        grid: {
            left: '60px',
            right: '45px',
            bottom: '45px',
            top: '60px'
        },
        dataZoom: WAVE_DATA_ZOOM,
        series: [
            createWaveLineSeries(a, adata, '#DAA520'),
            createWaveLineSeries(b, bdata, '#2E8B57'),
            createWaveLineSeries(c, cdata, '#A52a2a'),
            {
                name: '暂降触发点',
                type: 'scatter',
                symbol: 'image://' + url,
                itemStyle: { width: 18, height: 18 },
                data: cu
            }
        ]
    }

    myChartes.setOption(option)
    myChartess.value = myChartes
    finishChartRender(myChartes, true)

    if (waveDatas && waveDatas.length > 1) {
        const waveDatasTemp = waveDatas.slice(1)
        for (let step = 0; step < waveDatasTemp.length; step++) {
            drawPics(waveDatasTemp[step], picHeight, step, show, myChartes, titleText)
        }
    }
}

const drawPics = (
    waveDataTemp: WaveData,
    picHeight: any,
    step: number,
    show: boolean,
    myChartes1: echarts.ECharts,
    title: string
) => {
    step = step + 1
    const waveId = 'wave' + step
    let a: string | null = null,
        b: string | null = null,
        c: string | null = null
    let max: any = 0,
        min: any = 0,
        unit = ''
    let adata: number[][] = [],
        bdata: number[][] = [],
        cdata: number[][] = []
    const colors: string[] = []

    switch (iphasic.value) {
        case 1:
            a = waveDataTemp.title.aTitle
            colors.push('#DAA520', '#000', '#000')
            break
        case 2:
            a = waveDataTemp.title.aTitle
            b = waveDataTemp.title.bTitle
            colors.push('#DAA520', '#2E8B57', '#000')
            break
        case 3:
            a = waveDataTemp.title.aTitle
            b = waveDataTemp.title.bTitle
            c = waveDataTemp.title.cTitle
            colors.push('#DAA520', '#2E8B57', '#A52a2a')
            break
    }

    if (props.value === 1) {
        max = waveDataTemp.instantF.max
        min = waveDataTemp.instantF.min
        adata = waveDataTemp.shunshiF.shunshiFA
        bdata = waveDataTemp.shunshiF.shunshiFB
        cdata = waveDataTemp.shunshiF.shunshiFC
    } else {
        max = waveDataTemp.instantS.max
        min = waveDataTemp.instantS.min
        adata = waveDataTemp.shunshiS.shunshiSA
        bdata = waveDataTemp.shunshiS.shunshiSB
        cdata = waveDataTemp.shunshiS.shunshiSC
    }

    if (waveDataTemp.title.unit === '电压') {
        unit = props.value === 1 ? 'kV' : 'V'
    } else {
        unit = 'A'
    }

    let titlename = ''
    if (props.boxoList.systemType == 'ZL' || props.boxoList.systemType == 'YPT') {
        const str = waveId.split('e')
        const str1 = Number(str[1])

        props.wp.channelNames.forEach((element: string, i: number) => {
            if ((str1 == 1 && i == 4) || (str1 == 2 && i == 7) || (str1 == 3 && i == 10)) {


                if (element.includes('L')) {
                    titlename = '电网侧'
                }
                if (element.includes('S')) {
                    titlename = '负载侧'
                }
              
                // if (str1 == 1 && i == 4) {
                //     const s = element.split('A')
                //     const s1 = s[0] == 'LI' ? '电网侧' : ''//s[0] + '侧' + s[1]
                //     titlename = s1 //+ '    ' + title
                // }
                // if (str1 == 2 && i == 7) {
                //     const s = element.split('A')
                //     const s1 = s[0] == 'SU' ? '负载侧' : ''//s[0] + '侧' + s[1]
                //     titlename = s1 //+ '    ' + title
                // }
                // if (str1 == 3 && i == 10) {
                //     const s = element.split('A')
                //     const s1 = s[0] == 'SI' ? '负载侧' : ''//s[0] + '侧' + s[1]
                //     titlename = s1 //+ '    ' + title
                // }
            }
        })


    }

    const waveIds = document.getElementById(waveId)
    if (!waveIds) return

    applyChartSize(waveIds)

    const yRange = calcShuYAxisRange(Number(min), Number(max))

    const existingChart = echarts.getInstanceByDom(waveIds)
    if (existingChart) existingChart.dispose()

    const myChartes = echarts.init(waveIds)
    const echartsColor = {
        WordColor: '#000',
        thread: '#000',
        FigureColor: [
            '#07CCCA ',
            '#00BFF5',
            '#FFBF00',
            '#77DA63',
            '#D5FF6B',
            '#Ff6600',
            '#FF9100',
            '#5B6E96',
            '#66FFCC',
            '#B3B3B3',
            '#FF00FF',
            '#CC00FF',
            '#FF9999'
        ]
    }

    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: WAVE_AXIS_POINTER,
            borderColor: 'grey',
            formatter: (params: any) => formatWaveAxisTooltip(params, { showMarker: false }),
            textStyle: {
                color: '#fff',
                fontStyle: 'normal',
                opacity: 0.35,
                fontSize: 14
            },
            backgroundColor: 'rgba(0,0,0,0.55)',
            borderWidth: 0
        },
        title: {
            left: 'center',
            text: '', //titlename || title,
            textStyle: {
                fontSize: '16px',
                color: props.DColor ? '#000' : echartsColor.WordColor
            }
        },
        legend: {
            right: 50,
            top: 25,
            verticalAlign: 'top',
            enabled: true,
            itemDistance: 5,
            textStyle: {
                fontSize: 12,
                color: props.DColor ? '#000' : echartsColor.WordColor,
                rich: { a: { verticalAlign: 'middle' } },
                padding: [0, 0, 0, 0]
            }
        },
        xAxis: {
            type: 'value',
            name: '时间\n(ms)',
            boundaryGap: false,
            min: props.wp.listWaveData[0][0],
            max: props.wp.listWaveData[props.wp.listWaveData.length - 1][0] + 1,
            title: {
                text: 'ms',
                textStyle: {
                    fontSize: '12px',
                    color: props.DColor ? '#000' : echartsColor.WordColor
                },
                enabled: true,
                align: 'high'
            },
            splitLine: { show: false },
            axisTick: { alignWithLabel: true },
            axisLine: {
                lineStyle: {
                    color: props.DColor ? '#000' : echartsColor.thread
                },
                onZero: false
            },
            nameTextStyle: { fontSize: '12px' },
            axisLabel: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor,
                formatter: function (value: number) {
                    if (valB.value != (value - 0).toFixed(0)) {
                        valB.value = Number((value - 0).toFixed(0))
                        return (value - 0).toFixed(0)
                    }
                    return ''
                }
            }
        },
        yAxis: {
            type: 'value',
            name: unit + (titlename ? '_' + titlename : ''),
            title: {
                align: 'high',
                offset: 0,
                text: unit,
                rotation: 0,
                y: -10
            },
            boundaryGap: [0, '100%'],
            showLastLabel: true,
            max: yRange.max,
            min: yRange.min,
            interval: yRange.interval,
            minInterval: yRange.interval,
            scale: false,
            opposite: false,
            nameTextStyle: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: props.DColor ? '#000' : echartsColor.thread
                },
                onZero: false
            },
            axisLabel: {
                fontSize: '12px',
                color: props.DColor ? '#000' : echartsColor.WordColor,
                formatter: function (value: number) {
                    return formatAxisLabel(value)
                }
            },
            splitLine: {
                lineStyle: {
                    color: [props.DColor ? '#000' : echartsColor.thread],
                    type: 'dashed',
                    opacity: 0.5
                }
            }
        },
        grid: {
            left: '60px',
            right: '45px',
            bottom: '45px',
            top: '60px'
            // containLabel: true
        },
        dataZoom: WAVE_DATA_ZOOM,
        series: [
            createWaveLineSeries(a, adata, '#DAA520'),
            createWaveLineSeries(b, bdata, '#2E8B57'),
            createWaveLineSeries(c, cdata, '#A52a2a')
        ]
    }

    myChartes.setOption(option)

    switch (step) {
        case 1:
            myChartess1.value = myChartes
            break
        case 2:
            myChartess2.value = myChartes
            break
        case 3:
            myChartess3.value = myChartes
            break
        case 4:
            myChartess4.value = myChartes
            break
        case 5:
            myChartess5.value = myChartes
            break
    }

    finishChartRender(myChartes)

    echarts.connect([myChartes1, myChartes])
}

const backbxlb = () => {
    waveDatas.value = []
    const charts = [
        myChartess.value,
        myChartess1.value,
        myChartess2.value,
        myChartess3.value,
        myChartess4.value,
        myChartess5.value
    ]

    charts.forEach(chart => {
        if (chart) {
            chart.dispose()
        }
    })

    myChartess.value = null
    myChartess1.value = null
    myChartess2.value = null
    myChartess3.value = null
    myChartess4.value = null
    myChartess5.value = null

    $('#shushi').nextAll(`.${EXTRA_PANEL_CLASS}`).remove()
    $('div.bx1').remove()
}

const getMax = (temp: number, tempA: number, tempB: number, tempC: number): number => {
    temp = temp > tempA ? temp : tempA
    temp = temp > tempB ? temp : tempB
    temp = temp > tempC ? temp : tempC
    return temp
}

const getMaxTwo = (temp: number, tempA: number, tempB: number): number => {
    temp = temp > tempA ? temp : tempA
    temp = temp > tempB ? temp : tempB
    return temp
}

const getMin = (temp: number, tempA: number, tempB: number, tempC: number): number => {
    temp = temp < tempA ? temp : tempA
    temp = temp < tempB ? temp : tempB
    temp = temp < tempC ? temp : tempC
    return temp
}

const getMinOpen = (temp: number, tempA: number, tempB: number): number => {
    temp = temp < tempA ? temp : tempA
    temp = temp < tempB ? temp : tempB
    return temp
}
</script>
