import * as _vue from "vue";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import { inject, provide } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from '../_util/classNames';
import { getOptionProps, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export var BasicProps = {
  prefixCls: PropTypes.string,
  hasSider: PropTypes.boolean,
  tagName: PropTypes.string
};

function generator(_ref) {
  var suffixCls = _ref.suffixCls,
      tagName = _ref.tagName,
      name = _ref.name;
  return function (BasicComponent) {
    return {
      name: name,
      props: BasicComponent.props,
      setup: function setup() {
        return {
          configProvider: inject('configProvider', ConfigConsumerProps)
        };
      },
      render: function render() {
        var _this = this;

        var customizePrefixCls = this.$props.prefixCls;
        var getPrefixCls = this.configProvider.getPrefixCls;
        var prefixCls = getPrefixCls(suffixCls, customizePrefixCls);

        var basicComponentProps = _objectSpread(_objectSpread({
          prefixCls: prefixCls
        }, getOptionProps(this)), {}, {
          tagName: tagName
        });

        return _vue.createVNode(BasicComponent, basicComponentProps, {
          default: function _default() {
            return [getSlot(_this)];
          }
        });
      }
    };
  };
}

var Basic = {
  props: BasicProps,
  render: function render() {
    var _this2 = this;

    var prefixCls = this.prefixCls,
        Tag = this.tagName;
    var divProps = {
      class: prefixCls
    };
    return _vue.createVNode(Tag, divProps, {
      default: function _default() {
        return [getSlot(_this2)];
      }
    });
  }
};
var BasicLayout = {
  props: BasicProps,
  data: function data() {
    return {
      siders: []
    };
  },
  created: function created() {
    var _this3 = this;

    provide('siderHook', {
      addSider: function addSider(id) {
        _this3.siders = [].concat(_toConsumableArray(_this3.siders), [id]);
      },
      removeSider: function removeSider(id) {
        _this3.siders = _this3.siders.filter(function (currentId) {
          return currentId !== id;
        });
      }
    });
  },
  render: function render() {
    var _this4 = this;

    var prefixCls = this.prefixCls,
        hasSider = this.hasSider,
        Tag = this.tagName;
    var divCls = classNames(prefixCls, _defineProperty({}, "".concat(prefixCls, "-has-sider"), typeof hasSider === 'boolean' ? hasSider : this.siders.length > 0));
    var divProps = {
      class: divCls
    };
    return _vue.createVNode(Tag, divProps, {
      default: function _default() {
        return [getSlot(_this4)];
      }
    });
  }
};
var Layout = generator({
  suffixCls: 'layout',
  tagName: 'section',
  name: 'ALayout'
})(BasicLayout);
var Header = generator({
  suffixCls: 'layout-header',
  tagName: 'header',
  name: 'ALayoutHeader'
})(Basic);
var Footer = generator({
  suffixCls: 'layout-footer',
  tagName: 'footer',
  name: 'ALayoutFooter'
})(Basic);
var Content = generator({
  suffixCls: 'layout-content',
  tagName: 'main',
  name: 'ALayoutContent'
})(Basic);
Layout.Header = Header;
Layout.Footer = Footer;
Layout.Content = Content;
export default Layout;