import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";

/*
 * @Descripttion : 组件样式
 */
import cloneDeep from "lodash/cloneDeep";
import { getThemeVar } from "../utils/util";
export default {
  namespace: 'style',
  state: {
    // 自定义样式
    customStyle: {},
    // 临时样式
    temporaryStyle: {},
    // 页面样式
    pageStyle: {},
    // 主题
    themeStyle: _objectSpread({}, getThemeVar),
    // 当前主题
    currentTheme: {
      name: 'pto',
      title: '',
      url: ''
    },
    // 所有主题
    allThemes: {
      pto: {
        name: 'pto',
        title: 'pto主题',
        url: '/css/pto.min.css'
      }
    }
  },
  effects: {
    updateCustomStyle: /*#__PURE__*/_regeneratorRuntime.mark(function updateCustomStyle(_ref, _ref2) {
      var payload, put;
      return _regeneratorRuntime.wrap(function updateCustomStyle$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              put = _ref2.put;
              _context.next = 4;
              return put({
                type: 'saveCustomStyle',
                payload: payload
              });

            case 4:
              return _context.abrupt("return", true);

            case 5:
            case "end":
              return _context.stop();
          }
        }
      }, updateCustomStyle);
    }),
    updatePageStyle: /*#__PURE__*/_regeneratorRuntime.mark(function updatePageStyle(_ref3, _ref4) {
      var payload, put;
      return _regeneratorRuntime.wrap(function updatePageStyle$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              put = _ref4.put;
              _context2.next = 4;
              return put({
                type: 'savePageStyle',
                payload: payload
              });

            case 4:
              return _context2.abrupt("return", true);

            case 5:
            case "end":
              return _context2.stop();
          }
        }
      }, updatePageStyle);
    }),
    updateThemeStyle: /*#__PURE__*/_regeneratorRuntime.mark(function updateThemeStyle(_ref5, _ref6) {
      var payload, put;
      return _regeneratorRuntime.wrap(function updateThemeStyle$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              put = _ref6.put;
              _context3.next = 4;
              return put({
                type: 'saveThemeStyle',
                payload: payload
              });

            case 4:
              return _context3.abrupt("return", true);

            case 5:
            case "end":
              return _context3.stop();
          }
        }
      }, updateThemeStyle);
    }),
    updateTemporaryStyle: /*#__PURE__*/_regeneratorRuntime.mark(function updateTemporaryStyle(_ref7, _ref8) {
      var payload, put;
      return _regeneratorRuntime.wrap(function updateTemporaryStyle$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              put = _ref8.put;
              _context4.next = 4;
              return put({
                type: 'saveTemporaryStyle',
                payload: payload
              });

            case 4:
              return _context4.abrupt("return", true);

            case 5:
            case "end":
              return _context4.stop();
          }
        }
      }, updateTemporaryStyle);
    })
  },
  reducers: {
    saveCustomStyle: function saveCustomStyle(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        customStyle: _objectSpread(_objectSpread({}, state.customStyle), action.payload)
      });
    },
    savePageStyle: function savePageStyle(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        pageStyle: _objectSpread(_objectSpread({}, state.pageStyle), action.payload)
      });
    },
    saveThemeStyle: function saveThemeStyle(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        themeStyle: _objectSpread(_objectSpread({}, state.themeStyle), action.payload)
      });
    },
    saveCurrentTheme: function saveCurrentTheme(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        currentTheme: _objectSpread({}, action.payload)
      });
    },
    saveTemporaryStyle: function saveTemporaryStyle(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        temporaryStyle: _objectSpread(_objectSpread({}, state.temporaryStyle), action.payload)
      });
    },
    deleteTemporaryStyle: function deleteTemporaryStyle(state, action) {
      var getTemporaryStyle = cloneDeep(state.temporaryStyle);
      var item = ".".concat(action === null || action === void 0 ? void 0 : action.payload, " ");
      var itemHover = ".".concat(action === null || action === void 0 ? void 0 : action.payload, ":hover ");
      var itemFocus = ".".concat(action === null || action === void 0 ? void 0 : action.payload, ":focus ");
      var itemActive = ".".concat(action === null || action === void 0 ? void 0 : action.payload, ":active ");
      Object.keys(getTemporaryStyle).map(function (vl) {
        if (vl.includes(item) || vl.includes(itemHover) || vl.includes(itemFocus) || vl.includes(itemActive)) {
          delete getTemporaryStyle[vl];
        }
      });
      return _objectSpread(_objectSpread({}, state), {}, {
        temporaryStyle: _objectSpread({}, getTemporaryStyle)
      });
    },
    saveAllThemes: function saveAllThemes(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        allThemes: _objectSpread(_objectSpread({}, state.allThemes), _defineProperty({}, action.payload.name, _objectSpread({}, action.payload)))
      });
    },
    save: function save(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    },
    clearThemeStyle: function clearThemeStyle(state, action) {
      var defaultThemeStyle = _objectSpread({}, getThemeVar);

      return _objectSpread(_objectSpread({}, state), {}, {
        themeStyle: defaultThemeStyle
      });
    }
  }
};
//# sourceMappingURL=style.js.map