'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var formik = require('formik');
var phoneNumber = require('./phone-number-CkAhqr7l.js');
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var Typography = require('@bigbinary/neetoui/Typography');
var Button = require('@bigbinary/neetoui/Button');
var CopyToClipboardButton = require('./CopyToClipboardButton.js');
require('@tanstack/react-query');
require('libphonenumber-js/min');
require('@bigbinary/neetoui/Input');
require('@bigbinary/neetoui/Select');
require('react-i18next');
require('./_commonjsHelpers-BJu3ubxk.js');
require('ramda');
require('@bigbinary/neetoui/Tooltip');
require('@babel/runtime/helpers/asyncToGenerator');
require('i18next');
require('@bigbinary/neeto-commons-frontend/utils');
require('yup');
require('axios');
require('./inject-css-B6qYtOJe.js');
require('@bigbinary/neeto-commons-frontend/utils/general');
require('@bigbinary/neeto-icons/Copy');
require('@bigbinary/neeto-icons/Check');

var _excluded$1 = ["name"];
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var FormikPhoneNumberInput = function FormikPhoneNumberInput(_ref) {
  var name = _ref.name,
    props = _objectWithoutProperties(_ref, _excluded$1);
  var _useField = formik.useField(name),
    _useField2 = _slicedToArray(_useField, 3),
    field = _useField2[0],
    meta = _useField2[1],
    setValue = _useField2[2].setValue;
  return /*#__PURE__*/jsxRuntime.jsx(phoneNumber.PhoneNumberInput, _objectSpread$1(_objectSpread$1({}, field), {}, {
    error: meta.touched ? meta.error : "",
    onChange: setValue
  }, props));
};

var _excluded = ["className", "defaultCountry", "value", "showEmoji", "children", "linkable", "linkPrefix", "showCopyButton"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var PhoneNumber = function PhoneNumber(_ref) {
  var className = _ref.className,
    _ref$defaultCountry = _ref.defaultCountry,
    defaultCountry = _ref$defaultCountry === void 0 ? "IN" : _ref$defaultCountry,
    value = _ref.value,
    _ref$showEmoji = _ref.showEmoji,
    showEmoji = _ref$showEmoji === void 0 ? false : _ref$showEmoji,
    children = _ref.children,
    _ref$linkable = _ref.linkable,
    linkable = _ref$linkable === void 0 ? false : _ref$linkable,
    _ref$linkPrefix = _ref.linkPrefix,
    linkPrefix = _ref$linkPrefix === void 0 ? "tel:" : _ref$linkPrefix,
    _ref$showCopyButton = _ref.showCopyButton,
    showCopyButton = _ref$showCopyButton === void 0 ? false : _ref$showCopyButton,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  if (neetoCist.isNotPresent(value) && neetoCist.isNotPresent(children)) return null;
  var _getPhoneData = phoneNumber.getPhoneData(value || children, defaultCountry),
    international = _getPhoneData.international,
    countryCode = _getPhoneData.countryCode;
  var link = linkable ? "".concat(linkPrefix).concat(value) : undefined;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: classnames(["flex items-center gap-x-2", className]),
    children: [/*#__PURE__*/jsxRuntime.jsx(phoneNumber.SingleValue, _objectSpread({}, _objectSpread({
      countryCode: countryCode,
      showEmoji: showEmoji
    }, otherProps))), /*#__PURE__*/jsxRuntime.jsx(Typography, _objectSpread(_objectSpread({
      style: "body2"
    }, otherProps), {}, {
      children: linkable ? /*#__PURE__*/jsxRuntime.jsx(Button, {
        className: "neeto-molecules-phone-number truncate",
        "data-cy": "phone-number-link",
        "data-testid": "phone-number-link",
        href: link,
        style: "link",
        children: international
      }) : international
    })), showCopyButton && /*#__PURE__*/jsxRuntime.jsx(CopyToClipboardButton, {
      className: "flex-shrink-0",
      size: "small",
      style: "text",
      value: international
    })]
  });
};
var PhoneNumber$1 = /*#__PURE__*/React.memo(PhoneNumber);

exports.PhoneNumberInput = phoneNumber.PhoneNumberInput;
exports.isPhoneNumberValid = phoneNumber.isPhoneNumberValid;
exports.validation = phoneNumber.validation;
exports.FormikPhoneNumberInput = FormikPhoneNumberInput;
exports.PhoneNumber = PhoneNumber$1;
//# sourceMappingURL=PhoneNumber.js.map
