import * as tslib_1 from "tslib";
import * as React from 'react';
import { loadTheme, FontClassNames } from 'office-ui-fabric-react/lib/Styling';
import { Highlight } from '@uifabric/example-app-base';
import { defaultTheme } from './defaultTheme';
import { Callout } from 'office-ui-fabric-react/lib/Callout';
import { DetailsList, DetailsListLayoutMode as LayoutMode } from 'office-ui-fabric-react/lib/DetailsList';
import { SelectionMode } from 'office-ui-fabric-react/lib/Selection';
import { ColorPicker } from 'office-ui-fabric-react/lib/ColorPicker';
import './ThemePage.scss';
var ThemeCodeExample = require('!raw-loader!office-ui-fabric-react/src/components/Theme/examples/ThemeCode.Example.tsx');
var ThemePage = /** @class */ (function (_super) {
    tslib_1.__extends(ThemePage, _super);
    function ThemePage(props) {
        var _this = _super.call(this, props) || this;
        _this._createDetailsListRef = function (component) {
            _this._list = component;
        };
        _this._onPickerDismiss = _this._onPickerDismiss.bind(_this);
        _this.state = {
            colors: Object.keys(defaultTheme).map(function (variableName) { return ({
                key: variableName,
                name: variableName,
                value: defaultTheme[variableName],
                description: '',
                colorPickerProps: undefined
            }); })
        };
        return _this;
    }
    ThemePage.prototype.render = function () {
        var _this = this;
        var _a = this.state, colors = _a.colors, colorPickerProps = _a.colorPickerProps;
        return (React.createElement("div", { className: 'Themes' },
            React.createElement("h1", { className: FontClassNames.xxLarge }, "Themes"),
            React.createElement("p", null, "The entire color palette of the controls are themeable. We provide a set of sensible defaults, but you can override all colors individually."),
            React.createElement("p", null,
                "To override the themes, you need to call ",
                React.createElement("span", { className: 'code' }, "loadTheme()"),
                " with the appropriate set of overrides:"),
            React.createElement(Highlight, { className: 'typescript' }, ThemeCodeExample),
            React.createElement("h1", { className: FontClassNames.xLarge }, "Define a theme"),
            React.createElement("div", null,
                React.createElement(DetailsList, { ref: this._createDetailsListRef, items: colors, selectionMode: SelectionMode.none, layoutMode: LayoutMode.fixedColumns, columns: [
                        {
                            key: 'name',
                            name: 'Name',
                            fieldName: 'name',
                            minWidth: 150,
                            maxWidth: 150
                        },
                        {
                            key: 'color',
                            name: 'Color',
                            fieldName: 'value',
                            minWidth: 200,
                            onRender: function (item, index) { return (React.createElement("div", { className: 'ThemePage-colorSwatch', "data-is-focusable": 'true', onClick: _this._onSwatchClicked.bind(_this, item, index) },
                                React.createElement("span", { className: 'ThemePage-swatch', style: { backgroundColor: item.value } }),
                                React.createElement("span", { className: 'ThemePage-colorValue' }, item.value))); }
                        },
                        {
                            key: 'desc',
                            name: 'Description',
                            fieldName: 'description',
                            minWidth: 90
                        }
                    ] }),
                colorPickerProps && (React.createElement(Callout, { isBeakVisible: false, gapSpace: 10, target: colorPickerProps.targetElement, onDismiss: this._onPickerDismiss },
                    React.createElement(ColorPicker, { color: colorPickerProps.value, onColorChanged: this._onColorChanged.bind(this, colorPickerProps.index) }))))));
    };
    ThemePage.prototype._onSwatchClicked = function (item, index, ev) {
        this.setState({
            colorPickerProps: {
                targetElement: ev.currentTarget.children[0],
                value: item.value,
                index: index
            }
        });
    };
    ThemePage.prototype._onColorChanged = function (index, newColor) {
        var colors = this.state.colors;
        var color = colors[index];
        var palette = {};
        color.value = newColor;
        for (var i = 0; i < colors.length; i++) {
            var themeColor = colors[i];
            palette[themeColor.key] = themeColor.value;
        }
        loadTheme({ palette: palette });
        // The theme has changed values, but color state is the same. Force an update on the list.
        this._list.forceUpdate();
    };
    ThemePage.prototype._onPickerDismiss = function () {
        this.setState({
            colorPickerProps: undefined
        });
    };
    return ThemePage;
}(React.Component));
export { ThemePage };
//# sourceMappingURL=ThemePage.js.map