"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.enterAuthCodeStepSchema = exports.selectStepSchema = exports.sendKeysStepSchema = exports.enterTextMobileStepSchema = exports.enterTextBrowserStepSchema = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const shared_1 = require("./shared");
const find_descriptors_1 = require("../find-descriptors");
exports.enterTextBrowserStepSchema = shared_1.stepWithBrowserFindSchema
    .extend({
    text: shared_1.textOrSymbolSchema.describe('The text to enter (can contain {{@variables}})'),
    enterTextMode: zod_1.z
        .enum(['fill', 'press'])
        .optional()
        .describe("How to enter the text: 'fill' writes the value atomically; 'press' types character-by-character. When undefined, the runtime defaults to the legacy 'press' path."),
    doNotRetry: zod_1.z
        .boolean()
        .optional()
        .describe("When true, skip the read-after-write validation/retry on the 'press' path"),
})
    .describe('Type text into a browser element');
exports.enterTextMobileStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    find: find_descriptors_1.mobileFindDescriptorSchema.optional(),
    text: shared_1.textOrSymbolSchema,
    clearExistingText: zod_1.z
        .boolean()
        .optional()
        .describe('Clear the field before entering text'),
    useNativeKeyboard: zod_1.z
        .boolean()
        .optional()
        .describe('Use the device native keyboard for input'),
    sendCharByChar: zod_1.z.boolean().optional(),
    doNotRetry: zod_1.z.boolean().optional(),
    useSetValue: zod_1.z.boolean().optional(),
})
    .passthrough()
    .describe('Type text into a mobile element');
const keyPressSchema = zod_1.z.object({
    key: zod_1.z.string(),
    altKey: zod_1.z.boolean().optional(),
    ctrlKey: zod_1.z.boolean().optional(),
    metaKey: zod_1.z.boolean().optional(),
    shiftKey: zod_1.z.boolean().optional(),
});
const crossPlatformKeyPressSchema = keyPressSchema.extend({
    mac: keyPressSchema.optional(),
    windows: keyPressSchema.optional(),
});
exports.sendKeysStepSchema = shared_1.stepWithBrowserFindSchema
    .extend({
    keys: zod_1.z
        .array(crossPlatformKeyPressSchema)
        .min(1)
        .describe('Array of key presses with optional modifier keys'),
    sendKeys: zod_1.z
        .array(crossPlatformKeyPressSchema)
        .optional()
        .describe('Legacy alias for keys — older mablscript may use this field name'),
})
    .describe('Send keyboard key sequences to a browser element');
exports.selectStepSchema = shared_1.stepWithBrowserFindSchema
    .extend({
    selectOptionType: zod_1.z.enum(['any', 'exact']).optional(),
    value: zod_1.z.string().optional(),
    text: zod_1.z.string().optional(),
    position: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
    index: zod_1.z.number().optional(),
    selector_type: zod_1.z.string().optional(),
    uuid: zod_1.z.string().optional(),
})
    .describe('Choose an option from a select dropdown element');
exports.enterAuthCodeStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    find: zod_1.z.union([
        find_descriptors_1.findElementDescriptorSchema,
        find_descriptors_1.findCustomDescriptorSchema,
        find_descriptors_1.mobileFindDescriptorSchema,
    ]),
})
    .passthrough()
    .describe('Enter a TOTP authentication code into an element');
