"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var to_poll_server_exports = {};
__export(to_poll_server_exports, {
  toCreatePollPayload: () => toCreatePollPayload,
  toPollServer: () => toPollServer
});
module.exports = __toCommonJS(to_poll_server_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
const toPollServer = (poll) => {
  return {
    ...toCreatePollPayload(poll),
    options: poll.options.map(toPollOption),
    id: poll.id,
    createdBy: poll.createdBy,
    count: poll.count,
    anonymousCount: poll.anonymousCount,
    creatorFlag: poll.creatorFlag,
    ownVotes: poll.ownVotes
  };
};
const toCreatePollPayload = (poll) => {
  return {
    title: poll.title,
    mediaId: poll.image.src.url,
    ownVotes: [],
    options: poll.options.map((option) => ({
      title: option.title,
      mediaId: option.image.src.url
    })),
    settings: {
      resultsVisibility: getResultsVisibility(poll.settings.permissions?.view),
      multipleVotes: !!poll.settings.permissions?.allowMultipleVotes,
      voteRole: getVoteRole(poll.settings.permissions?.vote),
      votersDisplay: !!poll.settings.showVoters,
      votesDisplay: !!poll.settings.showVotesCount
    }
  };
};
const toPollOption = (option) => {
  return {
    id: option.id,
    title: option.title,
    mediaId: option.image.src.url,
    count: option.count,
    anonymousCount: option.anonymousCount,
    rating: option.rating,
    latestVoters: option.latestVoters
  };
};
const getResultsVisibility = (view) => view === "EVERYONE" ? "ALWAYS" : view === "VOTERS" ? "VOTERS_ONLY" : "ONLY_ME";
const getVoteRole = (vote) => vote === import_v1.PollData_Poll_Settings_Permissions_VoteRole.UNRECOGNIZED || vote === void 0 ? "ALL" : vote;
//# sourceMappingURL=to-poll-server.js.map
