"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChipList = exports.Item = void 0;
const color_hash_1 = __importDefault(require("color-hash"));
const react_1 = __importStar(require("react"));
const styled_components_1 = __importDefault(require("styled-components"));
const __1 = require("../");
const helper_1 = require("../util/helper");
const colorHash = new color_hash_1.default({ saturation: 0.7, lightness: 0.6 });
exports.Item = styled_components_1.default('div') `
  box-sizing: border-box;
  color: '#fff';
  border: none;
  min-height: var(--input-min-height);
  outline: none;
  padding: 5px;
  display: inline-flex;
  transition: background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
    box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  white-space: nowrap;
  align-items: center;
  border-radius: 4px;
  vertical-align: middle;
  text-decoration: none;
  justify-content: center;
  /* background-color: var(--transparent-grey); */
  margin: 0 10px 10px 0;
  /* border-left: 5px solid var(--primary-color); */
`;
const StyledButton = styled_components_1.default('button') `
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  :focus {
    outline: 0;
  }
`;
const Root = styled_components_1.default('div') `
  margin: 10px 0;
`;
const Form = styled_components_1.default('form') `
  display: flex;
  width: 100%;
`;
const ClearCircleIcon = styled_components_1.default(__1.icons.ClearCircle) `
  color: rgba(255, 255, 255, 0.8);
  margin: 0 0 0 4px;
`;
class ChipList extends react_1.Component {
    constructor() {
        super(...arguments);
        this.state = {
            newValue: '',
        };
        this.onAdd = () => {
            const { newValue } = this.state;
            this.props.onAdd(newValue);
            this.setState({ newValue: '' });
        };
    }
    render() {
        const { values, onDelete, noColor } = this.props;
        const { newValue } = this.state;
        return (react_1.default.createElement(Root, null,
            values &&
                values.map((v, index) => (react_1.default.createElement(exports.Item, { key: index, style: {
                        background: noColor
                            ? 'var(--accent-color)'
                            : colorHash.hex(String(v)),
                    } },
                    v,
                    react_1.default.createElement(StyledButton, { type: "button", onClick: () => onDelete(index) },
                        react_1.default.createElement(ClearCircleIcon, null))))),
            react_1.default.createElement(Form, { onSubmit: (e) => {
                    e.preventDefault();
                    this.onAdd();
                } },
                react_1.default.createElement(__1.SimpleInput, Object.assign({}, helper_1.testable('chip-list-input'), { value: newValue, onChange: (e) => this.setState({ newValue: e.target.value }) })),
                react_1.default.createElement(__1.Button, { icon: __1.paths.Plus, light: true, onClick: this.onAdd }, "Add"))));
    }
}
exports.ChipList = ChipList;
//# sourceMappingURL=index.js.map