import Add from "@mui/icons-material/Add"; import EditOutlined from "@mui/icons-material/EditOutlined"; import { AdminSwitch } from "@/shared/ui/AdminSwitch.jsx"; import TextField from "@mui/material/TextField"; import { formatMillis } from "@/shared/utils/time.js"; import { DataState } from "@/shared/ui/DataState.jsx"; import { AdminActionIconButton, AdminListBody, AdminListPage, AdminListToolbar, AdminRowActions, } from "@/shared/ui/AdminListLayout.jsx"; import { countryEnabledFilters } from "@/features/host-org/constants.js"; import { HostOrgActionModal } from "@/features/host-org/components/HostOrgActionModal.jsx"; import { HostOrgTable } from "@/features/host-org/components/HostOrgTable.jsx"; import { useHostCountriesPage } from "@/features/host-org/hooks/useHostCountriesPage.js"; import { createOptionsColumnFilter, createTextColumnFilter } from "@/shared/ui/tableFilters.js"; import styles from "@/features/host-org/host-org.module.css"; const baseCountryColumns = [ { key: "countryId", label: "国家 ID", width: "minmax(90px, 0.6fr)" }, { key: "flag", label: "国旗", render: (item) => {item.flag || "-"}, width: "minmax(70px, 0.4fr)", }, { key: "countryCode", label: "国家码", width: "minmax(90px, 0.7fr)" }, { key: "countryDisplayName", label: "展示名称", width: "minmax(150px, 1fr)" }, { key: "countryName", label: "国家名称", width: "minmax(150px, 1fr)" }, { key: "phoneCountryCode", label: "电话区号", width: "minmax(90px, 0.7fr)" }, { key: "sortOrder", label: "排序", width: "minmax(80px, 0.5fr)" }, { key: "updatedAtMs", label: "更新时间", render: (item) => formatMillis(item.updatedAtMs), width: "minmax(170px, 1fr)", }, ]; export function HostCountriesPage() { const page = useHostCountriesPage(); const createDisabled = !page.abilities.canCreate; const updateDisabled = !page.abilities.canUpdate; const items = page.data.items || []; const total = page.data.total || 0; const countryColumns = [ ...baseCountryColumns.slice(0, 6), { key: "enabled", label: "状态", render: (item) => , filter: createOptionsColumnFilter({ options: countryEnabledFilters, placeholder: "搜索状态", value: page.enabledStatus, onChange: page.changeEnabledStatus, }), width: "minmax(90px, 0.6fr)", }, ...baseCountryColumns.slice(6), ].map((column) => column.key === "countryCode" ? { ...column, filter: createTextColumnFilter({ placeholder: "搜索国家码、国家名称", value: page.query, onChange: page.changeQuery, }), } : column, ); const columns = page.abilities.canUpdate ? [ ...countryColumns, { key: "actions", label: "操作", render: (item) => , width: "minmax(104px, 0.7fr)", }, ] : countryColumns; return ( ) : null } /> item.countryId} pagination={{ page: 1, pageSize: Math.max(items.length, 1), total }} /> page.setCountryForm({ ...page.countryForm, countryCode: event.target.value })} /> page.setCountryForm({ ...page.countryForm, countryDisplayName: event.target.value }) } /> page.setCountryForm({ ...page.countryForm, countryName: event.target.value })} /> page.setCountryForm({ ...page.countryForm, isoAlpha3: event.target.value })} /> page.setCountryForm({ ...page.countryForm, isoNumeric: event.target.value })} /> page.setCountryForm({ ...page.countryForm, phoneCountryCode: event.target.value }) } /> page.setCountryForm({ ...page.countryForm, flag: event.target.value })} /> page.setCountryForm({ ...page.countryForm, sortOrder: event.target.value })} /> {page.activeAction === "create" ? ( page.setCountryForm({ ...page.countryForm, enabled: event.target.checked }) } /> ) : null} ); } function CountryActions({ item, page }) { return ( {page.abilities.canUpdate ? ( page.openEditCountry(item)}> ) : null} ); } function CountryStatusSwitch({ item, page }) { return ( page.toggleCountry(item, event.target.checked)} /> ); }