"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostList = void 0;
const react_web_components_1 = require("@nimles/react-web-components");
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_redux_2 = require("@nimles/react-redux");
const styled_1 = __importDefault(require("@emotion/styled"));
const Link_1 = require("./Link");
const Name = styled_1.default.h2 `
  font-size: 16px;
  margin-top: 0;
  font-size: 500;
  flex: 1 0 auto;
`;
const CardLink = (0, styled_1.default)(Link_1.NavLink) `
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
`;
const PostList = ({ organizationId, start, limit, order, style }) => {
    const dispatch = (0, react_redux_1.useDispatch)();
    const posts = (0, react_redux_1.useSelector)(({ publicPosts }) => publicPosts.values);
    (0, react_1.useEffect)(() => {
        dispatch((0, react_redux_2.searchAndLoadPublicPosts)({ start, limit, order, organizationId }));
    }, [start, limit, order, organizationId]);
    style = style && style.toLowerCase();
    switch (style) {
        case 'cards':
            return (<react_web_components_1.Row wrap>
          {posts.map((post) => (<react_web_components_1.Column key={post.id} padding xs={100}>
              <react_web_components_1.Card flex="1 0 auto">
                <CardLink to={`/${post.uniqueName}/pt`}>
                  <react_web_components_1.CardBody>
                    <Name>{post.title}</Name>
                  </react_web_components_1.CardBody>
                </CardLink>
              </react_web_components_1.Card>
            </react_web_components_1.Column>))}
        </react_web_components_1.Row>);
        case 'list':
            return (<react_web_components_1.List>
          {posts.map((post) => (<react_web_components_1.ListItem key={post.id}>
              <Link_1.NavLink to={`/${post.uniqueName}/pt`}>{post.title}</Link_1.NavLink>
            </react_web_components_1.ListItem>))}
        </react_web_components_1.List>);
        case 'menu':
            return (<react_web_components_1.List>
          {posts.map((post) => (<react_web_components_1.ListItem key={post.id} inheritColors>
              <Link_1.NavLink to={`/${post.uniqueName}/pt`}>{post.title}</Link_1.NavLink>
            </react_web_components_1.ListItem>))}
        </react_web_components_1.List>);
        default:
            return (<react_web_components_1.List>
          {posts.map((post) => (<react_web_components_1.ListItem key={post.id}>
              <Link_1.NavLink to={`/${post.uniqueName}/pt`}>{post.title}</Link_1.NavLink>
            </react_web_components_1.ListItem>))}
        </react_web_components_1.List>);
    }
};
exports.PostList = PostList;
//# sourceMappingURL=PostList.jsx.map