import { Select } from "antd";
import { Menu, Dropdown } from 'antd';
import { connect } from "dva";
import router from 'umi/router';
import { webSiteContactRelation } from "@/utils/utils"

const SiteSelector = ({ siteList, currentSite, dispatch }) => {
  const handleChange = (value) => {
    dispatch({ type: "global/setCurrentSite", payload: value });
    dispatch({ type: "global/setCurrentContactType", payload: webSiteContactRelation[value] });
    const targetSite = siteList.find(item => item.value === value);
    dispatch({ type: "global/setCurrentSiteName", payload: targetSite.title });
  };
  return (
    siteList.length ?  (
      <Select
        value={currentSite}
        style={{ width: 150 }}
        onChange={handleChange}
      >
        {siteList.map((site) => (
          <Select.Option key={site.name} value={site.value}>
            {site.title}
          </Select.Option>
        ))}
      </Select>
    ) : null
  );
};

export default connect(({ global }) => ({
  siteList: global.siteList,
  currentSite: global.currentSite,
}))(SiteSelector);
