"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var FeedbackContainer_stories_exports = {};
__export(FeedbackContainer_stories_exports, {
  AutoGeneratedDataOnly: () => AutoGeneratedDataOnly,
  Like: () => Like,
  LikeFailure: () => LikeFailure,
  Liked: () => Liked,
  Loading: () => Loading,
  Primary: () => Primary,
  QueryFailure: () => QueryFailure,
  default: () => FeedbackContainer_stories_default
});
module.exports = __toCommonJS(FeedbackContainer_stories_exports);
var import_test = require("@storybook/test");
var import_apollo = require("@nova/react-test-utils/apollo");
var import_FeedbackContainer = require("./FeedbackContainer");
var import_apolloCacheConfig = require("../../testing-utils/apolloCacheConfig");
var React = __toESM(require("react"), 1);
var import_schema = require("../../testing-utils/schema");
var import_resolvers = require("../../testing-utils/resolvers");
const telemetryEventMock = (0, import_test.fn)();
const meta = {
  component: import_FeedbackContainer.FeedbackContainer,
  decorators: [(0, import_apollo.getNovaDecorator)(import_schema.schema, { cache: import_apolloCacheConfig.cacheConfig })],
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => ({
          id: "feedback:42"
        }),
        Node: import_resolvers.defaultNodeResolver
      }
    }
  },
  render: () => /* @__PURE__ */ React.createElement(
    import_apollo.EventingInterceptor,
    {
      eventMap: {
        feedbackTelemetry: telemetryEventMock
      }
    },
    /* @__PURE__ */ React.createElement(import_FeedbackContainer.FeedbackContainer, null)
  )
};
var FeedbackContainer_stories_default = meta;
const AutoGeneratedDataOnly = {
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = (0, import_test.within)(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Like" });
    yield (0, import_test.expect)(button).toBeInTheDocument();
  })
};
const Primary = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = (0, import_test.within)(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Like" });
    yield (0, import_test.expect)(button).toBeInTheDocument();
  })
};
const Liked = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => __spreadProps(__spreadValues({}, sampleFeedback), {
          doesViewerLike: true
        })
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = (0, import_test.within)(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Unlike" });
    yield (0, import_test.expect)(button).toBeInTheDocument();
  })
};
const Like = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback,
        FeedbackLikeMutationResult: () => ({
          feedback: __spreadProps(__spreadValues({}, sampleFeedback), {
            doesViewerLike: true
          })
        })
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const container = (0, import_test.within)(canvasElement);
    const likeButton = yield container.findByRole("button", { name: "Like" });
    import_test.userEvent.click(likeButton);
    yield container.findByRole("button", { name: "Unlike" });
    let feedbackOperationEvents = [];
    yield (0, import_test.waitFor)(() => {
      feedbackOperationEvents = telemetryEventMock.mock.calls.filter(
        ([{ event }]) => {
          const operation = event.data().operation;
          return operation === "FeedbackLiked" || operation === "FeedbackUnliked";
        }
      );
      (0, import_test.expect)(feedbackOperationEvents).toHaveLength(1);
    });
    const call = feedbackOperationEvents[0];
    (0, import_test.expect)(call[0].event.data().operation).toBe("FeedbackLiked");
  })
};
const LikeFailure = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const {
      graphql: { mock }
    } = (0, import_apollo.getNovaEnvironmentForStory)(context);
    const container = (0, import_test.within)(context.canvasElement);
    yield (0, import_test.waitFor)(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      yield (0, import_test.expect)(operation).toBeDefined();
    }));
    yield mock.resolveMostRecentOperation(
      (operation) => import_apollo.MockPayloadGenerator.generate(operation, {
        Feedback: () => sampleFeedback
      })
    );
    const likeButton = yield container.findByRole("button", { name: "Like" });
    import_test.userEvent.click(likeButton);
    yield (0, import_test.waitFor)(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      (0, import_test.expect)(operation).toBeDefined();
    }));
    mock.rejectMostRecentOperation(new Error("Like failed"));
    yield container.findByText("Something went wrong");
  })
};
const QueryFailure = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const {
      graphql: { mock }
    } = (0, import_apollo.getNovaEnvironmentForStory)(context);
    yield (0, import_test.waitFor)(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      yield (0, import_test.expect)(operation).toBeDefined();
    }));
    yield mock.rejectMostRecentOperation(new Error("Query failed"));
    yield import_test.screen.findByText("Error: Query failed");
  })
};
const Loading = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = (0, import_test.within)(canvasElement);
    const loadingElement = yield canvas.findByText("Loading...");
    yield (0, import_test.expect)(loadingElement).toBeInTheDocument();
  })
};
const sampleFeedback = {
  id: "feedback:42",
  message: {
    text: "Feedback title"
  },
  doesViewerLike: false
};
