import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react'; import { isMobile } from '../../helpers'; import { Modal, Table, Input, Space, Highlight, Select, Tag, } from '@douyinfe/semi-ui'; import { IconSearch } from '@douyinfe/semi-icons'; import { CheckCircle, XCircle, AlertCircle, HelpCircle } from 'lucide-react'; const ChannelSelectorModal = forwardRef(({ visible, onCancel, onOk, allChannels, selectedChannelIds, setSelectedChannelIds, channelEndpoints, updateChannelEndpoint, t, }, ref) => { const [searchText, setSearchText] = useState(''); const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(10); const [filteredData, setFilteredData] = useState([]); useImperativeHandle(ref, () => ({ resetPagination: () => { setCurrentPage(1); setSearchText(''); }, })); useEffect(() => { if (!allChannels) return; const searchLower = searchText.trim().toLowerCase(); const matched = searchLower ? allChannels.filter((item) => { const name = (item.label || '').toLowerCase(); const baseUrl = (item._originalData?.base_url || '').toLowerCase(); return name.includes(searchLower) || baseUrl.includes(searchLower); }) : allChannels; setFilteredData(matched); }, [allChannels, searchText]); const total = filteredData.length; const paginatedData = filteredData.slice( (currentPage - 1) * pageSize, currentPage * pageSize, ); const updateEndpoint = (channelId, endpoint) => { if (typeof updateChannelEndpoint === 'function') { updateChannelEndpoint(channelId, endpoint); } }; const renderEndpointCell = (text, record) => { const channelId = record.key || record.value; const currentEndpoint = channelEndpoints[channelId] || ''; const getEndpointType = (ep) => { if (ep === '/api/ratio_config') return 'ratio_config'; if (ep === '/api/pricing') return 'pricing'; return 'custom'; }; const currentType = getEndpointType(currentEndpoint); const handleTypeChange = (val) => { if (val === 'ratio_config') { updateEndpoint(channelId, '/api/ratio_config'); } else if (val === 'pricing') { updateEndpoint(channelId, '/api/pricing'); } else { if (currentType !== 'custom') { updateEndpoint(channelId, ''); } } }; return (