kui-crm 0.0.521 → 0.0.522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kui-crm",
3
- "version": "0.0.521",
3
+ "version": "0.0.522",
4
4
  "description": "crm complex fields",
5
5
  "main": "./cjs/index.js",
6
6
  "types": "./index.d.ts",
package/utils/index.d.ts CHANGED
@@ -793,19 +793,14 @@ type InputFileWithVisibilityFields =
793
793
 
794
794
  declare const setFileFromFileWithVisibility: (formData: FormData, document: InputFileWithVisibilityFields | FileStore, fileField: string, nameField?: string | undefined, visibilityField?: string | undefined, withUrl?: boolean | undefined) => void;
795
795
 
796
- declare const phoneSchema: yup.ObjectSchema<{
797
- phoneNumber: string;
798
- }, yup.AnyObject, {
799
- phoneNumber: undefined;
800
- }, "">;
801
- declare const positiveNumberSchema: yup.NumberSchema<number, yup.AnyObject, undefined, "">;
802
- declare const phoneWithConditionSchema: (condition: string) => yup.ObjectSchema<{
796
+ declare const getPositiveNumberSchema: (settings?: any) => yup.NumberSchema<number, yup.AnyObject, undefined, "">;
797
+ declare const phoneWithConditionSchema: (condition: string, settings?: any) => yup.ObjectSchema<{
803
798
  phoneNumber: string | null | undefined;
804
799
  } | null, yup.AnyObject, {
805
800
  phoneNumber: undefined;
806
801
  }, "">;
807
- declare const fieldWithConditionSchema: (condition: string) => yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
808
- declare const phoneNonRequiredSchema: (name: string) => yup.ObjectSchema<{
802
+ declare const fieldWithConditionSchema: (condition: string, settings?: any) => yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
803
+ declare const phoneNonRequiredSchema: (name: string, settings?: any) => yup.ObjectSchema<{
809
804
  phoneNumber: string | null | undefined;
810
805
  } | null, yup.AnyObject, {
811
806
  phoneNumber: undefined;
@@ -965,4 +960,4 @@ declare type UploadMediaToStoreSettings = {
965
960
  };
966
961
  declare const uploadMediaToStore: (e: SyntheticEvent<HTMLInputElement>, filesStore: FilesStore, loader: Loader, settings: UploadMediaToStoreSettings, onAdd?: ((file: FileStore) => void) | undefined) => Promise<void>;
967
962
 
968
- export { apartmentFields, authFlag, csrfTokenKey, defaultRequiredMessage, fieldWithConditionSchema, genderMatches, getBodyForFileRequest, getBodyForImageRequest, getBodyForPostDocument, getBodyForPostFile, getBodyForPostImage, getBodyForVideoRequest, getInspectionFeedbackStatus, getPatchFileParams, getUpdatedFileParams, getUtilitiesPayerParams, getVideoDurationInSeconds, matchesAPICompanyTypes, matchesAPIFillingTypes, matchesAPISubjectRoles, matchesAPIVisibilityVariants, matchesApartmentStatuses, matchesCompanyTypes, matchesFillingTypes, matchesServiceTypes, matchesSubjectRoles, matchesVisibilityVariants, meterUnitLabel, phoneNonRequiredSchema, phoneSchema, phoneWithConditionSchema, positiveNumberSchema, sessionIdKey, setFileFromFileWithVisibility, setNestedNameValue, uploadDocument, uploadDocuments, uploadFile, uploadFiles, uploadFilesWithoutFilter, uploadImage, uploadImages, uploadMediaToStore, uploadNewFile, uploadVideo, uploadVideos };
963
+ export { apartmentFields, authFlag, csrfTokenKey, defaultRequiredMessage, fieldWithConditionSchema, genderMatches, getBodyForFileRequest, getBodyForImageRequest, getBodyForPostDocument, getBodyForPostFile, getBodyForPostImage, getBodyForVideoRequest, getInspectionFeedbackStatus, getPatchFileParams, getPositiveNumberSchema, getUpdatedFileParams, getUtilitiesPayerParams, getVideoDurationInSeconds, matchesAPICompanyTypes, matchesAPIFillingTypes, matchesAPISubjectRoles, matchesAPIVisibilityVariants, matchesApartmentStatuses, matchesCompanyTypes, matchesFillingTypes, matchesServiceTypes, matchesSubjectRoles, matchesVisibilityVariants, meterUnitLabel, phoneNonRequiredSchema, phoneWithConditionSchema, sessionIdKey, setFileFromFileWithVisibility, setNestedNameValue, uploadDocument, uploadDocuments, uploadFile, uploadFiles, uploadFilesWithoutFilter, uploadImage, uploadImages, uploadMediaToStore, uploadNewFile, uploadVideo, uploadVideos };
package/utils/index.js CHANGED
@@ -1 +1 @@
1
- import*as e from"yup";import{isValidWithMaskExp as n,deleteCookie as t,getCookie as r,promisesWithCallback as i,getPhoneParamsFromString as o,Loader as a}from"kui-utils";import u from"await-to-js";import l from"axios";import{setSettings as s}from"kui-complex";import{makeAutoObservable as c}from"mobx";import{DateTime as d}from"luxon";var f="maroomCRMisAuth",m="csrftoken",v="crm-sessionid",p="This field is required",h={water:"м3",gas:"м3",heating:"Гкал",electricity:"кВт"},b={maroom:"maroom",tenant:"renter",landlord:"owner",by_invoice:"by_invoice"},_={maroom:"maroom",renter:"tenant",tenant:"tenant",owner:"landlord",by_invoice:"by_invoice"},g={"Rented out":"Rented",Closed:"Closed",Open:"Free",New:"New","Free soon":"Free soon"},y={administrative_provider:"administrative",service_provider:"service",resource_provider:"resource",tenant:"tenant"},w={administrative:"administrative_provider",service:"service_provider",resource:"resource_provider",tenant:"tenant"},F={finish:"finish",furniture:"furniture",electronics:"appliance",accessories:"accessorie"},S={finish:"finish",furniture:"furniture",appliance:"electronics",accessorie:"accessories"},x={everybody:"everybody",renter:"tenant",owner:"landlord",nobody:"nobody"},E={everybody:"everybody",tenant:"renter",landlord:"owner",nobody:"nobody"},U={M:"male",F:"female"},I={open_ended:"openEnded",period:"period",once:"once",own:"own"},P=function(e,n,t,r,i,o){if(n&&"file"in n&&n.file&&n.file instanceof File?e.append(t,n.file):n&&"url"in n&&o&&e.append(t,n.url),n&&r&&"name"in n){var a=n.name.split(".");a.length>1&&a.pop(),e.append(r,a.join(""))}i&&(null==n?void 0:n.visibility)&&e.append(i,E[n.visibility])},N=e.object({phoneNumber:e.string().matches(n,"Enter the correct phone").required("Enter the phone")}),M=e.number().min(0).required(p),C=function(t){return e.object({phoneNumber:e.string().nullable()}).when(t,{is:function(e){return"true"===e},then:function(t){return t.shape({phoneNumber:e.string().matches(n,"Enter the correct phone").required("Enter the phone")})}}).nullable()},k=function(n){return e.string().nullable().when(n,{is:function(e){return"true"===e},then:function(e){return e.required(p)}}).nullable()},A=function(t){return e.object({phoneNumber:e.string().nullable()}).when(t,{is:function(e){return null==e?void 0:e.phoneNumber},then:function(t){return t.shape({phoneNumber:e.string().matches(n,"Enter the correct phone").required("Enter the phone")})}}).nullable()},j=function(){return j=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},j.apply(this,arguments)};function z(e,n,t,r){return new(t||(t=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function u(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,u)}l((r=r.apply(e,n||[])).next())}))}function O(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=n.call(e,a)}catch(e){o=[6,e],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}var T=new function(){var e=this;this.getSettings=function(){return j({},e.settings)},this.setSettings=function(n){e.settings=j(j({},e.settings),n),s(n),e.observers.forEach((function(n){return n(e.settings)}))},this.subscribeToSettings=function(n){e.observers.push(n)},this.unsubscribeFromSettings=function(n){var t=e.observers.indexOf(n);-1!==t&&e.observers.splice(t,1)},this.settings={mapKey:""},this.observers=[],this.id=100*Math.random()},V=l.create();V.defaults.withCredentials=!0;var R=l.create(),D=function(e){var n,r,i;if(e&&401===(null===(n=e.response)||void 0===n?void 0:n.status)){var o=T.getSettings();t(m),t(v),localStorage.removeItem(f),o.errorHandler&&o.errorHandler(e)}return Promise.reject((null===(r=e.response)||void 0===r?void 0:r.data)?j(j({},e.response.data),{status:null===(i=e.response)||void 0===i?void 0:i.status}):e)},L=function(e){var n=r(m);return n&&(e.headers["X-CSRFToken"]=n),e};V.interceptors.request.use((function(e){var n=T.getSettings().reqHandler;return n?n(L(e)):L(e)})),V.interceptors.response.use((function(e){return z(void 0,void 0,void 0,(function(){return O(this,(function(n){return[2,e.data]}))}))}),(function(e){return D(e)})),R.interceptors.response.use((function(e){return e.data}),(function(e){return D(e)}));var B=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){return r=t||T.getSettings().apiUrl,[2,V.post("".concat(r).concat(e),n)]}))}))},H=function(e,n){return B(n?"":"/upload/image",e,n)},q=function(e,n){return B(n?"":"/upload/document",e,n)},G=function(e,n){return B(n?"":"/upload/video",e,n)},W=function(e){var n=new FormData;return e.file&&n.append("upload",e.file,e.name?e.name:e.file.name),n},$=function(e){var n=new FormData;return e&&e instanceof File?n.append("upload",e):P(n,e,"upload"),n},K=function(e){var n=new FormData;return e&&n.append("upload",e.file),n},X=function(e,n){var t,r,i=e;return n?{temp_file_id:n.id,name:(null===(r=(null==i?void 0:i.name)||(null===(t=null==i?void 0:i.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"file_".concat(n.id),visibility:E[e.visibility],url:n.upload}:null},Y=function(e,n){var t,r;return n?{temp_file_id:n.id,image_name:(null===(r=e.name||(null===(t=e.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"",url:n.upload}:null},J=function(e,n){var t,r;return n?{temp_file_id:n.id,file_name:(null===(r=e.name||(null===(t=e.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"",url:n.upload}:null},Q=function(e){return e&&"name"in e&&"file"in e&&e.file?{name:e.name,visibility:E[e.visibility]}:null},Z=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return t=Q(n),[4,ce(e,n)];case 1:return[2,r.sent()||t]}}))}))},ee=function(e,n){return n?{temp_file_id:n.id,name:e.name,url:n.upload}:null},ne=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=W(n),[4,u(H(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},te=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=W(n),[4,u(G(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},re=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=$(n),[4,u(q(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},ie=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=K(n),[4,u(q(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},oe=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return n?[4,ne(e,n)]:[3,2];case 1:if(t=r.sent())return[2,Y(n,t)];r.label=2;case 2:return[2,null]}}))}))},ae=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return n?[4,te(e,n)]:[3,2];case 1:if(t=r.sent())return[2,J(n,t)];r.label=2;case 2:return[2,null]}}))}))},ue=function(e,n,t,r){return z(void 0,void 0,void 0,(function(){return O(this,(function(o){switch(o.label){case 0:return[4,i(n.map((function(n){return ne(e,n,r)})),t)];case 1:return[2,o.sent().map((function(e,t){return"fulfilled"===e.status?Y(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},le=function(e,n,t,r){return z(void 0,void 0,void 0,(function(){return O(this,(function(o){switch(o.label){case 0:return[4,i(n.map((function(n){return te(e,n,r)})),t)];case 1:return[2,o.sent().map((function(e,t){return"fulfilled"===e.status?J(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},se=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){switch(i.label){case 0:return n?[4,re(e,n,t)]:[3,2];case 1:r=i.sent(),i.label=2;case 2:return[2,n&&n instanceof File?ee(n,r):X(n,r)]}}))}))},ce=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return n&&("file"in n&&n.file&&n.file instanceof File||n&&n instanceof File)?[4,se(e,n,t)]:[3,2];case 1:return[2,r.sent()];case 2:return[2,null]}}))}))},de=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,Promise.allSettled(n.map((function(n){return ce(e,n,t)})))];case 1:return[2,r.sent().map((function(e){return"fulfilled"===e.status?e.value:null}))]}}))}))},fe=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,de(e,n,t)];case 1:return[2,r.sent().filter((function(e){return e}))]}}))}))},me=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,i(n.map((function(n){return ie(e,n,t)})))];case 1:return[2,r.sent().map((function(e,t){return"fulfilled"===e.status?X(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},ve=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){switch(i.label){case 0:return[4,ie(e,n,t)];case 1:return r=i.sent(),[2,X(n,r)]}}))}))},pe=function(e){return{payer:e.payment_made_by?"partial":e.refund_from,mainPayer:e.payment_made_by,refundFrom:e.refund_from,partType:e.value_type,refundValue:Number(e.refund_value).toLocaleString(),utilityType:"utility"===e.utility_type?"invoice":e.utility_type}},he={getApartmentDescriptionInfo:function(e){return j(j(j(j(j(j({},this.getApartmentMainInfo(e)),this.getApartmentSecurityInfo(e)),this.getApartmentDetailInfo(e)),this.getApartmentTelecommunicationInfo(e)),this.getApartmentHouseInfo(e)),this.getMaxMetersParams(e))},getApartmentMainInfo:function(e){return j(j({},e),{apartmentNumber:e.apartment_number,zipCode:e.post_index||"",floorCount:e.floor_count,entrance:e.num_entrance,geolocation:this.getGeolocationParams(e.geolocation),distanceToCenter:e.distance_to_center_kilometers||null,typeOfObject:e.room_type})},getApartmentSecurityInfo:function(e){var n,t,r,i,a,u;return{hasIntercom:null!==(n=e.has_intercom)&&void 0!==n?n:null,hasGate:null!==(t=e.has_gate)&&void 0!==t?t:null,hasBarrier:null!==(r=e.has_barrier)&&void 0!==r?r:null,hasSecurity:null!==(i=e.has_security)&&void 0!==i?i:null,hasConcierge:null!==(a=e.has_concierge)&&void 0!==a?a:null,hasVideoControl:null!==(u=e.has_video_surveillance)&&void 0!==u?u:null,intercomCode:e.intercom_code||"",gateCode:e.gate_code||"",barrierPhone:e.barrier_phone?o(e.barrier_phone):null,conciergePhone:e.concierge_phone?o(e.concierge_phone):null,securityPhone:e.security_phone?o(e.security_phone):null,videoControlPhone:e.video_surveillance_phone?o(e.video_surveillance_phone):null}},getApartmentDetailInfo:function(e){var n;return{area:e.area,livingArea:e.living_area,kitchenArea:e.kitchen_area,roomsNumber:e.rooms_number,bedroomsNumber:e.bedrooms_number,bathroomsNumber:e.bathrooms_number,restroomsNumber:e.restrooms_number,combinedBathroomsNumber:e.combined_bathrooms_number,ceilingHeight:e.ceiling_height,numberOfWindows:e.number_of_windows,renovation:{year:e.renovation_year||null,type:e.renovation_type||null,style:e.renovation_style||null},rooms:(null===(n=e.rooms)||void 0===n?void 0:n.map((function(e){return{id:e.id,area:e.area||null,type:e.room_type||null}})))||[]}},getApartmentTelecommunicationInfo:function(e){return{homePhone:e.home_phone?o(e.home_phone):null,wifi:{name:e.wifi_name,password:e.wifi_password},internetProvider:{link:e.internet_provider.link,login:e.internet_provider.login,password:e.internet_provider.password,name:e.internet_provider.name,contractNumber:e.internet_provider.contract_number,contractHolderName:e.internet_provider.contract_holder_name,contractHolderPhone:e.internet_provider.contract_holder_phone?o(e.internet_provider.contract_holder_phone):null},tvType:e.tv_type}},getApartmentHouseInfo:function(e){return{typeOfHouse:e.type_houses,buildingYear:e.building_year,houseNumber:e.serial_number,wallMaterial:e.wall_type,overlapType:e.overlap_type,parkingType:e.parking_type,parkingNumber:e.parking_number,passengerElevatorsCount:e.passenger_elevators_number?Number(e.passenger_elevators_number):null,serviceElevatorsCount:e.service_elevators_number?Number(e.service_elevators_number):null,gasLeads:e.type_gas,withHotWater:e.hot_water}},getMaxMetersParams:function(e){return{maxMeters:{water:e.max_water_counters,electricity:e.max_electricity_counters,gas:e.max_gas_counters,heating:e.max_heating_counters}}},getApartmentPaymentInfo:function(e){return{payerCode:e.payer_code,communalServicesAccount:e.financial_personal_account,company:e.administrative_company?j(j({},e.administrative_company),{operatingAccount:e.payer_code}):null}},getGeolocationParams:function(e){return e?{lat:Number(e.lat),lng:Number(e.lon)}:null}},be=function(e,n,t){for(var r=e.split("."),i={},o=i,a=t,u=0;u<r.length-1;u+=1){var l=r[u];o[l]=a[l]||{},o=o[l],a=a[l]}return o[r[r.length-1]]=n,i},_e=function(e){return e.signed?e.agree?"signed":"rejected":"notSigned"},ge=function(e){return new Promise((function(n,t){try{var r=document.createElement("video"),i=URL.createObjectURL(e),o=function(){r.onloadedmetadata=null,r.onerror=null,URL.revokeObjectURL(i)};r.preload="metadata",r.onloadedmetadata=function(){var e=Number(r.duration)||0;o(),n(e)},r.onerror=function(){o(),t(new Error("Failed to load video metadata"))},r.src=i}catch(e){t(e)}}))},ye=function(){function e(e,n,t){var r,i,o,u,l,s,f,m=this;this.uploadFile=function(e){return z(m,void 0,void 0,(function(){var n,t,r;return O(this,(function(i){switch(i.label){case 0:return this.file?(this.updateUploadStatus("loading"),this.url&&URL.revokeObjectURL(this.url),n=void 0,this.isVideo?[4,ae(this.loader,this)]:[3,2]):[3,7];case 1:return n=i.sent(),[3,6];case 2:return"image"!==e?[3,4]:[4,oe(this.loader,this)];case 3:return n=i.sent(),[3,6];case 4:return[4,ce(this.loader,this)];case 5:n=i.sent(),i.label=6;case 6:n?(this.updateUploadedData(n),this.updateUploadStatus("success")):400===this.loader.status&&(null===(r=null===(t=this.loader.error)||void 0===t?void 0:t.upload)||void 0===r?void 0:r[0])?this.updateUploadStatus("error"):this.updateUploadStatus("failure"),i.label=7;case 7:return[2]}}))}))},this.updateUploadStatus=function(e){m.uploadStatus=e},this.updateUploadedData=function(e){m.uploadedData=e,m.withFileCleanUp&&(m.file=void 0)},this.editFile=function(e){var n;m.id&&(null===(n=m.filesStore)||void 0===n||n.editFile(m.id,e,(function(){m.updateStore(e)})))},this.deleteFile=function(){var e;m.id&&(null===(e=m.filesStore)||void 0===e||e.deleteFile(m.id))},this.updateName=function(e){m.name=e},this.updateStore=function(e){},this.setIndex=function(e){m.index=e},this.id=null!==(r=e.id)&&void 0!==r?r:null,this.name=null!==(i=e.name)&&void 0!==i?i:"",this.index="number"==typeof e.index?e.index:void 0,this.url=null!==(o=e.url)&&void 0!==o?o:"",this.date=e.date?d.fromISO(e.date):null,this.size=null!==(u=e.size)&&void 0!==u?u:null,this.filesStore=n||null,this.createdBy=null!==(l=e.createdBy)&&void 0!==l?l:"",this.file=e.file||void 0,this.visibility=e.visibility&&x[e.visibility],this.extension=(null===(f=null===(s=this.name.split("."))||void 0===s?void 0:s.pop())||void 0===f?void 0:f.toUpperCase())||"",this.uploadStatus=e.uploadStatus||"default",this.uploadedData=e.uploadedData||null,this.loader=new a,this.withFileCleanUp=!!t,this.smallImageUrl=e.smallImageUrl,this.mediumImageUrl=e.mediumImageUrl,this.largeImageUrl=e.largeImageUrl,this.isVideo=e.isVideo,c(this,{filesStore:!1})}var n;return Object.defineProperty(e.prototype,"title",{get:function(){return this.name.replace(/\.[^/.]+$/,"")},enumerable:!1,configurable:!0}),n=e,e.createPreviewUrl=function(e){return z(void 0,void 0,void 0,(function(){var t,r,i,o,a;return O(n,(function(n){switch(n.label){case 0:return[4,createImageBitmap(e)];case 1:return t=n.sent(),600,r=Math.min(1,600/t.width),i=Math.floor(t.width*r),o=Math.floor(t.height*r),(a=document.createElement("canvas")).width=i,a.height=o,a.getContext("2d").drawImage(t,0,0,i,o),[2,new Promise((function(e,n){a.toBlob((function(t){if(t){var r=URL.createObjectURL(t);e(r)}else n(new Error("Не удалось получить Blob из canvas"))}),"image/jpeg",.4)}))]}}))}))},e.initFromFileWithPreview=function(t,r,i){return z(void 0,void 0,void 0,(function(){var o,a,u;return O(n,(function(n){switch(n.label){case 0:return[4,t.arrayBuffer()];case 1:return o=n.sent(),a=new File([o],t.name,{type:t.type}),[4,e.createPreviewUrl(t)];case 2:return u=n.sent(),[2,new e({name:a.name,size:Math.round(a.size/1048576*100)/100,url:u,index:r,file:a,isVideo:t.type.includes("video")},null,i)]}}))}))},e.initFromFileModel=function(n){return new e({id:n.id,name:n.name,size:Math.round(n.size/1048576*100)/100,url:n.url})},e.initFromDocumentModel=function(n){return new e({id:n.pk,name:n.name,url:n.attachment,size:Math.round(n.size/1048576*100)/100,visibility:n.visibility,createdBy:n.uploaded_by||null,date:n.created})},e.initFromImageModel=function(n,t,r){return new e({id:n.id,name:n.image_name||t||"",url:n.image_url,smallImageUrl:n.image_small_url,mediumImageUrl:n.image_medium_url,largeImageUrl:n.image_large_url,size:n.size?Math.round(n.size/1048576*100)/100:0,isVideo:r})},e.initFromFile=function(n,t,r){return new e({name:n.name,size:Math.round(n.size/1048576*100)/100,url:URL.createObjectURL(n),index:t,file:n,isVideo:n.type.includes("video")},null,r)},e.initFromFileStore=function(n){var t;return new e(j(j({},n),{date:(null===(t=n.date)||void 0===t?void 0:t.toISODate())||null,visibility:n.visibility?E[n.visibility]:"nobody"}))},e}(),we=function(e,n,t,r,i){return z(void 0,void 0,void 0,(function(){var o,a,u,l,s,c,d,f,m,v,p,h,b;return O(this,(function(_){switch(_.label){case 0:return o=r.uploadedPhotosCount,a=r.uploadedVideosCount,u=r.limitSize,l=r.limitVideosSize,s=r.withPreview,c=r.messages,d=r.withoutFilesStore,f=e.target,m=f.files?Array.from(f.files):[],v=m.filter((function(e){return!e.type.includes("video")})).length,p=m.filter((function(e){return e.type.includes("video")})).length,h=(o||0)+v,b=(a||0)+p,u&&h>u?(t.setError((null==c?void 0:c.limitPhotosExceed)||"The limit on the number of indoor images has been exceeded"),[2]):l&&b>l?(t.setError((null==c?void 0:c.limitVideosExceed)||"The limit on the number of indoor videos has been exceeded"),[2]):[4,Promise.all(m.map((function(e,r){return z(void 0,void 0,void 0,(function(){var o,a,u,l,f,m;return O(this,(function(v){switch(v.label){case 0:if(!(o=null===(m=e.type)||void 0===m?void 0:m.includes("video")))return[3,4];if(31457280,e.size>31457280)return t.setError('"'.concat(e.name,'" ').concat((null==c?void 0:c.limitVideoExceed)?null==c?void 0:c.limitVideoExceed(30):"exceeds the ".concat(30,"MB limit"))),[2];v.label=1;case 1:return v.trys.push([1,3,,4]),[4,ge(e)];case 2:return v.sent()>15?(t.setError('"'.concat(e.name,'" ').concat((null==c?void 0:c.limitVideoTimeExceed)?null==c?void 0:c.limitVideoTimeExceed(15):"exceeds ".concat(15," seconds duration limit"))),[2]):[3,4];case 3:return v.sent(),t.setError("".concat((null==c?void 0:c.readFailing)||"Unable to read metadata for",' "').concat(e.name,'"')),[2];case 4:if(!s||o)return[3,9];v.label=5;case 5:return v.trys.push([5,7,,8]),[4,ye.initFromFileWithPreview(e,n.files.length+r,!0)];case 6:return a=v.sent(),d||n.addFile(a),i&&i(a),[3,8];case 7:return u=v.sent(),l=T.getSettings().Sentry,t.setError("".concat((null==c?void 0:c.readFailing)||"Unable to read metadata for"," ").concat(e.name)),l.captureException(u),[3,8];case 8:return[2];case 9:return!n.files.some((function(n){return n.name===e.name}))?(f=ye.initFromFile(e,n.files.length+r),d||n.addFile(f),i&&i(f),[2]):[2]}}))}))})))];case 1:return _.sent(),[2]}}))}))};export{he as apartmentFields,f as authFlag,m as csrfTokenKey,p as defaultRequiredMessage,k as fieldWithConditionSchema,U as genderMatches,X as getBodyForFileRequest,Y as getBodyForImageRequest,K as getBodyForPostDocument,$ as getBodyForPostFile,W as getBodyForPostImage,J as getBodyForVideoRequest,_e as getInspectionFeedbackStatus,Q as getPatchFileParams,Z as getUpdatedFileParams,pe as getUtilitiesPayerParams,ge as getVideoDurationInSeconds,y as matchesAPICompanyTypes,S as matchesAPIFillingTypes,b as matchesAPISubjectRoles,E as matchesAPIVisibilityVariants,g as matchesApartmentStatuses,w as matchesCompanyTypes,F as matchesFillingTypes,I as matchesServiceTypes,_ as matchesSubjectRoles,x as matchesVisibilityVariants,h as meterUnitLabel,A as phoneNonRequiredSchema,N as phoneSchema,C as phoneWithConditionSchema,M as positiveNumberSchema,v as sessionIdKey,P as setFileFromFileWithVisibility,be as setNestedNameValue,ve as uploadDocument,me as uploadDocuments,se as uploadFile,fe as uploadFiles,de as uploadFilesWithoutFilter,oe as uploadImage,ue as uploadImages,we as uploadMediaToStore,ce as uploadNewFile,ae as uploadVideo,le as uploadVideos};
1
+ import*as e from"yup";import{isValidWithMaskExp as n,deleteCookie as t,getCookie as r,promisesWithCallback as i,getPhoneParamsFromString as o,Loader as a}from"kui-utils";import u from"await-to-js";import l from"axios";import{setSettings as s}from"kui-complex";import{makeAutoObservable as c}from"mobx";import{DateTime as d}from"luxon";var f="maroomCRMisAuth",m="csrftoken",v="crm-sessionid",p="This field is required",h={water:"м3",gas:"м3",heating:"Гкал",electricity:"кВт"},b={maroom:"maroom",tenant:"renter",landlord:"owner",by_invoice:"by_invoice"},g={maroom:"maroom",renter:"tenant",tenant:"tenant",owner:"landlord",by_invoice:"by_invoice"},_={"Rented out":"Rented",Closed:"Closed",Open:"Free",New:"New","Free soon":"Free soon"},y={administrative_provider:"administrative",service_provider:"service",resource_provider:"resource",tenant:"tenant"},w={administrative:"administrative_provider",service:"service_provider",resource:"resource_provider",tenant:"tenant"},F={finish:"finish",furniture:"furniture",electronics:"appliance",accessories:"accessorie"},S={finish:"finish",furniture:"furniture",appliance:"electronics",accessorie:"accessories"},x={everybody:"everybody",renter:"tenant",owner:"landlord",nobody:"nobody"},U={everybody:"everybody",tenant:"renter",landlord:"owner",nobody:"nobody"},E={M:"male",F:"female"},P={open_ended:"openEnded",period:"period",once:"once",own:"own"},I=function(e,n,t,r,i,o){if(n&&"file"in n&&n.file&&n.file instanceof File?e.append(t,n.file):n&&"url"in n&&o&&e.append(t,n.url),n&&r&&"name"in n){var a=n.name.split(".");a.length>1&&a.pop(),e.append(r,a.join(""))}i&&(null==n?void 0:n.visibility)&&e.append(i,U[n.visibility])},M=function(n){return e.number().min(0).required((null==n?void 0:n.requiredMessage)||p)},N=function(t,r){return e.object({phoneNumber:e.string().nullable()}).when(t,{is:function(e){return"true"===e},then:function(t){return t.shape({phoneNumber:e.string().matches(n,null==r?void 0:r.correctPhoneMessage).required(null==r?void 0:r.requiredMessage)})}}).nullable()},C=function(n,t){return e.string().nullable().when(n,{is:function(e){return"true"===e},then:function(e){return e.required((null==t?void 0:t.requiredMessage)||p)}}).nullable()},k=function(t,r){return e.object({phoneNumber:e.string().nullable()}).when(t,{is:function(e){return null==e?void 0:e.phoneNumber},then:function(t){return t.shape({phoneNumber:e.string().matches(n,null==r?void 0:r.correctPhoneMessage).required((null==r?void 0:r.requiredMessage)||p)})}}).nullable()},A=function(){return A=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},A.apply(this,arguments)};function z(e,n,t,r){return new(t||(t=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function u(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,u)}l((r=r.apply(e,n||[])).next())}))}function O(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=n.call(e,a)}catch(e){o=[6,e],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}var j=new function(){var e=this;this.getSettings=function(){return A({},e.settings)},this.setSettings=function(n){e.settings=A(A({},e.settings),n),s(n),e.observers.forEach((function(n){return n(e.settings)}))},this.subscribeToSettings=function(n){e.observers.push(n)},this.unsubscribeFromSettings=function(n){var t=e.observers.indexOf(n);-1!==t&&e.observers.splice(t,1)},this.settings={mapKey:""},this.observers=[],this.id=100*Math.random()},T=l.create();T.defaults.withCredentials=!0;var V=l.create(),R=function(e){var n,r,i;if(e&&401===(null===(n=e.response)||void 0===n?void 0:n.status)){var o=j.getSettings();t(m),t(v),localStorage.removeItem(f),o.errorHandler&&o.errorHandler(e)}return Promise.reject((null===(r=e.response)||void 0===r?void 0:r.data)?A(A({},e.response.data),{status:null===(i=e.response)||void 0===i?void 0:i.status}):e)},D=function(e){var n=r(m);return n&&(e.headers["X-CSRFToken"]=n),e};T.interceptors.request.use((function(e){var n=j.getSettings().reqHandler;return n?n(D(e)):D(e)})),T.interceptors.response.use((function(e){return z(void 0,void 0,void 0,(function(){return O(this,(function(n){return[2,e.data]}))}))}),(function(e){return R(e)})),V.interceptors.response.use((function(e){return e.data}),(function(e){return R(e)}));var L=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){return r=t||j.getSettings().apiUrl,[2,T.post("".concat(r).concat(e),n)]}))}))},q=function(e,n){return L(n?"":"/upload/image",e,n)},B=function(e,n){return L(n?"":"/upload/document",e,n)},H=function(e,n){return L(n?"":"/upload/video",e,n)},G=function(e){var n=new FormData;return e.file&&n.append("upload",e.file,e.name?e.name:e.file.name),n},W=function(e){var n=new FormData;return e&&e instanceof File?n.append("upload",e):I(n,e,"upload"),n},$=function(e){var n=new FormData;return e&&n.append("upload",e.file),n},K=function(e,n){var t,r,i=e;return n?{temp_file_id:n.id,name:(null===(r=(null==i?void 0:i.name)||(null===(t=null==i?void 0:i.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"file_".concat(n.id),visibility:U[e.visibility],url:n.upload}:null},X=function(e,n){var t,r;return n?{temp_file_id:n.id,image_name:(null===(r=e.name||(null===(t=e.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"",url:n.upload}:null},Y=function(e,n){var t,r;return n?{temp_file_id:n.id,file_name:(null===(r=e.name||(null===(t=e.file)||void 0===t?void 0:t.name))||void 0===r?void 0:r.replace(/\.[^/.]+$/,""))||"",url:n.upload}:null},J=function(e){return e&&"name"in e&&"file"in e&&e.file?{name:e.name,visibility:U[e.visibility]}:null},Q=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return t=J(n),[4,se(e,n)];case 1:return[2,r.sent()||t]}}))}))},Z=function(e,n){return n?{temp_file_id:n.id,name:e.name,url:n.upload}:null},ee=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=G(n),[4,u(q(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},ne=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=G(n),[4,u(H(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},te=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=W(n),[4,u(B(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},re=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r,i,o,a;return O(this,(function(l){switch(l.label){case 0:return e.cleanError(),r=$(n),[4,u(B(r,t))];case 1:return i=l.sent(),o=i[0],a=i[1],o&&e.setError("",o),[2,a]}}))}))},ie=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return n?[4,ee(e,n)]:[3,2];case 1:if(t=r.sent())return[2,X(n,t)];r.label=2;case 2:return[2,null]}}))}))},oe=function(e,n){return z(void 0,void 0,void 0,(function(){var t;return O(this,(function(r){switch(r.label){case 0:return n?[4,ne(e,n)]:[3,2];case 1:if(t=r.sent())return[2,Y(n,t)];r.label=2;case 2:return[2,null]}}))}))},ae=function(e,n,t,r){return z(void 0,void 0,void 0,(function(){return O(this,(function(o){switch(o.label){case 0:return[4,i(n.map((function(n){return ee(e,n,r)})),t)];case 1:return[2,o.sent().map((function(e,t){return"fulfilled"===e.status?X(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},ue=function(e,n,t,r){return z(void 0,void 0,void 0,(function(){return O(this,(function(o){switch(o.label){case 0:return[4,i(n.map((function(n){return ne(e,n,r)})),t)];case 1:return[2,o.sent().map((function(e,t){return"fulfilled"===e.status?Y(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},le=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){switch(i.label){case 0:return n?[4,te(e,n,t)]:[3,2];case 1:r=i.sent(),i.label=2;case 2:return[2,n&&n instanceof File?Z(n,r):K(n,r)]}}))}))},se=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return n&&("file"in n&&n.file&&n.file instanceof File||n&&n instanceof File)?[4,le(e,n,t)]:[3,2];case 1:return[2,r.sent()];case 2:return[2,null]}}))}))},ce=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,Promise.allSettled(n.map((function(n){return se(e,n,t)})))];case 1:return[2,r.sent().map((function(e){return"fulfilled"===e.status?e.value:null}))]}}))}))},de=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,ce(e,n,t)];case 1:return[2,r.sent().filter((function(e){return e}))]}}))}))},fe=function(e,n,t){return z(void 0,void 0,void 0,(function(){return O(this,(function(r){switch(r.label){case 0:return[4,i(n.map((function(n){return re(e,n,t)})))];case 1:return[2,r.sent().map((function(e,t){return"fulfilled"===e.status?K(n[t],e.value):null})).filter((function(e){return e}))]}}))}))},me=function(e,n,t){return z(void 0,void 0,void 0,(function(){var r;return O(this,(function(i){switch(i.label){case 0:return[4,re(e,n,t)];case 1:return r=i.sent(),[2,K(n,r)]}}))}))},ve=function(e){return{payer:e.payment_made_by?"partial":e.refund_from,mainPayer:e.payment_made_by,refundFrom:e.refund_from,partType:e.value_type,refundValue:Number(e.refund_value).toLocaleString(),utilityType:"utility"===e.utility_type?"invoice":e.utility_type}},pe={getApartmentDescriptionInfo:function(e){return A(A(A(A(A(A({},this.getApartmentMainInfo(e)),this.getApartmentSecurityInfo(e)),this.getApartmentDetailInfo(e)),this.getApartmentTelecommunicationInfo(e)),this.getApartmentHouseInfo(e)),this.getMaxMetersParams(e))},getApartmentMainInfo:function(e){return A(A({},e),{apartmentNumber:e.apartment_number,zipCode:e.post_index||"",floorCount:e.floor_count,entrance:e.num_entrance,geolocation:this.getGeolocationParams(e.geolocation),distanceToCenter:e.distance_to_center_kilometers||null,typeOfObject:e.room_type})},getApartmentSecurityInfo:function(e){var n,t,r,i,a,u;return{hasIntercom:null!==(n=e.has_intercom)&&void 0!==n?n:null,hasGate:null!==(t=e.has_gate)&&void 0!==t?t:null,hasBarrier:null!==(r=e.has_barrier)&&void 0!==r?r:null,hasSecurity:null!==(i=e.has_security)&&void 0!==i?i:null,hasConcierge:null!==(a=e.has_concierge)&&void 0!==a?a:null,hasVideoControl:null!==(u=e.has_video_surveillance)&&void 0!==u?u:null,intercomCode:e.intercom_code||"",gateCode:e.gate_code||"",barrierPhone:e.barrier_phone?o(e.barrier_phone):null,conciergePhone:e.concierge_phone?o(e.concierge_phone):null,securityPhone:e.security_phone?o(e.security_phone):null,videoControlPhone:e.video_surveillance_phone?o(e.video_surveillance_phone):null}},getApartmentDetailInfo:function(e){var n;return{area:e.area,livingArea:e.living_area,kitchenArea:e.kitchen_area,roomsNumber:e.rooms_number,bedroomsNumber:e.bedrooms_number,bathroomsNumber:e.bathrooms_number,restroomsNumber:e.restrooms_number,combinedBathroomsNumber:e.combined_bathrooms_number,ceilingHeight:e.ceiling_height,numberOfWindows:e.number_of_windows,renovation:{year:e.renovation_year||null,type:e.renovation_type||null,style:e.renovation_style||null},rooms:(null===(n=e.rooms)||void 0===n?void 0:n.map((function(e){return{id:e.id,area:e.area||null,type:e.room_type||null}})))||[]}},getApartmentTelecommunicationInfo:function(e){return{homePhone:e.home_phone?o(e.home_phone):null,wifi:{name:e.wifi_name,password:e.wifi_password},internetProvider:{link:e.internet_provider.link,login:e.internet_provider.login,password:e.internet_provider.password,name:e.internet_provider.name,contractNumber:e.internet_provider.contract_number,contractHolderName:e.internet_provider.contract_holder_name,contractHolderPhone:e.internet_provider.contract_holder_phone?o(e.internet_provider.contract_holder_phone):null},tvType:e.tv_type}},getApartmentHouseInfo:function(e){return{typeOfHouse:e.type_houses,buildingYear:e.building_year,houseNumber:e.serial_number,wallMaterial:e.wall_type,overlapType:e.overlap_type,parkingType:e.parking_type,parkingNumber:e.parking_number,passengerElevatorsCount:e.passenger_elevators_number?Number(e.passenger_elevators_number):null,serviceElevatorsCount:e.service_elevators_number?Number(e.service_elevators_number):null,gasLeads:e.type_gas,withHotWater:e.hot_water}},getMaxMetersParams:function(e){return{maxMeters:{water:e.max_water_counters,electricity:e.max_electricity_counters,gas:e.max_gas_counters,heating:e.max_heating_counters}}},getApartmentPaymentInfo:function(e){return{payerCode:e.payer_code,communalServicesAccount:e.financial_personal_account,company:e.administrative_company?A(A({},e.administrative_company),{operatingAccount:e.payer_code}):null}},getGeolocationParams:function(e){return e?{lat:Number(e.lat),lng:Number(e.lon)}:null}},he=function(e,n,t){for(var r=e.split("."),i={},o=i,a=t,u=0;u<r.length-1;u+=1){var l=r[u];o[l]=a[l]||{},o=o[l],a=a[l]}return o[r[r.length-1]]=n,i},be=function(e){return e.signed?e.agree?"signed":"rejected":"notSigned"},ge=function(e){return new Promise((function(n,t){try{var r=document.createElement("video"),i=URL.createObjectURL(e),o=function(){r.onloadedmetadata=null,r.onerror=null,URL.revokeObjectURL(i)};r.preload="metadata",r.onloadedmetadata=function(){var e=Number(r.duration)||0;o(),n(e)},r.onerror=function(){o(),t(new Error("Failed to load video metadata"))},r.src=i}catch(e){t(e)}}))},_e=function(){function e(e,n,t){var r,i,o,u,l,s,f,m=this;this.uploadFile=function(e){return z(m,void 0,void 0,(function(){var n,t,r;return O(this,(function(i){switch(i.label){case 0:return this.file?(this.updateUploadStatus("loading"),this.url&&URL.revokeObjectURL(this.url),n=void 0,this.isVideo?[4,oe(this.loader,this)]:[3,2]):[3,7];case 1:return n=i.sent(),[3,6];case 2:return"image"!==e?[3,4]:[4,ie(this.loader,this)];case 3:return n=i.sent(),[3,6];case 4:return[4,se(this.loader,this)];case 5:n=i.sent(),i.label=6;case 6:n?(this.updateUploadedData(n),this.updateUploadStatus("success")):400===this.loader.status&&(null===(r=null===(t=this.loader.error)||void 0===t?void 0:t.upload)||void 0===r?void 0:r[0])?this.updateUploadStatus("error"):this.updateUploadStatus("failure"),i.label=7;case 7:return[2]}}))}))},this.updateUploadStatus=function(e){m.uploadStatus=e},this.updateUploadedData=function(e){m.uploadedData=e,m.withFileCleanUp&&(m.file=void 0)},this.editFile=function(e){var n;m.id&&(null===(n=m.filesStore)||void 0===n||n.editFile(m.id,e,(function(){m.updateStore(e)})))},this.deleteFile=function(){var e;m.id&&(null===(e=m.filesStore)||void 0===e||e.deleteFile(m.id))},this.updateName=function(e){m.name=e},this.updateStore=function(e){},this.setIndex=function(e){m.index=e},this.id=null!==(r=e.id)&&void 0!==r?r:null,this.name=null!==(i=e.name)&&void 0!==i?i:"",this.index="number"==typeof e.index?e.index:void 0,this.url=null!==(o=e.url)&&void 0!==o?o:"",this.date=e.date?d.fromISO(e.date):null,this.size=null!==(u=e.size)&&void 0!==u?u:null,this.filesStore=n||null,this.createdBy=null!==(l=e.createdBy)&&void 0!==l?l:"",this.file=e.file||void 0,this.visibility=e.visibility&&x[e.visibility],this.extension=(null===(f=null===(s=this.name.split("."))||void 0===s?void 0:s.pop())||void 0===f?void 0:f.toUpperCase())||"",this.uploadStatus=e.uploadStatus||"default",this.uploadedData=e.uploadedData||null,this.loader=new a,this.withFileCleanUp=!!t,this.smallImageUrl=e.smallImageUrl,this.mediumImageUrl=e.mediumImageUrl,this.largeImageUrl=e.largeImageUrl,this.isVideo=e.isVideo,c(this,{filesStore:!1})}var n;return Object.defineProperty(e.prototype,"title",{get:function(){return this.name.replace(/\.[^/.]+$/,"")},enumerable:!1,configurable:!0}),n=e,e.createPreviewUrl=function(e){return z(void 0,void 0,void 0,(function(){var t,r,i,o,a;return O(n,(function(n){switch(n.label){case 0:return[4,createImageBitmap(e)];case 1:return t=n.sent(),600,r=Math.min(1,600/t.width),i=Math.floor(t.width*r),o=Math.floor(t.height*r),(a=document.createElement("canvas")).width=i,a.height=o,a.getContext("2d").drawImage(t,0,0,i,o),[2,new Promise((function(e,n){a.toBlob((function(t){if(t){var r=URL.createObjectURL(t);e(r)}else n(new Error("Не удалось получить Blob из canvas"))}),"image/jpeg",.4)}))]}}))}))},e.initFromFileWithPreview=function(t,r,i){return z(void 0,void 0,void 0,(function(){var o,a,u;return O(n,(function(n){switch(n.label){case 0:return[4,t.arrayBuffer()];case 1:return o=n.sent(),a=new File([o],t.name,{type:t.type}),[4,e.createPreviewUrl(t)];case 2:return u=n.sent(),[2,new e({name:a.name,size:Math.round(a.size/1048576*100)/100,url:u,index:r,file:a,isVideo:t.type.includes("video")},null,i)]}}))}))},e.initFromFileModel=function(n){return new e({id:n.id,name:n.name,size:Math.round(n.size/1048576*100)/100,url:n.url})},e.initFromDocumentModel=function(n){return new e({id:n.pk,name:n.name,url:n.attachment,size:Math.round(n.size/1048576*100)/100,visibility:n.visibility,createdBy:n.uploaded_by||null,date:n.created})},e.initFromImageModel=function(n,t,r){return new e({id:n.id,name:n.image_name||t||"",url:n.image_url,smallImageUrl:n.image_small_url,mediumImageUrl:n.image_medium_url,largeImageUrl:n.image_large_url,size:n.size?Math.round(n.size/1048576*100)/100:0,isVideo:r})},e.initFromFile=function(n,t,r){return new e({name:n.name,size:Math.round(n.size/1048576*100)/100,url:URL.createObjectURL(n),index:t,file:n,isVideo:n.type.includes("video")},null,r)},e.initFromFileStore=function(n){var t;return new e(A(A({},n),{date:(null===(t=n.date)||void 0===t?void 0:t.toISODate())||null,visibility:n.visibility?U[n.visibility]:"nobody"}))},e}(),ye=function(e,n,t,r,i){return z(void 0,void 0,void 0,(function(){var o,a,u,l,s,c,d,f,m,v,p,h,b;return O(this,(function(g){switch(g.label){case 0:return o=r.uploadedPhotosCount,a=r.uploadedVideosCount,u=r.limitSize,l=r.limitVideosSize,s=r.withPreview,c=r.messages,d=r.withoutFilesStore,f=e.target,m=f.files?Array.from(f.files):[],v=m.filter((function(e){return!e.type.includes("video")})).length,p=m.filter((function(e){return e.type.includes("video")})).length,h=(o||0)+v,b=(a||0)+p,u&&h>u?(t.setError((null==c?void 0:c.limitPhotosExceed)||"The limit on the number of indoor images has been exceeded"),[2]):l&&b>l?(t.setError((null==c?void 0:c.limitVideosExceed)||"The limit on the number of indoor videos has been exceeded"),[2]):[4,Promise.all(m.map((function(e,r){return z(void 0,void 0,void 0,(function(){var o,a,u,l,f,m;return O(this,(function(v){switch(v.label){case 0:if(!(o=null===(m=e.type)||void 0===m?void 0:m.includes("video")))return[3,4];if(31457280,e.size>31457280)return t.setError('"'.concat(e.name,'" ').concat((null==c?void 0:c.limitVideoExceed)?null==c?void 0:c.limitVideoExceed(30):"exceeds the ".concat(30,"MB limit"))),[2];v.label=1;case 1:return v.trys.push([1,3,,4]),[4,ge(e)];case 2:return v.sent()>15?(t.setError('"'.concat(e.name,'" ').concat((null==c?void 0:c.limitVideoTimeExceed)?null==c?void 0:c.limitVideoTimeExceed(15):"exceeds ".concat(15," seconds duration limit"))),[2]):[3,4];case 3:return v.sent(),t.setError("".concat((null==c?void 0:c.readFailing)||"Unable to read metadata for",' "').concat(e.name,'"')),[2];case 4:if(!s||o)return[3,9];v.label=5;case 5:return v.trys.push([5,7,,8]),[4,_e.initFromFileWithPreview(e,n.files.length+r,!0)];case 6:return a=v.sent(),d||n.addFile(a),i&&i(a),[3,8];case 7:return u=v.sent(),l=j.getSettings().Sentry,t.setError("".concat((null==c?void 0:c.readFailing)||"Unable to read metadata for"," ").concat(e.name)),l.captureException(u),[3,8];case 8:return[2];case 9:return!n.files.some((function(n){return n.name===e.name}))?(f=_e.initFromFile(e,n.files.length+r),d||n.addFile(f),i&&i(f),[2]):[2]}}))}))})))];case 1:return g.sent(),[2]}}))}))};export{pe as apartmentFields,f as authFlag,m as csrfTokenKey,p as defaultRequiredMessage,C as fieldWithConditionSchema,E as genderMatches,K as getBodyForFileRequest,X as getBodyForImageRequest,$ as getBodyForPostDocument,W as getBodyForPostFile,G as getBodyForPostImage,Y as getBodyForVideoRequest,be as getInspectionFeedbackStatus,J as getPatchFileParams,M as getPositiveNumberSchema,Q as getUpdatedFileParams,ve as getUtilitiesPayerParams,ge as getVideoDurationInSeconds,y as matchesAPICompanyTypes,S as matchesAPIFillingTypes,b as matchesAPISubjectRoles,U as matchesAPIVisibilityVariants,_ as matchesApartmentStatuses,w as matchesCompanyTypes,F as matchesFillingTypes,P as matchesServiceTypes,g as matchesSubjectRoles,x as matchesVisibilityVariants,h as meterUnitLabel,k as phoneNonRequiredSchema,N as phoneWithConditionSchema,v as sessionIdKey,I as setFileFromFileWithVisibility,he as setNestedNameValue,me as uploadDocument,fe as uploadDocuments,le as uploadFile,de as uploadFiles,ce as uploadFilesWithoutFilter,ie as uploadImage,ae as uploadImages,ye as uploadMediaToStore,se as uploadNewFile,oe as uploadVideo,ue as uploadVideos};