import MixCheckBox from '@containers/MixCheckBox';
import RadioDrop from "@containers/RadioDrop";
import RadioInpDrop from "@containers/RadioInpDrop";
import NumberDrop from "@containers/NumberDrop";
import MultSpread from "@containers/MultSpread";
import SpreadDrop from "@containers/SpreadDrop";
import EditableSpan from '@containers/EditableSpan';
import InlineTag from '@containers/InlineTag';
import NumberUnitDrop from '@containers/NumberUnitDrop';
import Multiple from '@containers/Multiple';

/******
 * 下拉类型分发
 * 先根据tagType分为几个大类填写单
 * 再根据controlType判断子项（列）类型
 * tagType：1：单项单列，例如： 程度，咳出通畅度  2：单项多列，例如：杂音，添加症状 3：横铺单标签形式，例如：血压 4：横铺多标签形式，例如：咳嗽 5：竖铺组合项，例如：有无治疗 6：组合项多列 既往史
 * controlType控件类型：(0：无类型，默认值 1：下拉单选 2：下拉多选 3：纯文本 4：待定 5：待定 6：文本框 7：数字键盘文本框 99：联合推送)
 *
 * *******/
//单选类型
export function singleRadio(params){
  const data = params.item;
  const {i,hideTag,boxMark,showArr,selecteds,boxTop,boxLeft,importLabel} = params;
  let isHigh=importLabel&&importLabel.includes(data.id);
  const showInx = boxMark+i+'0';    //单括号多标签的情况下需要识别同一个标签内多个下拉组件的显示状态
  switch (+data.controlType){
    case 0:
    case 1:
      const custom= JSON.parse(localStorage.getItem('radio'+data.id));
      const list = data.questionDetailList&&data.questionDetailList.length>0?data.questionDetailList:data.questionMapping;
      return <RadioDrop data={custom&&custom.length?[...custom,...list]:list}
                        prefix={data.labelPrefix}
                        suffix={data.labelSuffix}
                        placeholder={data.name}
                        show={showArr&&showArr[showInx]}
                        value = {data.value}
                        boxMark={boxMark}
                        id={data.id}
                        isImports={isHigh}
                        ikey={showInx}
                        hideTag={hideTag}></RadioDrop>;
    case 2:
      const dataList = data.questionDetailList&&data.questionDetailList.length>0?data.questionDetailList:data.questionMapping;
      return <Multiple data={dataList}
                     ikey={showInx}
                     placeholder={data.name}
                     value={data.value}
                     copyType={data.copyType}
                     selecteds={selecteds ?selecteds[i]:[]}
                     show={showArr&&showArr[showInx]}
                     order={data.textGenerate}
                     type={boxMark}
                     isImports={isHigh}
                     textPrefix={data.labelPrefix}
                     textSuffix={data.labelSuffix}
                     id={data.id}></Multiple>
    case 3:
      return <EditableSpan {...params} value={data.value||data.value==''?data.value:data.name} update={Math.random()}/>;
    case 5://带单位数字键盘
      return <NumberUnitDrop prefix={data.labelPrefix}
                         suffix={data.labelSuffix}
                         placeholder={data.name}
                         formulaCode={data.formulaCode}
                         boxMark={boxMark}
                         id={data.id}
                         isImports={isHigh}
                         show={showArr&&showArr[showInx]}
                         ikey={showInx}
                         value={data.value}
                         hideTag={hideTag}></NumberUnitDrop>;
    case 6:
      return <InlineTag prefix={data.labelPrefix}
                        suffix={data.labelSuffix}
                        placeholder={data.name}
                        value={data.value}
                        isImports={isHigh}
                        id={data.id}
                        ikey={showInx}></InlineTag>;
    case 7:
      const min = data.minValue;//!=null&&data.minValue!=undefined?data.minValue-1:undefined;
      const max = data.maxValue;//!=null&&data.maxValue!=undefined?+data.maxValue+1:undefined;
      return <NumberDrop prefix={data.labelPrefix}
                         suffix={data.labelSuffix}
                         min={min}
                         max={max}
                         placeholder={data.name}
                         boxMark={boxMark}
                         id={data.id}
                         allClick={true}
                         show={showArr&&showArr[showInx]}
                         ikey={showInx}
                         value={data.value}
                         hideTag={hideTag}></NumberDrop>;
    case 11:
      return <RadioInpDrop data={data.questionDetailList}
                           vals={data.vals}
                        placeholder={data.name}
                        show={showArr&&showArr[showInx]}
                        value = {data.value}
                        boxMark={boxMark}
                        isImports={isHigh}
                        id={data.id}
                        ikey={showInx}></RadioInpDrop>;
    default:
      return '';
  }
}

//多标签组合型
function multLabels(params){
  const data = params.item;
  const {i,boxMark,showArr,saveText,selecteds,importLabel} = params;
  let isHigh=importLabel&&importLabel.includes(data.id);
  return <MultSpread data={data.questionMapping}
                     showAdd = {+data.showAdd===1}
                     copyId={data.id}
                     fullData = {data}
                     showArr={showArr||{}}
                     update={Math.random()}
                     boxMark={boxMark}
                     isImports={isHigh}
                     ikey={boxMark+i}
                     selecteds={selecteds&&selecteds[i]}
                     saveText={saveText}
                     name={data.name||data.tagName}
                     textPrefix={data.prefix}
                     textSuffix={data.suffix}></MultSpread>
}

//多选标签展开型
function multCheckLabels(params,tagType){
  const data = params.item;
  const {i,boxMark,showArr,selecteds,importLabel} = params;
  let isHigh=importLabel&&importLabel.includes(data.id);
  const showInx = boxMark+i+'0';
  return <SpreadDrop data={data.questionMapping}
                     ikey={showInx}
                     placeholder={data.name}
                     value={data.value}
                     copyType={data.copyType}
                     selecteds={selecteds ?selecteds[i]:[]}
                     show={showArr&&showArr[showInx]}
                     order={data.textGenerate}
                     isImports={isHigh}
                     type={boxMark}
                     tagType={tagType}
                     textPrefix={data.prefix}
                     textSuffix={data.suffix}
                     id={data.id}
                     flag={data.flag}></SpreadDrop>
}

export default function(params){
  const data = params.item;
  switch (+data.tagType) {
    case 1:
    case 5:
      return singleRadio(params);
    case 2:
      // return singleChecks(params);
      return multCheckLabels(params,data.tagType);
    case 3:
      return multLabels(params);      //单标签组合展开
    case 4:
      return multLabels(params);      //多标签展开--已废（不会用到）
    case 6:
      return multCheckLabels(params,data.tagType);
    case 8:
      let isLast = false;
      if(+params.boxMark===3||+params.boxMark === 4){
        //其他史查体删到只剩最后一个自由文本标签时，该标签宽度100%，解决落关标文本
        if(params.saveText.length==1&&+data.tagType===8){
          isLast = true;
        }
      }
      // 删除后value为空，应展示空而不是name
      return <EditableSpan {...params} value={data.value||data.value==''?data.value:data.name} full={data.full||isLast}/>;
    case 11://推送类型
      return multCheckLabels(params,data.tagType);
    default:
      return '';
  }
}
