"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.switchContextStepSchema = exports.awaitTabStepSchema = exports.navigateStepSchema = exports.visitUrlStepSchema = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const find_descriptors_1 = require("../find-descriptors");
exports.visitUrlStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    url: zod_1.z
        .string()
        .describe('The URL to navigate to (can contain {{@variables}})'),
})
    .passthrough()
    .describe('Navigate the browser to a URL');
exports.navigateStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    navigation: zod_1.z
        .string()
        .describe("Navigation action to perform (currently only 'reload')"),
})
    .passthrough()
    .describe('Browser navigation action (reload)');
const tabSelectorSchema = zod_1.z
    .object({
    selector_type: zod_1.z.literal('tab'),
    url: zod_1.z.string(),
    uuid: zod_1.z.string().optional(),
    title: zod_1.z.string().optional(),
    id: zod_1.z.string().optional(),
    configuration: zod_1.z
        .object({
        ordinalPreference: zod_1.z
            .object({
            position: zod_1.z.number(),
            ascending: zod_1.z.boolean(),
        })
            .optional(),
        propertyPreferences: zod_1.z
            .record(zod_1.z.string(), zod_1.z.object({
            comparator: zod_1.z.enum(['equals', 'contains']).optional(),
            intended: zod_1.z.boolean(),
            value: zod_1.z.string().optional(),
        }))
            .optional(),
    })
        .optional(),
})
    .passthrough();
exports.awaitTabStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    tab: tabSelectorSchema,
})
    .passthrough()
    .describe('Wait for a new browser tab matching criteria to appear');
const switchTabVariantSchema = common_1.baseStepDescriptorSchema
    .extend({
    tab: find_descriptors_1.findTabDescriptorSchema,
    find: zod_1.z.unknown().optional(),
})
    .passthrough();
const switchFrameVariantSchema = common_1.baseStepDescriptorSchema
    .extend({
    frame: find_descriptors_1.findElementDescriptorSchema,
    find: zod_1.z.unknown().optional(),
})
    .passthrough();
const switchRootFrameVariantSchema = common_1.baseStepDescriptorSchema
    .extend({
    frame: zod_1.z.literal('root'),
    find: zod_1.z.unknown().optional(),
})
    .passthrough();
exports.switchContextStepSchema = zod_1.z
    .union([
    switchTabVariantSchema,
    switchRootFrameVariantSchema,
    switchFrameVariantSchema,
])
    .describe('Switch browser context to a different tab, frame, or back to root');
