"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CountrySelect = void 0;
const react_1 = __importStar(require("react"));
const lodash_1 = require("lodash");
const countriesList_1 = require("../../utils/countriesList");
const Select_1 = require("../Select");
const Option_1 = require("./Option");
const getOptions = (setOptions, props) => __awaiter(void 0, void 0, void 0, function* () {
    const flags = yield countriesList_1.getFlagsAsync();
    const countriesList = yield countriesList_1.getCountriesListAsync();
    const countriesWithFlag = yield countriesList_1.getCountriesWithFlagAsync();
    const options = Object.keys(countriesWithFlag).map((countryCode) => {
        const option = {
            value: countryCode,
            label: (react_1.default.createElement(Option_1.Option, { icon: react_1.default.createElement("img", { src: flags[lodash_1.camelCase(countriesWithFlag[countryCode])], width: 25, height: 25 }), label: countriesList[countryCode] })),
        };
        if (props.disabledOptions &&
            props.disabledOptions.indexOf(countryCode) !== -1) {
            option.isDisabled = true;
        }
        return option;
    });
    setOptions(options);
});
exports.CountrySelect = (_a) => {
    var { options: optionsProp = [] } = _a, otherProps = __rest(_a, ["options"]);
    const [options, setOptions] = react_1.useState(optionsProp);
    react_1.useEffect(() => {
        if (!options.length) {
            getOptions(setOptions, otherProps);
        }
    }, [options.length, otherProps]);
    return (react_1.default.createElement(Select_1.Select, Object.assign({ options: options, isDisabled: !options.length }, otherProps)));
};
//# sourceMappingURL=CountrySelect.js.map