1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.formatDeviceFamilies = formatDeviceFamilies;
7exports.getDeviceFamilies = getDeviceFamilies;
8exports.getIsTabletOnly = getIsTabletOnly;
9exports.getSupportsTablet = getSupportsTablet;
10exports.setDeviceFamily = setDeviceFamily;
11exports.withDeviceFamily = void 0;
12
13function _iosPlugins() {
14  const data = require("../plugins/ios-plugins");
15
16  _iosPlugins = function () {
17    return data;
18  };
19
20  return data;
21}
22
23function _warnings() {
24  const data = require("../utils/warnings");
25
26  _warnings = function () {
27    return data;
28  };
29
30  return data;
31}
32
33const withDeviceFamily = config => {
34  return (0, _iosPlugins().withXcodeProject)(config, async config => {
35    config.modResults = await setDeviceFamily(config, {
36      project: config.modResults
37    });
38    return config;
39  });
40};
41
42exports.withDeviceFamily = withDeviceFamily;
43
44function getSupportsTablet(config) {
45  var _config$ios;
46
47  return !!((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.supportsTablet);
48}
49
50function getIsTabletOnly(config) {
51  var _config$ios2;
52
53  return !!(config !== null && config !== void 0 && (_config$ios2 = config.ios) !== null && _config$ios2 !== void 0 && _config$ios2.isTabletOnly);
54}
55
56function getDeviceFamilies(config) {
57  var _config$ios3;
58
59  const supportsTablet = getSupportsTablet(config);
60  const isTabletOnly = getIsTabletOnly(config);
61
62  if (isTabletOnly && ((_config$ios3 = config.ios) === null || _config$ios3 === void 0 ? void 0 : _config$ios3.supportsTablet) === false) {
63    (0, _warnings().addWarningIOS)('ios.supportsTablet', `Found contradictory values: \`{ ios: { isTabletOnly: true, supportsTablet: false } }\`. Using \`{ isTabletOnly: true }\`.`);
64  } // 1 is iPhone, 2 is iPad
65
66
67  if (isTabletOnly) {
68    return [2];
69  } else if (supportsTablet) {
70    return [1, 2];
71  } else {
72    // is iPhone only
73    return [1];
74  }
75}
76/**
77 * Wrapping the families in double quotes is the only way to set a value with a comma in it.
78 *
79 * @param deviceFamilies
80 */
81
82
83function formatDeviceFamilies(deviceFamilies) {
84  return `"${deviceFamilies.join(',')}"`;
85}
86/**
87 * Add to pbxproj under TARGETED_DEVICE_FAMILY
88 */
89
90
91function setDeviceFamily(config, {
92  project
93}) {
94  const deviceFamilies = formatDeviceFamilies(getDeviceFamilies(config));
95  const configurations = project.pbxXCBuildConfigurationSection(); // @ts-ignore
96
97  for (const {
98    buildSettings
99  } of Object.values(configurations || {})) {
100    // Guessing that this is the best way to emulate Xcode.
101    // Using `project.addToBuildSettings` modifies too many targets.
102    if (typeof (buildSettings === null || buildSettings === void 0 ? void 0 : buildSettings.PRODUCT_NAME) !== 'undefined') {
103      buildSettings.TARGETED_DEVICE_FAMILY = deviceFamilies;
104    }
105  }
106
107  return project;
108}
109//# sourceMappingURL=DeviceFamily.js.map