"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __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 });
const classnames_1 = __importDefault(require("classnames"));
const dayjs_1 = __importDefault(require("dayjs"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const AutoAutoHeight_1 = __importDefault(require("../../../animations/AutoAutoHeight"));
const Icon_1 = __importStar(require("../Icon/Icon"));
const RatioImage_1 = __importDefault(require("../RatioImage/RatioImage"));
const Text_1 = __importStar(require("../Text"));
const Translation_1 = require("../../../translations/Translation");
const Color_1 = require("../../../util/Color");
const TextAlignment_1 = require("../../../util/TextAlignment");
const EventCard_module_scss_1 = __importDefault(require("./EventCard.module.scss"));
const EventCard = ({ event, ratio }) => {
    var _a, _b, _c, _d, _e, _f;
    const { t } = (0, react_i18next_1.useTranslation)();
    const [collapsed, setCollapsed] = (0, react_1.useState)(true);
    const onClickToggleCollapse = (buttonEvent) => {
        setCollapsed(!collapsed);
        buttonEvent.preventDefault();
        buttonEvent.stopPropagation();
    };
    const onClickMoreLink = (buttonEvent) => {
        window.open(event.url, '_blank', 'noreferrer');
        buttonEvent.preventDefault();
        buttonEvent.stopPropagation();
    };
    const displayEventTime = () => {
        const startDate = event.startDate ? (0, dayjs_1.default)(event.startDate) : undefined;
        const endDate = event.endDate ? (0, dayjs_1.default)(event.endDate) : undefined;
        if ([startDate, endDate].some((date) => !date)) {
            return `${startDate ? startDate.format(`ddd, MMM D, h:mmA`) : 'Now'}${endDate ? ` - ${endDate.format(`ddd, MMM D, h:mmA`)}` : ''}`;
        }
        else {
            if (startDate.isSame(endDate, 'date')) {
                return `${startDate.format(`ddd, MMM D, h:mmA`)} - ${endDate.format(`h:mmA`)}`;
            }
            else
                return `${startDate.format(`ddd, MMM D, h:mmA`)} - ${endDate.format(`ddd, MMM D, h:mmA`)}`;
        }
    };
    return (react_1.default.createElement("div", { className: EventCard_module_scss_1.default.root },
        react_1.default.createElement(RatioImage_1.default, { src: `${(_a = event === null || event === void 0 ? void 0 : event.image) === null || _a === void 0 ? void 0 : _a.url}`, ratio: ratio, style: {
                backgroundRepeat: 'no-repeat',
                backgroundPosition: 'top center',
            } }),
        react_1.default.createElement("div", { className: EventCard_module_scss_1.default.categoryMask },
            react_1.default.createElement(Text_1.default, { align: TextAlignment_1.TextAlign.Right, color: Color_1.Color.White, bold: true }, (_c = (_b = event.tags) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.display_name)),
        react_1.default.createElement("div", { className: EventCard_module_scss_1.default.content },
            react_1.default.createElement("div", { className: (0, classnames_1.default)(EventCard_module_scss_1.default.header) },
                react_1.default.createElement("div", null,
                    react_1.default.createElement(Text_1.default, { className: (0, classnames_1.default)({
                            'u-text-overflow-ellipsis-1': collapsed,
                            'u-text-overflow-ellipsis-2': !collapsed,
                        }), bold: true, color: Color_1.Color.Navy }, event.name),
                    react_1.default.createElement(Text_1.default, { color: Color_1.Color.Accent, bold: true }, event.eventTimeDescription ? event.eventTimeDescription : displayEventTime())),
                react_1.default.createElement("button", { className: (0, classnames_1.default)(EventCard_module_scss_1.default.collapButton, 'u-cursor-pointer', '--no-icon-animate'), onClick: onClickToggleCollapse },
                    react_1.default.createElement(Icon_1.default, { className: (0, classnames_1.default)(EventCard_module_scss_1.default.buttonIcon), color: Color_1.Color.Accent, icon: collapsed ? Icon_1.IconType.ArrowUp3 : Icon_1.IconType.ArrowDown3, size: "18px" }))),
            react_1.default.createElement(AutoAutoHeight_1.default, { open: !collapsed },
                react_1.default.createElement("div", { className: "u-pad-top--light" },
                    react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Accent }, [(_d = event === null || event === void 0 ? void 0 : event.address) === null || _d === void 0 ? void 0 : _d.line1, (_e = event === null || event === void 0 ? void 0 : event.address) === null || _e === void 0 ? void 0 : _e.line2, (_f = event === null || event === void 0 ? void 0 : event.address) === null || _f === void 0 ? void 0 : _f.city].filter((item) => !!item).join(', ')),
                    react_1.default.createElement(Text_1.default, { className: "u-text-overflow-ellipsis-3", color: Color_1.Color.DarkGrey, type: Text_1.TextType.Small }, event.summary)),
                event.url && (react_1.default.createElement("button", { className: (0, classnames_1.default)(EventCard_module_scss_1.default.linkButton, '--no-icon-animate'), onClick: onClickMoreLink },
                    react_1.default.createElement(Text_1.default, { className: (0, classnames_1.default)(EventCard_module_scss_1.default.footer, 'u-flex', 'u-flex-gap--light', 'u-flex-align-center'), type: Text_1.TextType.Label, color: Color_1.Color.Accent },
                        react_1.default.createElement("div", null, t(Translation_1.Translation.Misc.MoreInfo)),
                        react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.ArrowRight }))))))));
};
exports.default = EventCard;
//# sourceMappingURL=EventCard.js.map