'use strict';

var vue = require('vue');

function useComputed() {
  const compChildName = vue.computed(() => {
    return (opt) => {
      switch (opt.type) {
        case "checkbox":
          return "el-checkbox";
        case "radio":
          return "el-radio";
        case "select-arr":
        case "select-obj":
          return "el-option";
      }
    };
  });
  const selectListType = vue.computed(() => {
    return (opt) => {
      if (opt.listTypeInfo) {
        return opt.listTypeInfo[opt.list];
      } else {
        return [];
      }
    };
  });
  const compChildLabel = vue.computed(() => {
    return (opt, value) => {
      switch (opt.type) {
        case "radio":
        case "checkbox":
          return value[opt.arrLabel || "label"];
        case "el-select-multiple":
        case "select-arr":
          return value[opt.arrLabel || "label"];
        case "select-obj":
          return value;
      }
    };
  });
  const compChildValue = vue.computed(() => {
    return (opt, value, key) => {
      switch (opt.type) {
        case "radio":
        case "checkbox":
          return value[opt.arrKey || "key"];
        case "el-select-multiple":
        case "select-arr":
          return value[opt.arrKey || "key"];
        case "select-obj":
          return key;
      }
    };
  });
  const compChildShowLabel = vue.computed(() => {
    return (opt, value) => {
      switch (opt.type) {
        case "radio":
        case "checkbox":
          return value[opt.arrLabel || "label"];
        case "el-select-multiple":
        case "select-arr":
          return value[opt.arrLabel || "label"];
        case "select-obj":
          return value;
      }
    };
  });
  const getColLength = () => {
    const width = window.innerWidth;
    let colLength = 4;
    if (width > 1e3 && width < 1280) {
      colLength = 3;
    } else if (width > 768 && width <= 1e3) {
      colLength = 2;
    } else if (width <= 768) {
      colLength = 1;
    }
    return colLength;
  };
  return {
    compChildName,
    selectListType,
    compChildLabel,
    compChildValue,
    compChildShowLabel,
    getColLength
  };
}

exports.useComputed = useComputed;
