import React from 'react';
import {
    Card,
    CardHeader,
    CardContent
} from '@material-ui/core'


class CloudRole extends React.Component {
    constructor() {
        super()
        this.state = {

        }
    }

    copyToClipboard(element) {
        const range = document.createRange();
        const selection = window.getSelection();

        // Clear selection from any previous data.
        selection.removeAllRanges();

        // Make the range select the entire content of the contentHolder paragraph.
        range.selectNodeContents(document.querySelector(element));

        // Add that range to the selection.
        selection.addRange(range);

        // Copy the selection to clipboard.
        document.execCommand('copy');

        // Clear selection if you want to.
        selection.removeAllRanges();
    }


    handleExpandChange = (expanded) => {
        this.setState({ expanded: expanded });
    };

    handleToggle = (event, toggle) => {
        this.setState({ expanded: toggle });
    };

    handleExpand = () => {
        this.setState({ expanded: true });
    };

    handleReduce = () => {
        this.setState({ expanded: false });
    };

    render() {
        let TABLE = "User";
        let columnsData = ["createdAt", "expires", "username"]
        return (
            <div>
                <div className="method">
                    <a id="CloudRole-constructor" name="CloudObject-constructor" className="section-anchor" />
                    <Card style={{marginBottom:16}}>
                        <CardHeader
                            title="Instantiate a CloudRole Object"
                            style={{backgroundColor:"#f4f4f4", padding:"10px 16px"}}
                        />
                        <CardContent>
                            {/*overlay={<CardHeader title="Overlay title" subheaderTypographyProps={{ style: { fontSize: '12px !important' }  }} subheader="Overlay subtitle" />}
                        >*/}
                            <div className="method-example" id="api-summary-example">

                                <span className="pull-right flag fa fa-clipboard" title="Copy.." onClick={this.copyToClipboard.bind(this, "#pre_initiateRole")}>

                                </span>
                                <pre id="pre_initiateRole">
                                    <span className="code-red">{`var`}</span>{` roleObj = `}<span className="code-red">{`new`}</span>{` CB.CloudRole(`}<span className="code-yellow">{`"${TABLE}"`}</span>{`);`}
                                </pre>
                            </div>{/* method-example */}
                        </CardContent>
                        <CardHeader title="Constructor : CloudRole( roleName )" subheaderTypographyProps={{ style: { fontSize: '12px !important' }  }} subheader=" Instantiates a CloudRole object." />
                        <CardContent>
                            <div className="method-description">
                                <div className="method-list">
                                    <h6>Argument</h6>
                                    <dl className="argument-list">
                                        <dt>roleName</dt>
                                        <dd className>string <span>The name of the role you want to deal with</span></dd>
                                        <div className="clearfix" />
                                    </dl>
                                    <h6>Returns</h6>
                                    <p>It returns an instance of a CloudRole, as its a constructor. </p>
                                </div>
                            </div>
                        </CardContent>
                    </Card>
                    <a id="CloudUser-addToRole" name="CloudObject-fetch" className="section-anchor" />
                    <Card style={{marginBottom:16}}>
                        <CardHeader
                            title="Get Role of current CloudUser"
                            style={{backgroundColor:"#f4f4f4", padding:"10px 16px"}}
                        />
                        <CardContent>
                            <div className="method-example" id="api-summary-example">
                                <span className="pull-right flag fa fa-clipboard" title="Copy.." onClick={this.copyToClipboard.bind(this, "#pre_addRole")}>
                                    </span>
                                <pre id="pre_addRole">
                                    {
                                        `//role is an instance of CloudRole Object.
CB.CloudUser.current.addToRole(role, {
    success: `}<span className="code-red">{`function`}</span>{`(roleObj) {
        //given new role
        //to User successfully
    },
    error: `}<span className="code-red">{`function`}</span>{`(err) {    
        //Error occurred in assigning role
    }              
});`
                                    }
                                </pre>
                            </div>{/* method-example */}
                        </CardContent>
                        <CardHeader title="CloudObject.addToRole( role, [callback] )"
                            subheaderTypographyProps={{ style: { fontSize: '12px !important' }  }} subheader="Get the current Role of a current User." />
                        <CardContent>
                            <div className="method-description">
                                <div className="method-list">
                                    <h6>Argument</h6>
                                    <dl className="argument-list">
                                        <dt>role</dt>
                                        <dd className>CloudRole Object <span>The CloudRole object of the role you want to add the user to.</span></dd>
                                        <div className="clearfix" />
                                        <dt>callback</dt>
                                        <dd className>Object <span>The CloudRole object of the role you want to add the user to.</span></dd>
                                    </dl>
                                    <h6>Returns</h6>
                                    <p>[optional] if provided must have success and error functions to handle respective response.</p>
                                </div>
                            </div>
                        </CardContent>
                    </Card>
                    <a id="CloudObject-removeFromRole" name="CloudObject-delete" className="section-anchor" />
                    <Card style={{marginBottom:16}}>
                        <CardHeader
                            title="To remove current User from current Role"
                            style={{backgroundColor:"#f4f4f4", padding:"10px 16px"}}
                        />
                        <CardContent>
                            <div className="method-example" id="api-summary-example">
                                <span className="pull-right flag fa fa-clipboard" title="Copy.." onClick={this.copyToClipboard.bind(this, "#pre_removeRole")}>
                                    </span>
                                <pre id="pre_removeRole">
                                    {
                                        `CB.CloudUser.current.removeFromRole(role, {
    success: `}<span className="code-red">{`function`}</span>{`(roleObj) {
        //user removed from role
    },
    error: `}<span className="code-red">{`function`}</span>{`(err) {    
        //Error occurred in removing role
    }              
});`
                                    }
                                </pre>
                            </div>{/* method-example */}
                        </CardContent>
                        <CardHeader title="CloudUser.removeFromRole( role , [callback] )"
                            subheaderTypographyProps={{ style: { fontSize: '12px !important' }  }} subheader="Removes the user from the given role provided in role object." />
                        <CardContent>
                            <div className="method-description">
                                <div className="method-list">
                                    <h6>Argument</h6>
                                    <dl className="argument-list">
                                        <dt>role</dt>
                                        <dd className>
                                            CloudRole Object
                                        <span>The CloudRole object of the role you want to remove the user from.</span>
                                        </dd>
                                        <div className="clearfix" />
                                        <dt>callback</dt>
                                        <dd className>
                                            Object
                                        <span>[optional] if provided must have success and error functions to handle respective response.</span>
                                        </dd>
                                    </dl>
                                    <h6>Returns</h6>
                                    <p>It returns a CloudUser object having the user information of the user who was logged in otherwise an error object along with JQuery promise (if callback is not provided).</p>
                                </div>
                            </div>
                        </CardContent>
                    </Card>
                </div>
            </div>
        );
    }
}

export default CloudRole;