import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as o,useEffect as i}from"react";import c from"prop-types";import{makeStyles as a,Dialog as s,DialogTitle as p,DialogContent as l,Typography as u,DialogActions as f,Button as m}from"@material-ui/core";import{get as d}from"lodash";import h from"classnames";import b from"./UsersChipSelector.js";import{getUsers as y}from"../../../clients/jsonApi/index.js";import{jsxs as g,jsx as v}from"react/jsx-runtime";function O(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function w(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}var j=a({dialog:{width:"600px",height:"600px"},actions:{padding:"8px 40px",boxShadow:"0px -4px 10px rgb(0 0 0 / 25%)"},mobileActions:{paddingRight:"100px"}});function x(c){var a=c.title,O=c.open,x=c.onSave,S=c.onCancel,P=c.currentUser,C=j(),R=!1,U=o([]),k=t(U,2),A=k[0],q=k[1],D=o(new Set),T=t(D,2),E=T[0],N=T[1];i((function(){function e(){return(e=r(n.mark((function e(){var r,t,o;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r={companyId:d(P,["company","id"])},e.next=4,y(r);case 4:t=e.sent,o=(t||[]).filter((function(e){return d(e,"id")!==d(P,"id")})).map((function(e){return w(w({},e),{},{id:d(e,"id"),displayName:"".concat(d(e,"first_name")," ").concat(d(e,"last_name"))})})),q(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(0),console.error(e.t0);case 12:case"end":return e.stop()}}),e,null,[[0,9]])})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[]);var _=function(){N(new Set),S()};return g(s,{open:O,onClose:_,fullScreen:R,classes:{paper:h(e({},C.dialog,!0))},children:[v(p,{children:a||"Share Templates"}),g(l,{children:[v(u,{variant:"subtitle1",gutterBottom:!0,children:"Share with users"}),v(b,{users:A,selectedUsers:E,onAddUser:function(e){N((function(r){return new Set(r.add(e))}))},onRemoveUser:function(e){N((function(r){return r.delete(e),new Set(r)}))}})]}),g(f,{className:h(C.actions,e({},C.mobileActions,R)),children:[v(m,{color:"primary",onClick:_,children:"Cancel"}),v(m,{variant:"contained",color:"primary",onClick:function(){x(A.filter((function(e){return E.has(d(e,"id"))}))),N(new Set)},children:"Save"})]})]})}x.propTypes={title:c.string,open:c.bool.isRequired,onSave:c.func.isRequired,onCancel:c.func.isRequired,currentUser:c.shape({}).isRequired},x.defaultProps={title:null};export{x as default};
