"use strict";
const minimatch = require("minimatch");
const constants = require("../constants");
const path = require("path");
const project_files_provider_base_1 = require("../common/services/project-files-provider-base");
class ProjectFilesProvider extends project_files_provider_base_1.ProjectFilesProviderBase {
    constructor($platformsData, $projectData, $mobileHelper, $options) {
        super($mobileHelper, $options);
        this.$platformsData = $platformsData;
        this.$projectData = $projectData;
    }
    mapFilePath(filePath, platform) {
        let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
        let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
        let parsedFilePath = this.getPreparedFilePath(filePath);
        let mappedFilePath = path.join(projectFilesPath, path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME), parsedFilePath));
        let appResourcesDirectoryPath = path.join(constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
        let platformSpecificAppResourcesDirectoryPath = path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName);
        if (parsedFilePath.indexOf(appResourcesDirectoryPath) > -1 && parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) === -1) {
            return null;
        }
        if (parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1) {
            let appResourcesRelativePath = path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, platformData.normalizedPlatformName), parsedFilePath);
            mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
        }
        return mappedFilePath;
    }
    isFileExcluded(filePath) {
        return !!_.find(ProjectFilesProvider.INTERNAL_NONPROJECT_FILES, (pattern) => minimatch(filePath, pattern, { nocase: true }));
    }
}
ProjectFilesProvider.INTERNAL_NONPROJECT_FILES = ["**/*.ts"];
exports.ProjectFilesProvider = ProjectFilesProvider;
$injector.register("projectFilesProvider", ProjectFilesProvider);
