"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.STARTING_TAB_SELECTOR = exports.MAILBOX_FEATURE = void 0;
exports.isFindTabDescriptor = isFindTabDescriptor;
exports.humanizeFind = humanizeFind;
exports.humanizeCustomFind = humanizeCustomFind;
exports.humanizeQuery = humanizeQuery;
exports.humanizeWaitUntil = humanizeWaitUntil;
exports.isPasswordField = isPasswordField;
exports.findDescriptorToAIString = findDescriptorToAIString;
exports.findDescriptorToAIObject = findDescriptorToAIObject;
const dom_util_1 = require("@mablhq-internal/mablscript-find/dom-util");
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
const elementUtils_1 = require("../../capture/elementUtils");
const variable_utils_1 = require("../../variable-utils");
const variable_names_util_1 = require("../../variable-names-util");
const mablscript_utils_1 = require("../mablscript-utils");
const BaseStep_1 = __importDefault(require("./BaseStep"));
const type_utils_1 = require("../../type-utils");
const MablscriptImporterUtil_1 = require("../MablscriptImporterUtil");
const stepUtil_1 = require("@mablhq/test-model/mobile/steps/stepUtil");
const mobile_constants_1 = require("../../mobile-constants");
const yaml_utils_1 = require("../yaml-utils");
exports.MAILBOX_FEATURE = Object.freeze({
    id: 'mailbox',
    label: 'mabl Mailbox',
});
exports.STARTING_TAB_SELECTOR = 'initial';
class StepWithFindImpl extends BaseStep_1.default {
    constructor(stepType, findDescriptor, findOptions = {}) {
        super(stepType);
        this.findDescriptor = findDescriptor;
        this.findOptions = findOptions;
        if (findDescriptor && findDescriptor.type === 'email') {
            this.mergeOptions({ feature: exports.MAILBOX_FEATURE });
        }
    }
    static getAdditionalDetailsList(selector) {
        return {
            findDetails: StepWithFindImpl.getSelectorDetailsList(selector),
        };
    }
    static getSelectorDetailsList(selector) {
        const selectorInfo = {};
        Object.entries(selector)
            .filter(([_attribute, value]) => typeof value === 'string')
            .forEach(([attribute, val]) => {
            const additionalDetailSelectors = elementUtils_1.ADDITIONAL_DETAIL_SELECTORS_HUMANIZED;
            const selectorKey = additionalDetailSelectors[attribute];
            if (selectorKey) {
                selectorInfo[selectorKey] = val;
            }
        });
        return selectorInfo;
    }
    getTargetElementSelector() {
        return getTargetElementSelector(this);
    }
    findDescriptorToAIString() {
        return findDescriptorToAIString(this.findDescriptor, this.findOptions);
    }
    findDescriptorToMablscript() {
        switch (this.findDescriptor.type) {
            case 'find_first':
            case 'find_last':
            case 'find_all':
                return this.generateMablscriptCustomFind(this.findDescriptor);
            case mablscriptFind_1.FindType.FIND_ONE:
            case 'find_one':
                return this.generateMablscriptFindOne(this.findDescriptor);
            case 'email':
                return this.generateMablscriptFindEmail(this.findDescriptor);
            case 'location':
                return this.generateMablscriptGetCurrentLocation();
            case 'cookie':
                return this.generateMablscriptFindCookie(this.findDescriptor);
            case 'find_tab':
                return this.generateMablscriptFindTab(this.findDescriptor);
            case 'viewport':
                return undefined;
        }
        return;
    }
    generateMablscriptCustomFind(findDescriptor) {
        const functionName = findDescriptor.type;
        const primarySelector = (0, mablscriptFind_1.buildElementSelectorString)(findDescriptor.primarySelectors);
        const foundElementSelector = (0, mablscriptFind_1.buildElementSelectorString)((0, mablscriptFind_1.getFoundTargetSelector)(findDescriptor));
        const findOptionsParameter = buildFindOptionsString(this.findOptions);
        if (findOptionsParameter) {
            return `${functionName}(${primarySelector}, ${foundElementSelector}, ${findOptionsParameter})`;
        }
        return `${functionName}(${primarySelector}, ${foundElementSelector})`;
    }
    generateMablscriptFindOne(findDescriptor) {
        const selectorParameter = this.generateFindOneDescriptorString(findDescriptor);
        const findOptionsParameter = buildFindOptionsString(this.findOptions);
        if (findOptionsParameter) {
            return `find_one(${selectorParameter}, ${findOptionsParameter})`;
        }
        return `find_one(${selectorParameter})`;
    }
    generateFindOneDescriptorString(findDescriptor) {
        const targetDescriptor = (0, mablscriptFind_1.getTargetFindDescriptor)(findDescriptor);
        const ancestorDescriptor = (0, mablscriptFind_1.getAncestorFindDescriptor)(findDescriptor);
        if (findDescriptor.shadowParents?.length) {
            const targetString = (0, mablscriptFind_1.buildFindDescriptorString)(targetDescriptor);
            if (!ancestorDescriptor) {
                return targetString;
            }
            const ancestorString = (0, mablscriptFind_1.buildFindDescriptorString)(ancestorDescriptor);
            return `[${targetString}, ${ancestorString}]`;
        }
        let targetString = (0, mablscriptFind_1.buildFindDescriptorString)(targetDescriptor);
        if ((0, mablscriptFind_1.isMobileFindSpecification)(this.findDescriptor)) {
            targetString = this.cleanMobileElementAttributes(JSON.stringify(targetDescriptor.selector));
        }
        if (!ancestorDescriptor) {
            return targetString;
        }
        let ancestorString = (0, mablscriptFind_1.buildFindDescriptorString)(ancestorDescriptor);
        if ((0, mablscriptFind_1.isMobileFindSpecification)(ancestorDescriptor)) {
            ancestorString = this.cleanMobileElementAttributes(JSON.stringify(ancestorDescriptor.selector));
        }
        return `[${targetString}, ${ancestorString}]`;
    }
    cleanMobileElementAttributes(descriptorString) {
        return descriptorString
            .replace(/\u2028/gu, '\\u2028')
            .replace(/\u2029/gu, '\\u2029');
    }
    generateMablscriptGetCurrentLocation() {
        return 'get_current_location()';
    }
    generateMablscriptFindCookie(findDescriptor) {
        return `find_cookie(${(0, mablscriptFind_1.buildCookieSelectorString)(findDescriptor.cookieSelector)})`;
    }
    generateMablscriptFindTab(findDescriptor) {
        if (findDescriptor.foundTabSelectors) {
            if (findDescriptor.foundTabSelectors.uuid === exports.STARTING_TAB_SELECTOR) {
                return `find_tab("${exports.STARTING_TAB_SELECTOR}")`;
            }
            return `find_tab(${(0, mablscriptFind_1.buildTabSelectorString)(findDescriptor.foundTabSelectors)})`;
        }
        return `find_tab(${JSON.stringify(findDescriptor)})`;
    }
    generateMablscriptFindEmail(emailDescriptor) {
        const normalizedDescriptor = (0, mablscriptFind_1.convertToNormalizedFindEmailDescriptor)(emailDescriptor);
        const descriptorString = (0, mablscriptFind_1.buildFindEmailDescriptorString)(normalizedDescriptor);
        return `find_email(${descriptorString})`;
    }
    inputVariables() {
        const patterns = [];
        let pattern;
        switch (this.findDescriptor.type) {
            case 'find_first':
            case 'find_all':
            case 'find_last':
                pattern =
                    this.findDescriptor.primarySelectors
                        .css_query ||
                        this.findDescriptor.primarySelectors.xpath;
                if (pattern) {
                    patterns.push(pattern);
                }
                break;
            case 'email':
                const EMAIL_INPUT_PROPERTIES = [
                    'from',
                    'to_received',
                    'subject',
                    'body_text',
                ];
                EMAIL_INPUT_PROPERTIES.forEach((property) => {
                    const findDescriptor = this.findDescriptor;
                    const propertyValue = findDescriptor.emailSelector[property];
                    if (propertyValue) {
                        patterns.push(propertyValue);
                    }
                    findDescriptor.emailConfiguration?.emailPreferences?.[property]?.forEach((preference) => {
                        if (preference?.value) {
                            patterns.push(preference.value);
                        }
                    });
                });
                break;
            case 'find_one':
                patterns.push(...Object.values(this.findDescriptor.configuration?.propertyPreferences || {})
                    .map((preference) => preference?.value)
                    .filter((value) => value)
                    .map((value) => value));
                this.findDescriptor.auxiliaryDescriptors?.forEach((auxiliaryDescriptor) => {
                    patterns.push(...Object.values(auxiliaryDescriptor.configuration?.propertyPreferences || {})
                        .map((preference) => preference?.value)
                        .filter((value) => value)
                        .map((value) => value));
                });
        }
        const variableNames = [];
        patterns
            .map(variable_names_util_1.extractVariableNamesFromPattern)
            .forEach((names) => variableNames.push(...names));
        return (0, type_utils_1.distinct)(variableNames);
    }
    static getFindDescriptorAndFindOptions(mablStep, importer) {
        if (isMablStepWithFindAction(mablStep) && mablStep.findAction) {
            return this.getFindDescriptorAndFindOptionsFromFindAction(mablStep.findAction, importer);
        }
        return {};
    }
    static getFindDescriptorAndFindOptionsFromFindAction(findAction, importer) {
        let findOptions;
        const findDescriptor = findAction?.toDescriptor();
        if ((0, mablscriptFind_1.isFindElementDescriptor)(findDescriptor)) {
            findOptions = findDescriptor.findOptions;
        }
        if (findDescriptor.hints) {
            findOptions = { ...findOptions, hints: findDescriptor.hints };
        }
        if (findDescriptor && !isFindTabDescriptor(findDescriptor)) {
            if ((0, mablscriptFind_1.isCustomFindDescriptor)(findDescriptor)) {
                let finalType = findDescriptor.findType;
                if (finalType === mablscriptFind_1.FindType.FIND_ANY) {
                    finalType = mablscriptFind_1.FindType.FIND_FIRST;
                }
                if ((finalType === mablscriptFind_1.FindType.FIND_LAST ||
                    mablscriptFind_1.FindType.FIND_FIRST ||
                    mablscriptFind_1.FindType.FIND_ALL) &&
                    findAction.args.length > 1) {
                    return this.getFindDescriptorForFindArgsArray(findAction, finalType, importer.variables);
                }
                return {
                    findDescriptor: {
                        type: finalType,
                        foundElementSelectors: findDescriptor.foundElementSelectors,
                        primarySelectors: findDescriptor.primarySelectors,
                    },
                    findOptions,
                };
            }
            const targetInfo = findDescriptor.findTarget;
            if ((0, mablscriptFind_1.isNormalizedFindDescriptor)(targetInfo)) {
                if (targetInfo.configuration || targetInfo.shadowParents) {
                    delete targetInfo.selector?.selector_type;
                }
                targetInfo.auxiliaryDescriptors?.forEach((descriptor, index) => {
                    if ((0, mablscriptFind_1.isInvalidElementSelectors)(descriptor.selector)) {
                        descriptor.selector = (0, MablscriptImporterUtil_1.createAndRegisterSelector)(importer.flowSteps.flowSelectors, descriptor.selector);
                    }
                    if (!descriptor.type && targetInfo.auxiliaryDescriptors) {
                        targetInfo.auxiliaryDescriptors[index].type = mablscriptFind_1.FindType.FIND_ONE;
                    }
                });
            }
            if ((0, mablscriptFind_1.isInvalidElementSelectors)(targetInfo.selector)) {
                targetInfo.selector = (0, MablscriptImporterUtil_1.createAndRegisterSelector)(importer.flowSteps.flowSelectors, targetInfo.selector);
            }
            return {
                findDescriptor: {
                    type: findDescriptor.findType,
                    ...targetInfo,
                },
                findOptions,
            };
        }
        return {
            findDescriptor,
            findOptions,
        };
    }
    static getFindDescriptorForFindArgsArray(findAction, finalFindType, variables) {
        const [primarySelectors, foundElementSelectors, findOptions] = findAction.args;
        const newPrimarySelectors = (0, variable_utils_1.canonicalizeVariablePatternsInObject)(variables, primarySelectors);
        return {
            findDescriptor: {
                type: finalFindType,
                foundElementSelectors,
                primarySelectors: newPrimarySelectors,
            },
            findOptions,
        };
    }
}
exports.default = StepWithFindImpl;
function isMablStepWithFindAction(value) {
    return value.findAction?.toDescriptor;
}
function buildFindOptionsString(findOptions) {
    if (!findOptions) {
        return '';
    }
    const findOptionsString = (0, mablscriptFind_1.buildStepArgumentString)({
        params: { ...findOptions },
        legacy: true,
    });
    if (!findOptionsString || findOptionsString === '{}') {
        return '';
    }
    return findOptionsString;
}
function pluralizeAttributes(numAttributes) {
    return numAttributes > 1 ? 'attributes' : 'attribute';
}
function isFindTabDescriptor(value) {
    return value && value.findType === mablscriptFind_1.FindType.FIND_TAB;
}
function humanizeFind(step) {
    switch (step.findDescriptor.type) {
        case 'find_first':
        case 'find_last':
        case 'find_all':
            return humanizeCustomFind(step.findDescriptor);
        case mablscriptFind_1.FindType.FIND_ONE:
        case 'find_one':
            const maybeMobileFindDescriptor = (0, mablscriptFind_1.isMobileFindSpecification)(step.findDescriptor)
                ? {
                    findTarget: { ...step.findDescriptor },
                    findType: step.findDescriptor.type,
                }
                : step.findDescriptor;
            if ((0, mablscriptFind_1.isMobileFindDescriptor)(maybeMobileFindDescriptor)) {
                return (0, stepUtil_1.getElementDescriptionFromMobileFindDescriptor)(maybeMobileFindDescriptor);
            }
            return humanizeFindOneWithQueryFallback(step.findDescriptor);
        case 'email':
            return humanizeFindEmail(step.findDescriptor);
        case 'location':
            return humanizeGetCurrentLocation(step.findDescriptor);
        case 'cookie':
            return humanizeFindCookie(step.findDescriptor);
        case 'find_tab':
            return humanizeFindTab(step.findDescriptor);
    }
    return;
}
function humanizeCustomFind(findDescriptor) {
    const type = findDescriptor.type.substring(5);
    let tagText;
    const tagName = (0, mablscriptFind_1.getFoundTargetSelector)(findDescriptor)?.tag_name;
    if (tagName) {
        tagText = `${type} ${(0, mablscriptFind_1.humanizeTag)({
            tag_name: tagName,
            uuid: '',
        })}`;
    }
    else {
        const s = findDescriptor.type === 'find_all' ? 's' : '';
        tagText = `${type} element${s}`;
    }
    return `${tagText} ${humanizeQuery(findDescriptor)}`;
}
function humanizeQuery(findDescriptor) {
    if (findDescriptor.primarySelectors?.css_query) {
        return `matching css query "${(0, dom_util_1.compactWhitespace)(findDescriptor.primarySelectors.css_query)}"`;
    }
    else if (findDescriptor.primarySelectors?.xpath) {
        return `matching xpath "${(0, dom_util_1.compactWhitespace)(findDescriptor.primarySelectors.xpath)}"`;
    }
    return 'matching "<unrecognized query>"';
}
function humanizeFindEmail(emailDescriptor) {
    const normalizedDescriptor = (0, mablscriptFind_1.convertToNormalizedFindEmailDescriptor)(emailDescriptor);
    return (0, mablscriptFind_1.humanizeEmailSelector)(normalizedDescriptor.selector);
}
function humanizeGetCurrentLocation(findDescriptor) {
    return findDescriptor.url ? `URL ${findDescriptor.url}` : 'current URL';
}
function humanizeFindOneWithQueryFallback(findDescriptor) {
    const selector = (0, mablscriptFind_1.getFoundTargetSelector)(findDescriptor);
    if (selector && !selector.tag_name) {
        if (selector.xpath) {
            return `an element matching xpath "${(0, dom_util_1.compactWhitespace)(selector.xpath)}"`;
        }
        if (selector.css_query) {
            return `an element matching css query "${(0, dom_util_1.compactWhitespace)(selector.css_query)}"`;
        }
    }
    return (0, mablscriptFind_1.humanizeFindOneDescriptor)(findDescriptor);
}
function humanizeFindCookie(findDescriptor) {
    return (0, mablscriptFind_1.humanizeCookieSelector)(findDescriptor.cookieSelector);
}
function humanizeFindTab(findDescriptor) {
    if (findDescriptor.foundTabSelectors.uuid === exports.STARTING_TAB_SELECTOR) {
        return 'the initial tab';
    }
    return (0, mablscriptFind_1.humanizeTabSelector)(findDescriptor.foundTabSelectors);
}
function humanizeWaitUntil(step) {
    if (!step.findOptions?.waitUntil) {
        return;
    }
    if (step.findDescriptor.type !== 'find_one') {
        return;
    }
    const isMobile = !!(0, mablscriptFind_1.isMobileFindSpecification)(step.findDescriptor);
    const humanizedSelectorsMap = (isMobile
        ? mobile_constants_1.MOBILE_FULL_ATTRIBUTE_OPTION_SELECTOR_KEYS
        : elementUtils_1.ADDITIONAL_DETAIL_SELECTORS_HUMANIZED);
    const { timeoutSeconds, properties } = step.findOptions.waitUntil;
    const foundElementSelectors = step.findDescriptor && (0, mablscriptFind_1.getFoundElementSelectors)(step.findDescriptor);
    if (!foundElementSelectors) {
        return;
    }
    const { targetAttributes, ancestorAttributes } = (0, mablscript_utils_1.getWaitUntilAttributes)(properties, foundElementSelectors);
    const stringTarget = (0, mablscriptFind_1.humanizeValueArray)(targetAttributes?.map((attribute) => humanizedSelectorsMap[attribute]));
    const stringAncestor = ancestorAttributes &&
        (0, mablscriptFind_1.humanizeValueArray)(ancestorAttributes.map((attribute) => humanizedSelectorsMap[attribute]));
    if (timeoutSeconds && (targetAttributes || ancestorAttributes)) {
        let waitString = `up to ${timeoutSeconds} seconds until`;
        if (targetAttributes) {
            waitString =
                waitString +
                    ` target element matching` +
                    ` ${stringTarget} ${pluralizeAttributes(targetAttributes.length)}`;
        }
        if (targetAttributes && ancestorAttributes) {
            waitString = waitString + ' and';
        }
        if (ancestorAttributes) {
            waitString =
                waitString +
                    ` ancestor element matching` +
                    ` ${stringAncestor} ${pluralizeAttributes(ancestorAttributes.length)}`;
        }
        waitString = waitString + ` is present`;
        return waitString;
    }
    return;
}
function isPasswordField(step) {
    const targetElementSelector = getTargetElementSelector(step);
    const tagName = targetElementSelector?.tag_name;
    return !!(tagName &&
        tagName.toLowerCase() === 'input' &&
        targetElementSelector &&
        targetElementSelector.inputElementType === 'password');
}
function getTargetElementSelector(step) {
    switch (step.findDescriptor.type) {
        case 'find_first':
        case 'find_last':
        case 'find_all':
        case 'find_one':
            return (0, mablscriptFind_1.getFoundTargetSelector)(step.findDescriptor);
    }
    return;
}
function findDescriptorToAIString(findDescriptor, findOptions = {}) {
    return (0, yaml_utils_1.toYaml)(findDescriptorToAIObject(findDescriptor, findOptions));
}
function findDescriptorToAIObject(descriptor, findOptions = {}) {
    switch (descriptor.type) {
        case 'find_one':
        case mablscriptFind_1.FindType.FIND_ONE:
            return buildElementAIObject(descriptor, findOptions);
        case 'find_first':
        case 'find_last':
        case 'find_all':
            return buildCustomFindAIObject(descriptor);
        case 'email':
            return buildEmailAIObject(descriptor);
        case 'cookie':
            return buildCookieAIObject(descriptor);
        case 'find_tab':
            return buildTabAIObject(descriptor);
        case 'location':
            return { type: 'location' };
        case 'viewport':
            return { type: 'viewport' };
        default:
            return { type: descriptor.type };
    }
}
function buildElementAIObject(descriptor, findOptions = {}) {
    const result = { type: 'element' };
    const selector = (0, mablscriptFind_1.getFoundTargetSelector)(descriptor);
    if (selector) {
        if (selector.tag_name) {
            result.tag = selector.tag_name;
        }
        if (selector.text) {
            result.text = selector.text;
        }
        if (selector.id) {
            result.id = selector.id;
        }
        if (selector.name) {
            result.name = selector.name;
        }
        if (selector.class_name) {
            result.class = selector.class_name;
        }
        if (selector.placeholder) {
            result.placeholder = selector.placeholder;
        }
        if (selector.aria_label) {
            result.aria_label = selector.aria_label;
        }
        if (selector.title) {
            result.title = selector.title;
        }
        if (selector.href) {
            result.href = selector.href;
        }
        if (selector.value) {
            result.value =
                selector.inputElementType?.toLowerCase() === 'password'
                    ? '***'
                    : selector.value;
        }
        if (selector.inputElementType) {
            result.input_type = selector.inputElementType;
        }
        if (selector.css_query) {
            result.css = selector.css_query;
        }
        if (selector.find_prompt) {
            result.visual_find_prompt = selector.find_prompt;
        }
    }
    const ancestorDescriptor = (0, mablscriptFind_1.getAncestorFindDescriptor)(descriptor);
    if (ancestorDescriptor) {
        const ancestorSelector = ancestorDescriptor.selector;
        if (ancestorSelector) {
            const ancestor = {};
            if (ancestorSelector.tag_name) {
                ancestor.tag = ancestorSelector.tag_name;
            }
            if (ancestorSelector.id) {
                ancestor.id = ancestorSelector.id;
            }
            if (ancestorSelector.text) {
                ancestor.text = ancestorSelector.text;
            }
            if (ancestorSelector.class_name) {
                ancestor.class = ancestorSelector.class_name;
            }
            if (Object.keys(ancestor).length > 0) {
                result.ancestor = ancestor;
            }
        }
    }
    const targetDescriptor = (0, mablscriptFind_1.getTargetFindDescriptor)(descriptor);
    const configuration = targetDescriptor?.configuration;
    if (configuration) {
        const configuredFind = {};
        if (configuration.ordinalPreference) {
            configuredFind.ordinal = {
                position: configuration.ordinalPreference.position,
                direction: configuration.ordinalPreference.ascending
                    ? 'ascending'
                    : 'descending',
            };
        }
        if (configuration.propertyPreferences) {
            const properties = {};
            for (const [key, preference] of Object.entries(configuration.propertyPreferences)) {
                if (preference?.intended) {
                    const comparator = preference.comparator?.toString() ?? 'equals';
                    const value = preference.value ?? '';
                    properties[key] = `${comparator} ${value}`.trim();
                }
            }
            if (Object.keys(properties).length > 0) {
                configuredFind.properties = properties;
            }
        }
        if (findOptions?.waitUntil) {
            configuredFind.wait_until_timeout_seconds = findOptions.waitUntil;
        }
        if (Object.keys(configuredFind).length > 0) {
            result.configured_find = configuredFind;
        }
    }
    return result;
}
function buildCustomFindAIObject(descriptor) {
    const result = {
        type: descriptor.type,
    };
    const targetSelector = (0, mablscriptFind_1.getFoundTargetSelector)(descriptor);
    if (targetSelector?.tag_name) {
        result.tag = targetSelector.tag_name;
    }
    if (descriptor.primarySelectors?.css_query) {
        result.css = descriptor.primarySelectors.css_query;
    }
    else if (descriptor.primarySelectors?.xpath) {
        result.xpath = descriptor.primarySelectors.xpath;
    }
    return result;
}
function buildEmailAIObject(descriptor) {
    const result = { type: 'email' };
    const selector = descriptor.emailSelector;
    if (selector) {
        if (selector.from) {
            result.from = selector.from;
        }
        if (selector.subject) {
            result.subject = selector.subject;
        }
        if (selector.to_received) {
            result.to = selector.to_received;
        }
        if (selector.body_text) {
            result.body_contains = selector.body_text;
        }
    }
    return result;
}
function buildCookieAIObject(descriptor) {
    const result = { type: 'cookie' };
    const selector = descriptor.cookieSelector;
    if (selector) {
        if (selector.name) {
            result.name = selector.name;
        }
        if (selector.domain) {
            result.domain = selector.domain;
        }
        if (selector.path) {
            result.path = selector.path;
        }
    }
    return result;
}
function buildTabAIObject(descriptor) {
    const result = { type: 'tab' };
    const selector = descriptor.foundTabSelectors;
    if (selector) {
        if (selector.uuid === exports.STARTING_TAB_SELECTOR) {
            result.initial = true;
        }
        else {
            if (selector.title) {
                result.title = selector.title;
            }
            if (selector.url) {
                result.url = selector.url;
            }
        }
    }
    return result;
}
