"use strict";
var path = require("path");
var util = require("util");
var ProjectFilesProviderBase = (function () {
    function ProjectFilesProviderBase($mobileHelper, $options) {
        this.$mobileHelper = $mobileHelper;
        this.$options = $options;
    }
    ProjectFilesProviderBase.prototype.getPreparedFilePath = function (filePath) {
        var projectFileInfo = this.getProjectFileInfo(filePath);
        return path.join(path.dirname(filePath), projectFileInfo.onDeviceFileName);
    };
    ProjectFilesProviderBase.prototype.getProjectFileInfo = function (filePath, platform) {
        var parsed = this.parseFile(filePath, this.$mobileHelper.platformNames, platform || "");
        if (!parsed) {
            parsed = this.parseFile(filePath, ["debug", "release"], this.$options.release ? "release" : "debug");
        }
        return parsed || {
            filePath: filePath,
            onDeviceFileName: path.basename(filePath),
            shouldIncludeFile: true
        };
    };
    ProjectFilesProviderBase.prototype.parseFile = function (filePath, validValues, value) {
        var regex = util.format("^(.+?)[.](%s)([.].+?)$", validValues.join("|"));
        var parsed = filePath.match(new RegExp(regex, "i"));
        if (parsed) {
            return {
                filePath: filePath,
                onDeviceFileName: path.basename(parsed[1] + parsed[3]),
                shouldIncludeFile: parsed[2].toLowerCase() === value.toLowerCase()
            };
        }
        return null;
    };
    return ProjectFilesProviderBase;
})();
exports.ProjectFilesProviderBase = ProjectFilesProviderBase;
