import React, { useState, useEffect } from 'react';
import { Form } from 'antd';
import { PREFIX_CLS } from '../../../../config';
import VideoButton from '../../../video-button';
import { findValuesByNamePath } from '../../../../utils';
import './index.less';

const prefixCls = `${PREFIX_CLS}-video-play-button-template`;
const list = ['simple', 'app'];
export default ({ node, propKey, config, onChangePathValue = () => {} }) => {
  const { name } = config;
  const [, setButtonType] = useState();

  const handleClick = type => {
    onChangePathValue({ path: name, value: type });
  };

  useEffect(() => {
    const { playButtonType } = findValuesByNamePath(name, node[propKey]);
    setButtonType(playButtonType);
  }, [node[propKey]]);

  return (
    <Form.Item label="播放按钮">
      <div className={`${prefixCls}-list`}>
        {list.map(item => {
          return (
            <div
              className={`${prefixCls}-item`}
              onClick={() => {
                handleClick(item);
              }}
            >
              <VideoButton type={item} />
            </div>
          );
        })}
      </div>
    </Form.Item>
  );
};
