"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var countries_1 = require("../../../core/utils/countries");
exports.CountryDropdown = function (_a) {
    var selectedCountry = _a.selectedCountry, setCountry = _a.setCountry, setCurrency = _a.setCurrency;
    var _b = __read(react_1.useState(false), 2), expanded = _b[0], setExpanded = _b[1];
    var onDropdownItemClick = function (selectedCountry, currency) {
        setExpanded(false);
        setCountry(selectedCountry);
    };
    var countrySelectionButton = function () {
        var country = countries_1.countries.find(function (_a) {
            var name = _a.name;
            return name === selectedCountry;
        });
        var _a = country || {}, name = _a.name, code = _a.code;
        var flag = code && require("../../assets/flags/" + code.toLowerCase() + ".svg");
        return (react_1.default.createElement("button", { onClick: function () { return setExpanded(!expanded); }, key: name || 'no-country', className: "country-select-btn country-select-toggle " + (expanded ? 'expanded' : '') },
            flag && react_1.default.createElement("img", { src: flag, alt: "", className: "country-select-img" }),
            react_1.default.createElement("p", { className: "country-select-text" }, name || 'Select your country')));
    };
    var countrySelectionList = function () {
        if (expanded) {
            return (react_1.default.createElement("ul", { className: "country-select-list" }, countries_1.countries.map(function (country) { return (react_1.default.createElement("li", { key: country.name, className: "country-select-item" },
                react_1.default.createElement(CountryDropdownItem, __assign({}, country, { onDropdownItemClick: onDropdownItemClick })))); })));
        }
    };
    return (react_1.default.createElement("div", { className: "country-select" },
        countrySelectionButton(),
        countrySelectionList()));
};
var CountryDropdownItem = function (_a) {
    var name = _a.name, code = _a.code, currency = _a.currency, onDropdownItemClick = _a.onDropdownItemClick;
    return (react_1.default.createElement("button", { onClick: function () { return onDropdownItemClick(name, currency); }, className: "country-select-btn" },
        react_1.default.createElement("img", { src: require("../../assets/flags/" + code.toLowerCase() + ".svg"), alt: name + " flag", className: "country-select-img" }),
        react_1.default.createElement("p", { className: "country-select-text" }, name)));
};
//# sourceMappingURL=CountryDropdown.js.map