"use strict"; const { message, onMessage } = props; return <iframe style={{ display: "none" }} srcDoc={'<html><body><script>"use strict";(()=>{function d(o){return e=>e.split(`\n`).map(t=>t.length?" ".repeat(o)+t:"").join(`\n`)}var m=class{constructor(e){this.config=e}generate(e){let t=[{path:["near_sdk_contract_tools","FungibleToken"]},{path:["near_sdk_contract_tools","standard","nep141","*"]}],a;this.config.preMint&&this.config.preMint.trim().length>0&&+this.config.preMint>0&&(t.push({path:["near_sdk","env"]}),a=`contract.deposit_unchecked(&env::predecessor_account_id(), ${this.config.preMint}u128);`);let n="decimals"in this.config?+this.config.decimals:24,c=Math.max(0,Math.min(24,n)),i=[`name = "${this.config.name}"`,`symbol = "${this.config.symbol}"`,`decimals = ${c}`],s=[],u=e.beforeChangeFunction.length?`\n`+e.beforeChangeFunction.map(d(1)).join(`\n`):"",f=e.afterChangeFunction.length?`\n`+e.afterChangeFunction.map(d(1)).join(`\n`):"",p=e.beforeAuthorizedFunction.length?`\n`+d(1)(e.beforeAuthorizedFunction.join(`\n`)):"";if(this.config.mintable){t.push({path:["near_sdk","AccountId"]}),t.push({path:["near_sdk","json_types","U128"]});let h=`\npub fn mint(&mut self, account_id: AccountId, amount: U128) {${u}${p}\n Nep141Controller::mint(self, account_id, amount.into(), None);${f}\n}\n`.trim();s.push(h)}if(this.config.burnable){t.push({path:["near_sdk","env"]}),t.push({path:["near_sdk","json_types","U128"]});let h=`\npub fn burn(&mut self, amount: U128) {${u}\n Nep141Controller::burn(self, env::predecessor_account_id(), amount.into(), None);${f}\n}\n`.trim();s.push(h)}let g=s.join(`\n\n`)||void 0,r;e.afterChangeFunction.length==0&&e.beforeChangeFunction.length==0?i.push("no_hooks"):r=`\nimpl Nep141Hook for Contract {\n fn before_transfer(&mut self, transfer: &Nep141Transfer) {${d(1)(u)}\n }\n\n fn after_transfer(&mut self, transfer: &Nep141Transfer, _: ()) {${d(1)(f)}\n }\n}\n`.trim();let l=`#[fungible_token(${i.join(", ")})]`;return{imports:t,deriveMacroName:"FungibleToken",deriveMacroAttribute:l,constructorCode:a,bindgenCode:g,otherCode:r}}},_=class{constructor(e){this.config=e}generate(e){let t=[{path:["near_sdk_contract_tools","nft","*"]}],a=`\ncontract.set_contract_metadata(ContractMetadata::new(\n "${this.config.name}".to_string(),\n "${this.config.symbol}".to_string(),\n ${this.config.baseUri?`Some("${this.config.baseUri}".to_string())`:"None"},\n));\n`.trim(),n=[],c,i=e.beforeChangeFunction.length?`\n`+e.beforeChangeFunction.map(d(1)).join(`\n`):"",s=e.afterChangeFunction.length?`\n`+e.afterChangeFunction.map(d(1)).join(`\n`):"",u=e.beforeAuthorizedFunction.length?`\n`+d(1)(e.beforeAuthorizedFunction.join(`\n`)):"";if(e.afterChangeFunction.length==0&&e.beforeChangeFunction.length==0&&e.beforeAuthorizedFunction.length==0)n.push("no_core_hooks","no_approval_hooks");else{t.push({path:["near_sdk","AccountId"]});let r=[i.length>0?`\nfn before_nft_approve(&self, token_id: &TokenId, account_id: &AccountId) {${i}\n}\n\nfn before_nft_revoke(&self, token_id: &TokenId, account_id: &AccountId) {${i}\n}\n\nfn before_nft_revoke_all(&self, token_id: &TokenId) {${i}\n}\n`.trim():"",s.length>0?`\nfn after_nft_approve(&mut self, token_id: &TokenId, account_id: &AccountId, _approval_id: &ApprovalId) {${s}\n}\n\nfn after_nft_revoke(&mut self, token_id: &TokenId, account_id: &AccountId) {${s}\n}\n\nfn after_nft_revoke_all(&mut self, token_id: &TokenId) {${s}\n}\n`.trim():""].filter(h=>h.length>0).map(d(1)).join(`\n\n`);r.length==0?n.push("no_approval_hooks"):r=`\nimpl SimpleNep178Hook for Contract {\n${r}\n}\n`.trim();let l=[i.length>0?`fn before_nft_transfer(&self, transfer: &Nep171Transfer) {${i}\n}`:"",s.length>0?`fn after_nft_transfer(&self, transfer: &Nep171Transfer) {${s}\n}`:""].filter(h=>h.length>0).map(d(1)).join(`\n\n`);l.length==0?n.push("no_core_hooks"):l=`\nimpl SimpleNep171Hook for Contract {\n${l}\n}\n`.trim(),c=[r,l].filter(h=>h.length>0).join(`\n\n`)}let f=[];if(this.config.mintable){t.push({path:["near_sdk","AccountId"]}),t.push({path:["near_sdk","env"]});let r=`\npub fn mint(&mut self, token_id: TokenId, account_id: AccountId, metadata: TokenMetadata) {${u}${i}\n Nep177Controller::mint_with_metadata(self, token_id, account_id, metadata)\n .unwrap_or_else(|e| env::panic_str(&e.to_string()));${s}\n}\n`.trim();f.push(r)}if(this.config.burnable){t.push({path:["near_sdk","env"]});let r=`\npub fn burn(&mut self, token_id: TokenId) {${i}\n Nep177Controller::burn_with_metadata(self, token_id, &env::predecessor_account_id())\n .unwrap_or_else(|e| env::panic_str(&e.to_string()));${s}\n}\n`.trim();f.push(r)}let p=f.join(`\n\n`)||void 0,g=n.length>0?`#[non_fungible_token(${n.join(", ")})]`:void 0;return{imports:t,deriveMacroName:"NonFungibleToken",deriveMacroAttribute:g,constructorCode:a,bindgenCode:p,otherCode:c}}},b=class{constructor(e){this.config=e}generate(){let e=[{path:["near_sdk","borsh","self"]},{path:["near_sdk","borsh","BorshSerialize"]},{path:["near_sdk","BorshStorageKey"]},{path:["near_sdk_contract_tools","Rbac"]},{path:["near_sdk_contract_tools","rbac","*"]}],t=this.config.accountId?`"${this.config.accountId}".parse().unwrap()`:"env::predecessor_account_id()";return{imports:e,deriveMacroName:"Rbac",deriveMacroAttribute:\'#[rbac(roles = "Role")]\',beforeChangeFunctionGuards:[],afterChangeFunctionGuards:[],authorizedFunctionGuards:["<Self as Rbac>::require_role(&Role::Admin);"],constructorCode:`contract.add_role(${t}, &Role::Admin);`,otherCode:`\n#[derive(BorshSerialize, BorshStorageKey)]\npub enum Role {\n Admin,\n}\n`.trim()}}},C=class{constructor(e){this.config=e}generate(){let e=[{path:["near_sdk","env"]},{path:["near_sdk_contract_tools","Owner"]},{path:["near_sdk_contract_tools","owner","*"]}],a=`Owner::init(&mut contract, &${this.config.accountId?`"${this.config.accountId}".parse().unwrap()`:"env::predecessor_account_id()"});`;return{imports:e,deriveMacroName:"Owner",constructorCode:a,beforeChangeFunctionGuards:[],afterChangeFunctionGuards:[],authorizedFunctionGuards:["<Self as Owner>::require_owner();"]}}},k=class{constructor(e){}generate(){return{imports:[{path:["near_sdk_contract_tools","Pause"]},{path:["near_sdk_contract_tools","pause","*"]}],deriveMacroName:"Pause",beforeChangeFunctionGuards:["Contract::require_unpaused();"],afterChangeFunctionGuards:[],authorizedFunctionGuards:[]}}};function v(o){return o&&typeof o=="object"&&typeof o.token=="object"&&typeof o.token.which=="string"}function $(o){let e=o.token.which==="ft"?new m(o.token.config):new _(o.token.config),t=Object.entries(o.plugins).map(([a,n])=>{switch(a){case"owner":return new C(n);case"pause":return new k(n);case"rbac":return new b(n);default:throw new Error(`Unknown plugin: "${a}"`)}});return{token:e,plugins:t}}function I(o){let e={part:"",children:{}};function t(n,c){if(c.length==0)return;let[i,...s]=c;n.children[i]==null&&(n.children[i]={part:i,children:{}}),t(n.children[i],s)}for(let n of o)t(e,n.path);function a(n){let c=Object.values(n.children);if(c.length===1)return`${n.part}::${a(c[0])}`;if(c.length>1){let i=c.map(a).map(d(1)).join(`,\n`);return`${n.part}::{\n${i},\n}`}else return n.part}return Object.values(e.children).map(n=>`use ${a(n)};`).join(`\n`)}function F(o){let e;v(o)?e=$(o):e=o;let t=[{path:["near_sdk","near_bindgen"]},{path:["near_sdk","PanicOnDefault"]},{path:["near_sdk","borsh","self"]},{path:["near_sdk","borsh","BorshSerialize"]},{path:["near_sdk","borsh","BorshDeserialize"]}],a={beforeChangeFunction:[],afterChangeFunction:[],beforeAuthorizedFunction:[]},n=["BorshSerialize","BorshDeserialize","PanicOnDefault"],c=[],i=[],s=[];Object.values(e.plugins).forEach(g=>{let r=g.generate();t.push(...r.imports),a.beforeChangeFunction.push(...r.beforeChangeFunctionGuards),a.afterChangeFunction.push(...r.afterChangeFunctionGuards),a.beforeAuthorizedFunction.push(...r.authorizedFunctionGuards),r.constructorCode&&i.push(r.constructorCode),r.deriveMacroName&&n.push(r.deriveMacroName),r.deriveMacroAttribute&&c.push(r.deriveMacroAttribute),r.otherCode&&s.push(r.otherCode)});let u=e.token.generate(a);t.push(...u.imports),u.deriveMacroName&&n.push(u.deriveMacroName),u.deriveMacroAttribute&&c.push(u.deriveMacroAttribute),u.constructorCode&&i.push(u.constructorCode),u.otherCode&&s.push(u.otherCode),c.push("#[near_bindgen]");let f=`\nSelf {}`;i.length>0&&(f=`\nlet mut contract = Self {};\n\n${i.join(`\n`)}\n\ncontract`);let p="";return u.bindgenCode&&(p=`\n\n${u.bindgenCode}`),`\n${I(t)}\n\n#[derive(${n.join(", ")})]\n${c.join(`\n`)}\npub struct Contract {}\n\n#[near_bindgen]\nimpl Contract {\n #[init]\n pub fn new() -> Self {${d(2)(f)}\n }${d(1)(p)}\n}\n\n${s.join(`\n\n`)}\n`.trim()+`\n`}window.addEventListener("message",o=>{window.top.postMessage(F(o.data),"*")});})();\n<\/script></body></html>'} message={message} onMessage={onMessage} />;