import {
  CheckOutlined,
  DeleteOutlined,
  EditOutlined,
  FilterOutlined,
  SearchOutlined,
  SortAscendingOutlined,
  UndoOutlined,
} from "@ant-design/icons";
import { Button, ConfigProvider, Input, Space, type ThemeConfig } from "antd";

import { Background } from "../Shared";
import { CardDetail } from "./CardDetail";
import { DeckSelect } from "./DeckSelect";
import styles from "./index.module.scss";

const theme: ThemeConfig = {
  components: {
    Layout: {
      colorBgBody: "transparent",
    },
  },
};

export const Component: React.FC = () => {
  return (
    <ConfigProvider theme={theme}>
      <Background />
      <div className={styles.layout} style={{ width: "100%" }}>
        <div className={styles.sider}>
          <div className={styles["deck-select-container"]}>
            <DeckSelect
              decks={Array.from({ length: 18 }).map((_, i) => ({
                name: `卡组 ${i}`,
                id: i,
              }))}
              selected={4}
              onSelect={(id) => console.log(id)}
              onDelete={(id) => console.log(id)}
              onDownload={(id) => console.log(id)}
              onAdd={() => console.log("add")}
            />
          </div>
          <CardDetail code={123} open={false} onClose={() => {}} />
        </div>
        <div className={styles.content}>
          <Deck />
          <CardSelect />
        </div>
      </div>
    </ConfigProvider>
  );
};
Component.displayName = "Build";

const Deck: React.FC = () => {
  return (
    <div className={styles.deck}>
      <div className={styles.container}>
        <Space
          className={styles.title}
          style={{ justifyContent: "space-between" }}
        >
          <Input
            placeholder="我的卡组"
            bordered={false}
            prefix={<EditOutlined />}
            style={{ width: 400 }}
          />
          <Space style={{ marginRight: 6 }}>
            <Button type="text" size="small" icon={<DeleteOutlined />}>
              清空
            </Button>
            <Button type="text" size="small" icon={<UndoOutlined />}>
              重置
            </Button>
            <Button type="text" size="small" icon={<CheckOutlined />}>
              保存
            </Button>
          </Space>
        </Space>
        <div className={styles["deck-zone"]}>
          <div className={styles.main}>
            <div className={styles["card-continer"]}>
              {Array.from({ length: 42 }).map((_, i) => (
                <div className={styles.card} key={i} />
              ))}
            </div>
          </div>
          <div className={styles.extra}>
            <div className={styles["card-continer"]}>
              {Array.from({ length: 15 }).map((_, i) => (
                <div className={styles.card} key={i} />
              ))}
            </div>
          </div>
          <div className={styles.side}>
            <div className={styles["card-continer"]}>
              {Array.from({ length: 15 }).map((_, i) => (
                <div className={styles.card} key={i} />
              ))}
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

const CardSelect: React.FC = () => {
  return (
    <div className={styles.select}>
      <div className={styles.container}>
        <div className={styles.title}>
          <Input
            placeholder="搜索卡片"
            bordered={false}
            suffix={<Button type="text" icon={<SearchOutlined />} />}
          />
        </div>
        <div className={styles["select-btns"]}>
          <Button block type="text" icon={<FilterOutlined />}>
            筛选
          </Button>
          <Button block type="text" icon={<SortAscendingOutlined />}>
            排列
          </Button>
          <Button block type="text" icon={<DeleteOutlined />}>
            重置
          </Button>
        </div>
        <div className={styles["search-cards-container"]}>
          <div className={styles["search-cards"]}>
            {Array.from({ length: 60 }).map((_, i) => (
              <div className={styles.card} key={i} />
            ))}
          </div>
        </div>
      </div>
    </div>
  );
};
