/* eslint-disable */
import React, { PureComponent } from "react";
import styles from "./index.less";

export default class ColorInfo extends PureComponent {
  colorContentItem = item => {
    const title = item?.sName;
    const info = Array.isArray(item?.sColor) ? item.sColor.filter(Boolean) : [];
    return (
      <>
        <div className={styles.colorInfo}>
          <div style={{ fontWeight: "bold", marginRight: 10 }}>{title}:</div>
          <div style={{ display: "flex", flexWrap: "wrap", flex: 1 }}>
            {info.map((i, index) => (
              <div style={{ marginRight: 15 }}>
                <input
                  type="color"
                  value={i?.sColor}
                  disabled
                  name={index}
                  id={index}
                  style={{
                    marginRight: 5,
                    width: 15,
                    height: 15,
                    padding: 0,
                    verticalAlign: "middle"
                  }}
                />
                <label for={index} style={{ fontSize: 10 }}>
                  {i?.sName}
                </label>
              </div>
            ))}
          </div>
        </div>
      </>
    );
  };

  colorContent = () => {
    const { masterConfig } = this.props;
    try {
      const result = JSON.parse(masterConfig.sTableColorTs);
      if (!Array.isArray(result)) return;
      return result.map(i => this.colorContentItem(i));
    } catch (error) {
      return [];
    }
  };

  render() {
    return (
      <div
        className="colorInfo"
        style={{
          lineHeight: "20px",
          overflow: "hidden"
        }}
      >
        <div
          style={{
            maxHeight: 60,
            overflowY: "scroll",
            marginRight: -20,
          }}
        >
          {this.colorContent()}
        </div>
      </div>
    );
  }
}
